NCBI C++ ToolKit
classstr.hpp

Search Toolkit Book for str_8hpp_source

Go to the documentation of this file.
1 #ifndef CLASSSTR_HPP
2 #define CLASSSTR_HPP
3 
4 /* $Id: classstr.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 * C++ class info: includes, used classes, C++ code etc.
33 */
34 
35 #include "typestr.hpp"
36 #include <corelib/ncbiutil.hpp>
37 #include "namespace.hpp"
38 #include "type.hpp"
39 #include <list>
40 
42 
43 class CClassCode;
44 class CDataType;
45 
47 {
49 public:
50  struct SMemberInfo {
51  string externalName; // logical name
52  string cName; // C++ type code
53  string mName; // member name
54  string tName; // typedef name
55  AutoPtr<CTypeStrings> type; // value type
56  string ptrType; // "*" or "NCBI_NS_NCBI::CRef"
57  string valueName; // value name (mName or '*'+mName)
58  bool optional; // have OPTIONAL or DEFAULT attribute
59  bool ref; // implement member via CRef
60  bool haveFlag; // need additional boolean flag 'isSet'
61  bool canBeNull; // pointer type can be NULL pointer
62  bool delayed;
63  int memberTag;
64  string defaultValue; // DEFAULT value code
65  bool noPrefix;
66  bool attlist;
67  bool noTag;
68  bool simple;
70  bool nonEmpty;
72  SMemberInfo(const string& external_name,
73  const string& name,
75  const string& pointerType,
76  bool optional, const string& defaultValue,
77  bool delayed, int tag,
78  bool noPrefx, bool attlst, bool noTg, bool simpl,
79  const CDataType* dataTp, bool nEmpty,
80  const CComments& comments);
81  };
82  typedef list<SMemberInfo> TMembers;
83 
84  CClassTypeStrings(const string& externalName, const string& className,
85  const string& namespaceName, const CDataType* dataType,
86  const CComments& comments);
87  ~CClassTypeStrings(void);
88 
89  void SetClassNamespace(const CNamespace& ns);
90 
91  const string& GetExternalName(void) const
92  {
93  if (DataType() && !DataType()->HasExternalName()) {
94  return kEmptyStr;
95  }
96  return m_ExternalName;
97  }
98  // DT added to avoid conflict with the standard Windows interfaces
99  const string& GetClassNameDT(void) const
100  {
101  return m_ClassName;
102  }
103 
104  void SetParentClass(const string& className, const CNamespace& ns,
105  const string& fileName);
106 
107  void AddMember(const string& external_name, const string& name,
109  const string& pointerType,
110  bool optional, const string& defaultValue,
111  bool delayed, int tag,
112  bool noPrefix, bool attlist, bool noTag, bool simple,
113  const CDataType* dataType, bool nonEmpty, const CComments& comments);
114  void AddMember(const AutoPtr<CTypeStrings>& type, int tag, bool nonEmpty, bool noPrefix)
115  {
117  false, NcbiEmptyString, false, tag,
118  noPrefix,false,false,false,0,nonEmpty,CComments());
119  }
120 
121  virtual string GetCType(const CNamespace& ns) const override;
122  virtual string GetPrefixedCType(const CNamespace& ns,
123  const string& methodPrefix) const override;
124  virtual string GetRef(const CNamespace& ns) const override;
125 
126  virtual EKind GetKind(void) const override;
127 
128  void SetObject(bool isObject)
129  {
130  m_IsObject = isObject;
131  }
132 
133  bool HaveUserClass(void) const
134  {
135  return m_HaveUserClass;
136  }
137  void SetHaveUserClass(bool haveUserClass)
138  {
139  m_HaveUserClass = haveUserClass;
140  }
141 
142  bool HaveTypeInfo(void) const
143  {
144  return m_HaveTypeInfo;
145  }
146  void SetHaveTypeInfo(bool haveTypeInfo)
147  {
148  m_HaveTypeInfo = haveTypeInfo;
149  }
150 
151  virtual void GenerateTypeCode(CClassContext& ctx) const override;
152  virtual string GetResetCode(const string& var) const override;
153 
154  virtual void GenerateUserHPPCode(CNcbiOstream& out) const override;
155  virtual void GenerateUserCPPCode(CNcbiOstream& out) const override;
156 
157 protected:
158  virtual void GenerateClassCode(CClassCode& code,
159  CNcbiOstream& getters,
160  const string& methodPrefix,
161  bool haveUserClass,
162  const string& classPrefix) const;
163  bool x_IsNullType(TMembers::const_iterator i) const;
164  bool x_IsNullWithAttlist(TMembers::const_iterator i, string& name) const;
165  bool x_IsAnyContentType(TMembers::const_iterator i) const;
166  bool x_IsUniSeq(TMembers::const_iterator i) const;
167 
168 private:
173  string m_ClassName;
177 public:
179 };
180 
182 {
183 public:
184  CClassRefTypeStrings(const string& className, const CNamespace& ns,
185  const string& fileName,
186  const CComments& comments);
187 
188  string GetClassName(void) const;
189  virtual string GetCType(const CNamespace& ns) const override;
190  virtual string GetPrefixedCType(const CNamespace& ns,
191  const string& methodPrefix) const override;
192  virtual string GetRef(const CNamespace& ns) const override;
193 
194  virtual EKind GetKind(void) const override;
195  virtual const CNamespace& GetNamespace(void) const override;
196 
197  virtual string GetResetCode(const string& var) const override;
198 
199  virtual void GenerateTypeCode(CClassContext& ctx) const override;
200  virtual void GeneratePointerTypeCode(CClassContext& ctx) const override;
201 
202 private:
203  string m_ClassName;
205  string m_FileName;
206 };
207 
209 {
211 public:
212  CWsdlTypeStrings(const string& externalName, const string& className,
213  const string& namespaceName, const CDataType* dataType,
214  const CComments& comments);
215  ~CWsdlTypeStrings(void);
216 
217  virtual void GenerateTypeCode(CClassContext& ctx) const override;
218  virtual void GenerateClassCode( CClassCode& code, CNcbiOstream& setters,
219  const string& methodPrefix, bool haveUserClass,
220  const string& classPrefix) const override;
221 };
222 
224 
225 #endif
string GetClassName(void) const
Definition: classstr.cpp:1860
virtual string GetResetCode(const string &var) const override
Definition: classstr.cpp:1881
virtual string GetRef(const CNamespace &ns) const override
Definition: classstr.cpp:1876
virtual void GeneratePointerTypeCode(CClassContext &ctx) const override
Definition: classstr.cpp:1849
CNamespace m_Namespace
Definition: classstr.hpp:204
virtual EKind GetKind(void) const override
Definition: classstr.cpp:1824
virtual string GetPrefixedCType(const CNamespace &ns, const string &methodPrefix) const override
Definition: classstr.cpp:1870
virtual string GetCType(const CNamespace &ns) const override
Definition: classstr.cpp:1865
virtual const CNamespace & GetNamespace(void) const override
Definition: classstr.cpp:1829
virtual void GenerateTypeCode(CClassContext &ctx) const override
Definition: classstr.cpp:1834
CClassRefTypeStrings(const string &className, const CNamespace &ns, const string &fileName, const CComments &comments)
Definition: classstr.cpp:1813
const string & GetExternalName(void) const
Definition: classstr.hpp:91
bool x_IsNullType(TMembers::const_iterator i) const
Definition: classstr.cpp:73
virtual void GenerateUserCPPCode(CNcbiOstream &out) const override
Definition: classstr.cpp:1803
CTypeStrings CParent
Definition: classstr.hpp:48
void AddMember(const AutoPtr< CTypeStrings > &type, int tag, bool nonEmpty, bool noPrefix)
Definition: classstr.hpp:114
virtual string GetCType(const CNamespace &ns) const override
Definition: classstr.cpp:201
string m_ParentClassFileName
Definition: classstr.hpp:176
string m_ExternalName
Definition: classstr.hpp:172
virtual string GetResetCode(const string &var) const override
Definition: classstr.cpp:221
void SetParentClass(const string &className, const CNamespace &ns, const string &fileName)
Definition: classstr.cpp:226
virtual void GenerateClassCode(CClassCode &code, CNcbiOstream &getters, const string &methodPrefix, bool haveUserClass, const string &classPrefix) const
Definition: classstr.cpp:319
bool x_IsUniSeq(TMembers::const_iterator i) const
Definition: classstr.cpp:107
CClassTypeStrings(const string &externalName, const string &className, const string &namespaceName, const CDataType *dataType, const CComments &comments)
Definition: classstr.cpp:53
void SetHaveTypeInfo(bool haveTypeInfo)
Definition: classstr.hpp:146
TMembers m_Members
Definition: classstr.hpp:178
virtual void GenerateTypeCode(CClassContext &ctx) const override
Definition: classstr.cpp:256
~CClassTypeStrings(void)
Definition: classstr.cpp:64
bool x_IsNullWithAttlist(TMembers::const_iterator i, string &name) const
Definition: classstr.cpp:79
void SetClassNamespace(const CNamespace &ns)
list< SMemberInfo > TMembers
Definition: classstr.hpp:82
bool HaveUserClass(void) const
Definition: classstr.hpp:133
string m_ParentClassName
Definition: classstr.hpp:174
void SetObject(bool isObject)
Definition: classstr.hpp:128
virtual string GetRef(const CNamespace &ns) const override
Definition: classstr.cpp:216
bool x_IsAnyContentType(TMembers::const_iterator i) const
Definition: classstr.cpp:98
bool HaveTypeInfo(void) const
Definition: classstr.hpp:142
virtual EKind GetKind(void) const override
Definition: classstr.cpp:68
void SetHaveUserClass(bool haveUserClass)
Definition: classstr.hpp:137
virtual string GetPrefixedCType(const CNamespace &ns, const string &methodPrefix) const override
Definition: classstr.cpp:206
CNamespace m_ParentClassNamespace
Definition: classstr.hpp:175
virtual void GenerateUserHPPCode(CNcbiOstream &out) const override
Definition: classstr.cpp:1650
void AddMember(const string &external_name, const string &name, const AutoPtr< CTypeStrings > &type, const string &pointerType, bool optional, const string &defaultValue, bool delayed, int tag, bool noPrefix, bool attlist, bool noTag, bool simple, const CDataType *dataType, bool nonEmpty, const CComments &comments)
Definition: classstr.cpp:112
const string & GetClassNameDT(void) const
Definition: classstr.hpp:99
const CDataType * DataType(void) const
Definition: typestr.hpp:135
CWsdlTypeStrings(const string &externalName, const string &className, const string &namespaceName, const CDataType *dataType, const CComments &comments)
Definition: wsdlstr.cpp:48
virtual void GenerateClassCode(CClassCode &code, CNcbiOstream &setters, const string &methodPrefix, bool haveUserClass, const string &classPrefix) const override
Definition: wsdlstr.cpp:165
CClassTypeStrings CParent
Definition: classstr.hpp:210
virtual void GenerateTypeCode(CClassContext &ctx) const override
Definition: wsdlstr.cpp:80
~CWsdlTypeStrings(void)
Definition: wsdlstr.cpp:55
std::ofstream out("events_result.xml")
main entry point for tests
CS_CONTEXT * ctx
Definition: t0006.c:12
#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
#define kEmptyStr
Definition: ncbistr.hpp:123
#define NcbiEmptyString
Definition: ncbistr.hpp:122
int i
const GenericPointer< typename T::ValueType > T2 defaultValue
Definition: pointer.h:1126
const char * tag
Useful/utility classes and methods.
const CDataType * dataType
Definition: classstr.hpp:69
SMemberInfo(const string &external_name, const string &name, const AutoPtr< CTypeStrings > &type, const string &pointerType, bool optional, const string &defaultValue, bool delayed, int tag, bool noPrefx, bool attlst, bool noTg, bool simpl, const CDataType *dataTp, bool nEmpty, const CComments &comments)
Definition: classstr.cpp:130
AutoPtr< CTypeStrings > type
Definition: classstr.hpp:55
Definition: inftrees.h:24
Definition: type.c:6
Modified on Mon Jun 24 05:23:21 2024 by modify_doxy.py rev. 669887