NCBI C++ ToolKit
nst_users.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: nst_users.cpp 72347 2016-05-03 13:19:07Z satskyse $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Sergey Satskiy
27  *
28  * File Description:
29  * NetStorage users facilities
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 
36 #include "nst_users.hpp"
37 #include "nst_exception.hpp"
38 
39 
41 
42 
43 
44 
46 {
47  // Note:
48  // both fields could be empty. This is a 'special case': when the
49  // user namespace and user name were not provided at the time of creation
50 
51 
52  // The following will throw an exception if the limit is broken
53  SNetStorage::SLimits::
54  Check<SNetStorage::SLimits::SUserName>(name);
55  SNetStorage::SLimits::
56  Check<SNetStorage::SLimits::SUserNamespace>(name_space);
57 }
58 
59 
61 {}
62 
63 
65 {
66  CMutexGuard guard(m_Lock);
67  TUsers::const_iterator found = m_Users.find(user);
68  if (found != m_Users.end())
69  return found->second.GetDBUserID();
70  return k_UndefinedUserID;
71 }
72 
73 
75 {
76  CMutexGuard guard(m_Lock);
77  TUsers::iterator found = m_Users.find(user);
78  if (found != m_Users.end())
79  found->second.SetDBUserID(id);
80  else {
81  CNSTUserData user_data;
82  user_data.SetDBUserID(id);
83  m_Users[user] = user_data;
84  }
85 }
86 
87 
88 size_t CNSTUserCache::Size(void) const
89 {
90  CMutexGuard guard(m_Lock);
91  return m_Users.size();
92 }
93 
TUsers m_Users
Definition: nst_users.hpp:110
size_t Size(void) const
Definition: nst_users.cpp:88
Int8 GetDBUserID(const CNSTUserID &user) const
Definition: nst_users.cpp:64
void SetDBUserID(const CNSTUserID &user, Int8 id)
Definition: nst_users.cpp:74
void SetDBUserID(Int8 id)
Definition: nst_users.hpp:90
string name_space
Definition: nst_users.hpp:75
string name
Definition: nst_users.hpp:76
void Validate(void)
Definition: nst_users.cpp:45
size_type size() const
Definition: map.hpp:148
const_iterator end() const
Definition: map.hpp:152
const_iterator find(const key_type &key) const
Definition: map.hpp:153
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
USING_NCBI_SCOPE
Definition: nst_users.cpp:40
const Int8 k_UndefinedUserID
Definition: nst_users.hpp:42
Modified on Sat Dec 09 04:45:09 2023 by modify_doxy.py rev. 669887