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

Go to the SVN repository for this file.

1 #ifndef ENUMTYPE_HPP
2 #define ENUMTYPE_HPP
3 
4 /* $Id: enumtype.hpp 79562 2017-09-20 18:15:56Z 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 * Enumerated type definition
33 *
34 */
35 
36 #include "type.hpp"
37 #include <list>
38 
40 
42 {
43 public:
45  : m_SourceLine(0), m_Name(name), m_Value(value), m_Flags(eNone), m_IdName(name)
46  {
47  }
48 
49  const string& GetName(void) const
50  {
51  return m_Name;
52  }
54  {
55  return m_Value;
56  }
57 
59  {
60  return m_Comments;
61  }
62  const CComments& GetComments(void) const
63  {
64  return m_Comments;
65  }
66  void SetSourceLine(int line)
67  {
68  m_SourceLine = line;
69  }
70  int GetSourceLine(void) const
71  {
72  return m_SourceLine;
73  }
74 
75  const string& GetEnumId(void) const {
76  return m_IdName;
77  }
78  void SetEnumId(const string& id) const {
79  m_IdName = id;
80  }
81 
82  enum EValueFlags {
83  eNone = 0,
84  eHideName = 1
85  };
86  typedef unsigned int TValueFlags;
87 
88  void SetFlag(EValueFlags flag) const {
89  m_Flags |= flag;
90  }
91  TValueFlags GetFlags(void) const {
92  return m_Flags;
93  }
94 private:
96  string m_Name;
100  mutable string m_IdName;
101 };
102 
103 class CEnumDataType : public CDataType
104 {
106 public:
108  typedef list<TValue> TValues;
109 
110  CEnumDataType(void);
111  virtual bool IsInteger(void) const;
112  virtual const char* GetASNKeyword(void) const override;
113  virtual const char* GetDEFKeyword(void) const override;
114  virtual string GetXMLContents(void) const;
115 
116  TValue& AddValue(const string& name, TEnumValueType value);
117  const TValues& GetValues(void) const
118  {
119  return m_Values;
120  }
121 
122  virtual void PrintASN(CNcbiOstream& out, int indent) const override;
123  virtual void PrintSpecDumpExtra(CNcbiOstream& out, int indent) const override;
124  virtual void PrintJSONSchema(CNcbiOstream& out, int indent, list<string>& required, bool contents_only=false) const override;
125  virtual void PrintXMLSchema(CNcbiOstream& out, int indent, bool contents_only=false) const override;
126  virtual void PrintDTDElement(CNcbiOstream& out, bool contents_only=false) const override;
127  virtual void PrintDTDExtra(CNcbiOstream& out) const override;
128 
129  virtual bool CheckValue(const CDataValue& value) const override;
130  virtual TObjectPtr CreateDefault(const CDataValue& value) const override;
131  virtual string GetDefaultString(const CDataValue& value) const override;
132  virtual string GetXmlValueName(const string& value) const;
133 
134  struct SEnumCInfo {
135  string enumName;
136  string cType;
137  string valuePrefix;
138 
139  SEnumCInfo(const string& name, const string& type,
140  const string& prefix)
141  : enumName(name), cType(type), valuePrefix(prefix)
142  {
143  }
144  };
145 
146  string DefaultEnumName(void) const;
147  SEnumCInfo GetEnumCInfo(void) const;
148 
150  {
151  return m_LastComments;
152  }
153 
154 public:
155 
156  virtual CTypeInfo* CreateTypeInfo(void) override;
157  virtual AutoPtr<CTypeStrings> GetRefCType(void) const override;
158  virtual AutoPtr<CTypeStrings> GetFullCType(void) const override;
159  virtual AutoPtr<CTypeStrings> GenerateCode(void) const override;
160 
161 private:
164 };
165 
168 public:
169  virtual bool IsInteger(void) const override;
170  virtual const char* GetASNKeyword(void) const override;
171  virtual const char* GetDEFKeyword(void) const override;
172  virtual string GetXmlValueName(const string& value) const override;
173 };
174 
177 public:
178  virtual const char* GetASNKeyword(void) const override;
179  virtual const char* GetDEFKeyword(void) const override;
180 };
181 
183 
184 #endif
virtual const char * GetASNKeyword(void) const override
Definition: enumtype.cpp:589
virtual const char * GetDEFKeyword(void) const override
Definition: enumtype.cpp:594
CIntEnumDataType CParent
Definition: enumtype.hpp:176
const string & GetEnumId(void) const
Definition: enumtype.hpp:75
CComments & GetComments(void)
Definition: enumtype.hpp:58
TValueFlags GetFlags(void) const
Definition: enumtype.hpp:91
TEnumValueType GetValue(void) const
Definition: enumtype.hpp:53
TEnumValueType m_Value
Definition: enumtype.hpp:97
void SetFlag(EValueFlags flag) const
Definition: enumtype.hpp:88
void SetEnumId(const string &id) const
Definition: enumtype.hpp:78
TValueFlags m_Flags
Definition: enumtype.hpp:99
CComments m_Comments
Definition: enumtype.hpp:98
const string & GetName(void) const
Definition: enumtype.hpp:49
unsigned int TValueFlags
Definition: enumtype.hpp:86
int GetSourceLine(void) const
Definition: enumtype.hpp:70
CEnumDataTypeValue(const string &name, TEnumValueType value)
Definition: enumtype.hpp:44
void SetSourceLine(int line)
Definition: enumtype.hpp:66
const CComments & GetComments(void) const
Definition: enumtype.hpp:62
virtual string GetXmlValueName(const string &value) const
Definition: enumtype.cpp:442
virtual void PrintASN(CNcbiOstream &out, int indent) const override
Definition: enumtype.cpp:85
CComments & LastComments(void)
Definition: enumtype.hpp:149
CEnumDataTypeValue TValue
Definition: enumtype.hpp:107
virtual const char * GetDEFKeyword(void) const override
Definition: enumtype.cpp:56
virtual string GetDefaultString(const CDataValue &value) const override
Definition: enumtype.cpp:413
virtual void PrintXMLSchema(CNcbiOstream &out, int indent, bool contents_only=false) const override
Definition: enumtype.cpp:166
CDataType CParent
Definition: enumtype.hpp:105
virtual AutoPtr< CTypeStrings > GenerateCode(void) const override
Definition: enumtype.cpp:554
virtual void PrintDTDElement(CNcbiOstream &out, bool contents_only=false) const override
Definition: enumtype.cpp:296
SEnumCInfo GetEnumCInfo(void) const
Definition: enumtype.cpp:473
TValue & AddValue(const string &name, TEnumValueType value)
Definition: enumtype.cpp:78
list< TValue > TValues
Definition: enumtype.hpp:108
virtual void PrintDTDExtra(CNcbiOstream &out) const override
Definition: enumtype.cpp:333
string DefaultEnumName(void) const
Definition: enumtype.cpp:460
virtual string GetXMLContents(void) const
Definition: enumtype.cpp:61
virtual CTypeInfo * CreateTypeInfo(void) override
Definition: enumtype.cpp:447
const TValues & GetValues(void) const
Definition: enumtype.hpp:117
virtual void PrintJSONSchema(CNcbiOstream &out, int indent, list< string > &required, bool contents_only=false) const override
Definition: enumtype.cpp:123
virtual AutoPtr< CTypeStrings > GetRefCType(void) const override
Definition: enumtype.cpp:497
CEnumDataType(void)
Definition: enumtype.cpp:47
virtual TObjectPtr CreateDefault(const CDataValue &value) const override
Definition: enumtype.cpp:399
virtual void PrintSpecDumpExtra(CNcbiOstream &out, int indent) const override
Definition: enumtype.cpp:112
virtual AutoPtr< CTypeStrings > GetFullCType(void) const override
Definition: enumtype.cpp:507
TValues m_Values
Definition: enumtype.hpp:162
virtual const char * GetASNKeyword(void) const override
Definition: enumtype.cpp:51
virtual bool CheckValue(const CDataValue &value) const override
Definition: enumtype.cpp:368
CComments m_LastComments
Definition: enumtype.hpp:163
virtual bool IsInteger(void) const
Definition: enumtype.cpp:73
virtual bool IsInteger(void) const override
Definition: enumtype.cpp:569
CEnumDataType CParent
Definition: enumtype.hpp:167
virtual string GetXmlValueName(const string &value) const override
Definition: enumtype.cpp:574
virtual const char * GetDEFKeyword(void) const override
Definition: enumtype.cpp:564
virtual const char * GetASNKeyword(void) const override
Definition: enumtype.cpp:559
CTypeInfo class contains all information about C++ types (both basic and classes): members and layout...
Definition: typeinfo.hpp:76
std::ofstream out("events_result.xml")
main entry point for tests
void * TObjectPtr
Definition: serialdef.hpp:55
int TEnumValueType
Definition: serialdef.hpp:232
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
string indent(" ")
SEnumCInfo(const string &name, const string &type, const string &prefix)
Definition: enumtype.hpp:139
Definition: type.c:6
Modified on Fri Sep 20 14:58:27 2024 by modify_doxy.py rev. 669887