1 #ifndef ENUMVALUES__HPP 2 #define ENUMVALUES__HPP 3 4 /* $Id: enumvalues.hpp 554977 2018-01-11 14:18:53Z gouriano $ 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 49 BEGIN_NCBI_SCOPE 50 51 class NCBI_XSERIAL_EXPORT CEnumeratedTypeValues 52 { 53 public: 54 typedef list< pair<string, TEnumValueType> > TValues; 55 typedef map<CTempString, TEnumValueType, PQuickStringLess> TNameToValue; 56 typedef map<TEnumValueType, const string*> TValueToName; 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 IsInteger(void) const75 bool IsInteger(void) const 76 { 77 return m_Integer; 78 } 79 80 /// Check if this enum describes internal unnamed type IsInternal(void) const81 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 GetValues(void) const98 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 SetBitset(bool bitset=true)142 void SetBitset(bool bitset=true) { 143 m_IsBitset = bitset; 144 } IsBitset(void) const145 bool IsBitset(void) const { 146 return m_IsBitset; 147 } 148 149 TValueFlags GetValueFlags(TEnumValueType) const; 150 const string& FindNameEx(TEnumValueType value, bool allowBadValue) const; 151 152 private: 153 string m_Name; 154 string m_ModuleName; 155 156 bool m_Integer; 157 bool m_IsBitset; 158 bool m_IsInternal; 159 TValues m_Values; 160 map<TEnumValueType, TValueFlags> m_ValueFlags; 161 mutable shared_ptr<TNameToValue> m_NameToValue; 162 mutable shared_ptr<TValueToName> m_ValueToName; 163 }; 164 165 166 /* @} */ 167 168 169 END_NCBI_SCOPE 170 171 #endif /* ENUMVALUES__HPP */ 172