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

Go to the SVN repository for this file.

1 #ifndef ENUMVALUES__HPP
2 #define ENUMVALUES__HPP
3 
4 /* $Id: enumvalues.hpp 99879 2023-05-18 17:35:50Z 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 * Description of enumerated data type values (named integers)
33 */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <serial/serialdef.hpp>
37 #include <corelib/tempstr.hpp>
38 #include <list>
39 #include <map>
40 #include <memory>
41 
42 
43 /** @addtogroup FieldsComplex
44  *
45  * @{
46  */
47 
48 
50 
52 {
53 public:
54  typedef list< pair<string, TEnumValueType> > TValues;
57 
58  enum EValueFlags {
59  eNone = 0,
60  eHideName = 1
61  };
62  typedef unsigned int TValueFlags; ///< Binary OR of EValueFlags
63 
64  CEnumeratedTypeValues(const char* name, bool isInteger);
65  CEnumeratedTypeValues(const string& name, bool isInteger);
66  ~CEnumeratedTypeValues(void);
67 
68  const string& GetName(void) const;
69  /// Get ASN.1 module name
70  const string& GetModuleName(void) const;
71  /// Set ASN.1 module name
72  void SetModuleName(const string& name);
73 
74  /// Check whether the type is defined as INTEGER in ASN.1 spec
75  bool IsInteger(void) const
76  {
77  return m_Integer;
78  }
79 
80  /// Check if this enum describes internal unnamed type
81  bool IsInternal(void) const
82  {
83  return m_IsInternal;
84  }
85  /// Return internal type access string e.g. Int-fuzz.lim
86  const string& GetInternalName(void) const;
87  /// Return internal type's owner module name
88  const string& GetInternalModuleName(void) const;
89  /// Mark this enum as internal
90  void SetInternalName(const string& name);
91 
92  /// Return internal or regular name
93  const string& GetAccessName(void) const;
94  /// Return internal or regular module name
95  const string& GetAccessModuleName(void) const;
96 
97  /// Get the list of name-value pairs
98  const TValues& GetValues(void) const
99  {
100  return m_Values;
101  }
102 
103  /// Add name-value pair
104  void AddValue(const string& name, TEnumValueType value, TValueFlags flags = eNone);
105  /// Add name-value pair
106  void AddValue(const char* name, TEnumValueType value, TValueFlags flags = eNone);
107 
108  /// Find numeric value by the name of the enum
109  ///
110  /// @param name
111  /// Name of enum value
112  /// @return
113  /// Numeric value, if found; otherwise, throws an exception
114  TEnumValueType FindValue(const CTempString& name) const;
115 
116  /// Check whether enum with this name is defined
117  ///
118  /// @param name
119  /// Name of enum value
120  /// @return
121  /// TRUE, if it is defined
122  bool IsValidName(const CTempString& name) const;
123 
124  /// Find name of the enum by its numeric value
125  ///
126  /// @param value
127  /// Numeric value
128  /// @param allowBadValue
129  /// When TRUE, and the name is not found, return empty string;
130  /// otherwise, throw an exception
131  /// @return
132  /// Name of the enum
133  const string& FindName(TEnumValueType value, bool allowBadValue) const;
134 
135  string GetDisplayName(TEnumValueType value) const;
136 
137  /// Get name-to-value map
138  const TNameToValue& NameToValue(void) const;
139  /// Get value-to-name map
140  const TValueToName& ValueToName(void) const;
141 
142  void ClearIndexes(void);
143 
144  void SetBitset(bool bitset=true) {
145  m_IsBitset = bitset;
146  }
147  bool IsBitset(void) const {
148  return m_IsBitset;
149  }
150 
151  TValueFlags GetValueFlags(TEnumValueType) const;
152  const string& FindNameEx(TEnumValueType value, bool allowBadValue) const;
153 
154 private:
155  string m_Name;
156  string m_ModuleName;
157 
158  bool m_Integer;
163  mutable atomic<TNameToValue*> m_NameToValue;
164  mutable atomic<TValueToName*> m_ValueToName;
165 };
166 
167 
168 /* @} */
169 
170 
172 
173 #endif /* ENUMVALUES__HPP */
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
Definition: map.hpp:338
Include a standard set of the NCBI C++ Toolkit most basic headers.
static uch flags
map< CTempString, TEnumValueType, PQuickStringLess > TNameToValue
Definition: enumvalues.hpp:55
list< pair< string, TEnumValueType > > TValues
Definition: enumvalues.hpp:54
bool IsInternal(void) const
Check if this enum describes internal unnamed type.
Definition: enumvalues.hpp:81
bool IsBitset(void) const
Definition: enumvalues.hpp:147
atomic< TValueToName * > m_ValueToName
Definition: enumvalues.hpp:164
const TValues & GetValues(void) const
Get the list of name-value pairs.
Definition: enumvalues.hpp:98
unsigned int TValueFlags
Binary OR of EValueFlags.
Definition: enumvalues.hpp:62
void SetBitset(bool bitset=true)
Definition: enumvalues.hpp:144
map< TEnumValueType, const string * > TValueToName
Definition: enumvalues.hpp:56
map< TEnumValueType, TValueFlags > m_ValueFlags
Definition: enumvalues.hpp:162
bool IsInteger(void) const
Check whether the type is defined as INTEGER in ASN.1 spec.
Definition: enumvalues.hpp:75
atomic< TNameToValue * > m_NameToValue
Definition: enumvalues.hpp:163
int TEnumValueType
Definition: serialdef.hpp:232
void SetModuleName(CTypeInfo *info, const char *name)
Definition: serial.cpp:96
void SetInternalName(CTypeInfo *info, const char *owner_name, const char *member_name=0)
Definition: serial.cpp:106
#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
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
static const string & GetModuleName(const char *moduleName)
Definition: serial.cpp:87
Modified on Wed Apr 17 13:08:08 2024 by modify_doxy.py rev. 669887