NCBI C++ ToolKit
stdstr.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: stdstr.cpp 85756 2019-03-08 15:00:32Z gouriano $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Eugene Vasilchenko
27 *
28 * File Description:
29 * Type info for class generation: includes, used classes, C code etc.
30 *
31 */
32 
33 #include <ncbi_pch.hpp>
34 #include "stdstr.hpp"
35 #include "classctx.hpp"
36 
38 
39 CStdTypeStrings::CStdTypeStrings(const string& type, const CComments& comments, bool full_ns_name)
40  : CTypeStrings(comments), m_CType(type), m_BigInt(false)
41 {
42  SIZE_TYPE colon = type.rfind("::");
43  if ( colon != NPOS ) {
44  m_CType = type.substr(colon + 2);
45  m_Namespace = type.substr(0, colon);
46  m_Namespace.UseFullname(full_ns_name);
47  }
48 }
49 
51 {
52  return eKindStd;
53 }
54 
55 string CStdTypeStrings::GetCType(const CNamespace& ns) const
56 {
57  if ( m_Namespace )
59  else
60  return m_CType;
61 }
62 
63 void CStdTypeStrings::SetStorageType(const string& storage)
64 {
65  m_Storage = storage;
66 }
67 
69 {
70  if (m_Storage.empty()) {
71  return GetCType(ns);
72  }
73  return m_Storage;
74 }
75 
76 void CStdTypeStrings::SetBigInt(bool is_big)
77 {
78  m_BigInt = is_big;
79 }
80 
82  const string& /*methodPrefix*/) const
83 {
84  return GetCType(ns);
85 }
86 
87 string CStdTypeStrings::GetRef(const CNamespace& ns) const
88 {
89  if (HaveSpecialRef()) {
90  return CTypeStrings::GetRef(ns);
91  }
92  return "STD, ("+GetCType(ns)+')';
93 }
94 
96 {
97  return m_BigInt ? "0LL" : "0";
98 }
99 
101  : CTypeStrings(comments)
102 {
103 }
104 
106 {
107  return eKindStd;
108 }
109 
111 {
112  return true;
113 }
114 
115 string CNullTypeStrings::GetCType(const CNamespace& /*ns*/) const
116 {
117  return "bool";
118 }
119 
121  const string& /*methodPrefix*/) const
122 {
123  return GetCType(ns);
124 }
125 
126 string CNullTypeStrings::GetRef(const CNamespace& /*ns*/) const
127 {
128  return "null, ()";
129 }
130 
132 {
133  return "true";
134 }
135 
137  const CComments& comments, bool full_ns_name)
138  : CParent(type,comments,full_ns_name)
139 {
140 }
141 
143 {
144  return eKindString;
145 }
146 
148 {
149  return string();
150 }
151 
152 string CStringTypeStrings::GetResetCode(const string& var) const
153 {
154  return var+".erase();\n";
155 }
156 
158 {
159  ctx.HPPIncludes().insert("<string>");
160 }
161 
163  const CComments& comments, bool full_ns_name)
164  : CParent(type,comments,full_ns_name)
165 {
166 }
167 
169 {
170  return true;
171 }
172 
173 string CStringStoreTypeStrings::GetRef(const CNamespace& /*ns*/) const
174 {
175  return "StringStore, ()";
176 }
177 
179  const CComments& comments, bool full_ns_name)
180  : CParent(type,comments,full_ns_name)
181 {
182 }
183 
185 {
186  return eKindObject;
187 }
188 
190 {
191  return string();
192 }
193 
194 string CAnyContentTypeStrings::GetResetCode(const string& var) const
195 {
196  return var+".Reset();\n";
197 }
198 
200 {
201 }
202 
203 
205  const CComments& comments, CTypeStrings* bitNames)
206  : CParent(type,comments,false), m_BitNames(bitNames)
207 {
208 }
209 
211 {
212  return eKindOther;
213 }
214 
216 {
217  return string();
218 }
219 
220 string CBitStringTypeStrings::GetResetCode(const string& var) const
221 {
222 // return var+".clear();\n";
223  return var+".resize(0);\n";
224 }
225 
227 {
228 // ctx.HPPIncludes().insert("<vector>");
229  if (m_BitNames) {
231  }
232 }
233 
#define false
Definition: bool.h:36
virtual string GetResetCode(const string &var) const override
Definition: stdstr.cpp:194
virtual void GenerateTypeCode(CClassContext &ctx) const override
Definition: stdstr.cpp:199
virtual EKind GetKind(void) const override
Definition: stdstr.cpp:184
virtual string GetInitializer(void) const override
Definition: stdstr.cpp:189
CAnyContentTypeStrings(const string &type, const CComments &comments, bool full_ns_name)
Definition: stdstr.cpp:178
virtual string GetResetCode(const string &var) const override
Definition: stdstr.cpp:220
virtual EKind GetKind(void) const override
Definition: stdstr.cpp:210
virtual string GetInitializer(void) const override
Definition: stdstr.cpp:215
AutoPtr< CTypeStrings > m_BitNames
Definition: stdstr.hpp:135
CBitStringTypeStrings(const string &type, const CComments &comments, CTypeStrings *bit_names)
Definition: stdstr.cpp:204
virtual void GenerateTypeCode(CClassContext &ctx) const override
Definition: stdstr.cpp:226
string GetNamespaceRef(const CNamespace &ns) const
Definition: namespace.cpp:97
void UseFullname(bool full)
Definition: namespace.hpp:52
virtual string GetCType(const CNamespace &ns) const override
Definition: stdstr.cpp:115
CNullTypeStrings(const CComments &comments)
Definition: stdstr.cpp:100
virtual bool HaveSpecialRef(void) const override
Definition: stdstr.cpp:110
virtual string GetInitializer(void) const override
Definition: stdstr.cpp:131
virtual string GetPrefixedCType(const CNamespace &ns, const string &methodPrefix) const override
Definition: stdstr.cpp:120
virtual EKind GetKind(void) const override
Definition: stdstr.cpp:105
virtual string GetRef(const CNamespace &ns) const override
Definition: stdstr.cpp:126
virtual string GetPrefixedCType(const CNamespace &ns, const string &methodPrefix) const override
Definition: stdstr.cpp:81
virtual void SetStorageType(const string &storage) override
Definition: stdstr.cpp:63
CStdTypeStrings(const string &type, const CComments &comments, bool full_ns_name)
Definition: stdstr.cpp:39
void SetBigInt(bool is_big=true)
Definition: stdstr.cpp:76
virtual string GetCType(const CNamespace &ns) const override
Definition: stdstr.cpp:55
CNamespace m_Namespace
Definition: stdstr.hpp:60
virtual EKind GetKind(void) const override
Definition: stdstr.cpp:50
string m_Storage
Definition: stdstr.hpp:59
virtual string GetInitializer(void) const override
Definition: stdstr.cpp:95
virtual string GetStorageType(const CNamespace &ns) const override
Definition: stdstr.cpp:68
virtual string GetRef(const CNamespace &ns) const override
Definition: stdstr.cpp:87
string m_CType
Definition: stdstr.hpp:58
virtual string GetRef(const CNamespace &ns) const override
Definition: stdstr.cpp:173
virtual bool HaveSpecialRef(void) const override
Definition: stdstr.cpp:168
CStringStoreTypeStrings(const string &type, const CComments &comments, bool full_ns_name)
Definition: stdstr.cpp:162
CStringTypeStrings(const string &type, const CComments &comments, bool full_ns_name)
Definition: stdstr.cpp:136
virtual EKind GetKind(void) const override
Definition: stdstr.cpp:142
virtual string GetResetCode(const string &var) const override
Definition: stdstr.cpp:152
virtual void GenerateTypeCode(CClassContext &ctx) const override
Definition: stdstr.cpp:157
virtual string GetInitializer(void) const override
Definition: stdstr.cpp:147
virtual bool HaveSpecialRef(void) const
Definition: typestr.cpp:129
virtual void GenerateTypeCode(CClassContext &ctx) const
Definition: typestr.cpp:220
virtual string GetRef(const CNamespace &ns) const
Definition: typestr.cpp:134
CS_CONTEXT * ctx
Definition: t0006.c:12
string
Definition: cgiapp.hpp:687
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
#define NPOS
Definition: ncbistr.hpp:133
Definition: type.c:6
Modified on Mon Dec 11 02:40:03 2023 by modify_doxy.py rev. 669887