NCBI C++ ToolKit
memberlist.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef MEMBERLIST__HPP
2 #define MEMBERLIST__HPP
3 
4 /* $Id: memberlist.hpp 99790 2023-05-10 17:59:02Z vasilche $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Eugene Vasilchenko
30 *
31 * File Description:
32 * !!! PUT YOUR DESCRIPTION HERE !!!
33 */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbiutil.hpp>
37 #include <corelib/tempstr.hpp>
38 #include <serial/impl/item.hpp>
39 #include <vector>
40 #include <map>
41 
42 
43 /** @addtogroup FieldsComplex
44  *
45  * @{
46  */
47 
48 
50 
51 class CConstObjectInfo;
52 class CObjectInfo;
53 class CClassTypeInfoBase;
54 
55 // This class supports sets of members with IDs
57 {
58 public:
60  typedef vector< AutoPtr<CItemInfo> > TItems;
62  typedef pair< TTag, CAsnBinaryDefs::ETagClass> TTagAndClass;
65 
66  CItemsInfo(void);
67  virtual ~CItemsInfo(void);
68 
69  bool Empty(void) const
70  {
71  return m_Items.empty();
72  }
73  size_t Size(void) const
74  {
75  return m_Items.size();
76  }
77 
78  static TMemberIndex FirstIndex(void)
79  {
80  return kFirstMemberIndex;
81  }
82  TMemberIndex LastIndex(void) const
83  {
84  return m_Items.size();
85  }
86 
87  TMemberIndex Find(const CTempString& name) const;
88  TMemberIndex FindDeep(const CTempString& name, bool search_attlist = false,
89  const CClassTypeInfoBase** classInfo = nullptr) const;
90  TMemberIndex FindDeep(const CTempString& name, TMemberIndex pos) const;
91  TMemberIndex FindEmpty(void) const;
92  TMemberIndex Find(const CTempString& name, TMemberIndex pos) const;
93  TMemberIndex Find(TTag tag, CAsnBinaryDefs::ETagClass tagclass) const;
94  TMemberIndex Find(TTag tag, CAsnBinaryDefs::ETagClass tagclass, TMemberIndex pos) const;
95 
96  static const CTypeInfo* FindRealTypeInfo(const CTypeInfo* info);
97  static const CItemInfo* FindNextMandatory(const CItemInfo* info);
98  static const CItemInfo* FindNextMandatory(const CTypeInfo* info);
99 
100  const CItemInfo* GetItemInfo(TMemberIndex index) const;
101  void AddItem(CItemInfo* item);
102  void AssignItemsTags(CAsnBinaryDefs::ETagType containerType);
103  void DataSpec(EDataSpec spec);
104 
105  // helping member iterator class (internal use)
106  class CIterator
107  {
108  public:
109  CIterator(const CItemsInfo& items);
110  CIterator(const CItemsInfo& items, TMemberIndex index);
111 
112  void SetIndex(TMemberIndex index);
114 
115  bool Valid(void) const;
116 
117  void Next(void);
118  void operator++(void);
119 
120  TMemberIndex GetIndex(void) const;
121  TMemberIndex operator*(void) const;
122 
123  private:
126  };
127  const CItemInfo* GetItemInfo(const CIterator& i) const;
128 
129 protected:
131 
132 private:
133  CItemsInfo(const CItemsInfo& ) = delete;
134  void operator=(const CItemsInfo& ) = delete;
135 
136  const TItemsByName& GetItemsByName(void) const;
137  const TItemsByOffset& GetItemsByOffset(void) const;
138  TTagAndClass GetTagAndClass(const CIterator& i) const;
139  pair<TMemberIndex, const TItemsByTag*> GetItemsByTagInfo(void) const;
140  void ClearIndexes();
141 
142  // items
144 
145  // items by name
146  mutable atomic<TItemsByName*> m_ItemsByName;
147 
148  // items by tag
149  mutable atomic<TMemberIndex> m_ZeroTagIndex;
150  mutable atomic<TItemsByTag*> m_ItemsByTag;
151 
152  // items by offset
153  mutable atomic<TItemsByOffset*> m_ItemsByOffset;
154 };
155 
156 
157 /* @} */
158 
159 
161 
163 
164 #endif /* MEMBERLIST__HPP */
info DataSpec(ncbi::EDataSpec::eXSD)
CConstObjectInfo –.
Definition: objectinfo.hpp:421
CObjectInfo –.
Definition: objectinfo.hpp:597
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
Definition: map.hpp:338
Include a standard set of the NCBI C++ Toolkit most basic headers.
TMemberIndex m_CurrentIndex
Definition: memberlist.hpp:124
atomic< TItemsByOffset * > m_ItemsByOffset
Definition: memberlist.hpp:153
TMemberIndex GetIndex(void) const
CMemberId::TTag TTag
Definition: memberlist.hpp:59
CIterator(const CItemsInfo &items)
pair< TTag, CAsnBinaryDefs::ETagClass > TTagAndClass
Definition: memberlist.hpp:62
map< size_t, TMemberIndex > TItemsByOffset
Definition: memberlist.hpp:64
TMemberIndex operator*(void) const
size_t Size(void) const
Definition: memberlist.hpp:73
TItems m_Items
Definition: memberlist.hpp:143
atomic< TMemberIndex > m_ZeroTagIndex
Definition: memberlist.hpp:149
CIterator & operator=(TMemberIndex index)
atomic< TItemsByTag * > m_ItemsByTag
Definition: memberlist.hpp:150
CAsnBinaryDefs::TLongTag TTag
Definition: memberid.hpp:54
vector< AutoPtr< CItemInfo > > TItems
Definition: memberlist.hpp:60
const CItemInfo * GetItemInfo(TMemberIndex index) const
static TMemberIndex FirstIndex(void)
Definition: memberlist.hpp:78
atomic< TItemsByName * > m_ItemsByName
Definition: memberlist.hpp:146
bool Valid(void) const
map< TTagAndClass, TMemberIndex > TItemsByTag
Definition: memberlist.hpp:63
void SetIndex(TMemberIndex index)
map< CTempString, TMemberIndex, PQuickStringLess > TItemsByName
Definition: memberlist.hpp:61
TMemberIndex m_LastIndex
Definition: memberlist.hpp:125
void operator=(const CItemsInfo &)=delete
CItemsInfo(const CItemsInfo &)=delete
const CItemInfo * GetItemInfo(const CIterator &i) const
CIterator(const CItemsInfo &items, TMemberIndex index)
TMemberIndex LastIndex(void) const
Definition: memberlist.hpp:82
bool Empty(void) const
Definition: memberlist.hpp:69
CItemInfo * x_GetItemInfo(TMemberIndex index) const
size_t TMemberIndex
Type used for indexing class members and choice variants.
Definition: serialdef.hpp:230
const TMemberIndex kFirstMemberIndex
Start if member indexing.
Definition: serialdef.hpp:235
EDataSpec
Definition: serialdef.hpp:204
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_XSERIAL_EXPORT
Definition: ncbi_export.h:1435
int i
static MDB_envinfo info
Definition: mdb_load.c:37
const char * tag
Useful/utility classes and methods.
Modified on Fri Sep 20 14:58:00 2024 by modify_doxy.py rev. 669887