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

Go to the SVN repository for this file.

1 #ifndef GENERATE_HPP
2 #define GENERATE_HPP
3 
4 /* $Id: generate.hpp 98952 2023-01-26 12:56:13Z 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 * Main generator: collects types, classes and files.
33 */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbireg.hpp>
37 #include <set>
38 #include <map>
39 #include "moduleset.hpp"
40 #include "namespace.hpp"
41 
43 
44 class CFileCode;
45 
47 {
48 public:
51 
52  CCodeGenerator(void);
53  ~CCodeGenerator(void);
54 
55  // setup interface
56  void LoadConfig(CNcbiIstream& in);
57  void LoadConfig(const string& fileName, bool ignoreAbsense = false,
58  bool warningAbsense = true);
59  void AddConfigLine(const string& s);
60 
61  void IncludeTypes(const string& types);
62  void ExcludeTypes(const string& types);
63  void ExcludeRecursion(bool exclude = true)
64  {
65  m_ExcludeRecursion = exclude;
66  }
67  void IncludeAllMainTypes(void);
68  bool HaveGenerateTypes(void) const
69  {
70  return !m_GenerateTypes.empty();
71  }
72 
73  void SetCPPDir(const string& dir)
74  {
75  m_CPPDir = dir;
76  }
77  const string& GetCPPDir(void) const
78  {
79  return m_CPPDir;
80  }
81  void SetHPPDir(const string& dir)
82  {
83  m_HPPDir = dir;
84  }
85  void SetFileListFileName(const string& file)
86  {
88  }
89  void SetCombiningFileName(const string& file)
90  {
92  }
93 
95  {
96  return m_MainFiles;
97  }
98  const CFileSet& GetMainModules(void) const
99  {
100  return m_MainFiles;
101  }
103  {
104  return m_ImportFiles;
105  }
106  const CFileSet& GetImportModules(void) const
107  {
108  return m_ImportFiles;
109  }
110  const string& GetDefFile(void) const
111  {
112  return m_DefFile;
113  }
114  void SetRootDir(const string& dir)
115  {
116  m_RootDir = dir;
117  }
118  const string& GetRootDir(void) const
119  {
120  return m_RootDir;
121  }
122 
123  bool Check(void) const;
124 
125  void CheckFileNames(void);
126  void GenerateCode(void);
127  void UndoGenerateCode(void);
128  void GenerateDoxygenGroupDescription(map<string, pair<string,string> >& module_names);
129  void GenerateFileList(const list<string>& generated, const list<string>& untouched,
130  list<string>& allGeneratedHpp, list<string>& allGeneratedCpp,
131  list<string>& allSkippedHpp, list<string>& allSkippedCpp);
132  void GenerateCombiningFile(const list<string>& module_inc, const list<string>& module_src,
133  list<string>& allHpp, list<string>& allCpp);
134  bool IsGitRepository(const string& dir) const;
135  void GenerateCvsignore(const string& outdir_cpp, const string& outdir_hpp,
136  const list<string>& generated, map<string, pair<string,string> >& module_names);
137  void GenerateModuleHPP(const string& path, list<string>& generated) const;
138  void GenerateModuleCPP(const string& path, list<string>& generated) const;
139 
140  void GenerateClientCode(list<string>& generated);
141  void GenerateClientCode(const string& name, bool mandatory, list<string>& generated);
142 
143  bool Imported(const CDataType* type) const;
144 
145  // generation interface
146  virtual const CMemoryRegistry& GetConfig(void) const override;
147  virtual string GetFileNamePrefix(void) const override;
148  void UseQuotedForm(bool use);
149  void CreateCvsignore(bool create);
150  void SetFileNamePrefix(const string& prefix);
151  virtual EFileNamePrefixSource GetFileNamePrefixSource(void) const override;
153  virtual CDataType* InternalResolve(const string& moduleName,
154  const string& typeName) const override;
155 
156  void SetDefaultNamespace(const string& ns);
157  void ResetDefaultNamespace(void);
158  virtual const CNamespace& GetNamespace(void) const override;
159 
160  CDataType* ExternalResolve(const string& module, const string& type,
161  bool allowInternal = false) const;
162  CDataType* ResolveInAnyModule(const string& type,
163  bool allowInternal = false) const;
164 
165  CDataType* ResolveMain(const string& fullName) const;
166  const string& ResolveFileName(const string& name) const;
167 
168  void SetDoxygenIngroup(const string& str)
169  {
171  }
172  void SetDoxygenGroupDescription(const string& str)
173  {
175  }
176  void ResolveImportRefs(void);
178  const CDataTypeModule* FindModuleByName(const string& name) const;
179 
180  bool GetOpt(const string& opt, string* value=0);
181 
182 protected:
183 
184  static void GetTypes(TTypeNames& typeNames, const string& name);
185 
186  enum EContext {
191  eMember
192  };
193  void CollectTypes(const CDataType* type, EContext context );
194  bool AddType(const CDataType* type);
195 
196 private:
197 
205  string m_HPPDir;
206  string m_CPPDir;
214  string m_DefFile;
215  string m_RootDir;
216 
218 };
219 
221 
222 #endif
void UseQuotedForm(bool use)
Definition: generate.cpp:82
string m_DefFile
Definition: generate.hpp:214
const string & GetCPPDir(void) const
Definition: generate.hpp:77
string m_HPPDir
Definition: generate.hpp:205
const CFileSet & GetImportModules(void) const
Definition: generate.hpp:106
string m_FileListFileName
Definition: generate.hpp:203
void CheckFileNames(void)
Definition: generate.cpp:330
bool m_ExcludeRecursion
Definition: generate.hpp:202
string m_DoxygenGroupDescription
Definition: generate.hpp:213
void ResolveImportRefs(void)
Definition: generate.cpp:1217
void SetFileNamePrefix(const string &prefix)
Definition: generate.cpp:92
void GenerateModuleHPP(const string &path, list< string > &generated) const
Definition: generate.cpp:787
string m_CPPDir
Definition: generate.hpp:206
void LoadConfig(CNcbiIstream &in)
Definition: generate.cpp:129
CFileSet & GetMainModules(void)
Definition: generate.hpp:94
string m_CombiningFileName
Definition: generate.hpp:204
bool HaveGenerateTypes(void) const
Definition: generate.hpp:68
CNamespace m_DefaultNamespace
Definition: generate.hpp:209
void GenerateFileList(const list< string > &generated, const list< string > &untouched, list< string > &allGeneratedHpp, list< string > &allGeneratedCpp, list< string > &allSkippedHpp, list< string > &allSkippedCpp)
Definition: generate.cpp:454
CDataType * ExternalResolve(const string &module, const string &type, bool allowInternal=false) const
Definition: generate.cpp:173
const string & GetRootDir(void) const
Definition: generate.hpp:118
void SetDoxygenIngroup(const string &str)
Definition: generate.hpp:168
static void GetTypes(TTypeNames &typeNames, const string &name)
Definition: generate.cpp:251
void ExcludeRecursion(bool exclude=true)
Definition: generate.hpp:63
CMemoryRegistry m_Config
Definition: generate.hpp:198
virtual string GetFileNamePrefix(void) const override
Definition: generate.cpp:77
void GenerateDoxygenGroupDescription(map< string, pair< string, string > > &module_names)
Definition: generate.cpp:407
bool Check(void) const
Definition: generate.cpp:263
EFileNamePrefixSource m_FileNamePrefixSource
Definition: generate.hpp:208
void GenerateClientCode(list< string > &generated)
Definition: generate.cpp:973
virtual const CMemoryRegistry & GetConfig(void) const override
Definition: generate.cpp:72
void GenerateCode(void)
Definition: generate.cpp:344
void GenerateCvsignore(const string &outdir_cpp, const string &outdir_hpp, const list< string > &generated, map< string, pair< string, string > > &module_names)
Definition: generate.cpp:686
void SetRootDir(const string &dir)
Definition: generate.hpp:114
void SetHPPDir(const string &dir)
Definition: generate.hpp:81
string m_RootDir
Definition: generate.hpp:215
CCodeGenerator(void)
Definition: generate.cpp:59
void AddConfigLine(const string &s)
Definition: generate.cpp:160
CDataType * ResolveInAnyModule(const string &type, bool allowInternal=false) const
Definition: generate.cpp:192
bool m_CreateCvsignore
Definition: generate.hpp:211
TTypeNames m_GenerateTypes
Definition: generate.hpp:201
void SetFileNamePrefixSource(EFileNamePrefixSource source)
Definition: generate.cpp:102
void ExcludeTypes(const string &types)
Definition: generate.cpp:269
const CFileSet & GetMainModules(void) const
Definition: generate.hpp:98
~CCodeGenerator(void)
Definition: generate.cpp:68
void SetCPPDir(const string &dir)
Definition: generate.hpp:73
void SetFileListFileName(const string &file)
Definition: generate.hpp:85
CFileSet m_MainFiles
Definition: generate.hpp:199
void CollectTypes(const CDataType *type, EContext context)
Definition: generate.cpp:1041
bool GetOpt(const string &opt, string *value=0)
Definition: generate.cpp:1260
string m_FileNamePrefix
Definition: generate.hpp:207
void SetDefaultNamespace(const string &ns)
Definition: generate.cpp:119
virtual const CNamespace & GetNamespace(void) const override
Definition: generate.cpp:114
virtual CDataType * InternalResolve(const string &moduleName, const string &typeName) const override
Definition: generate.cpp:108
bool Imported(const CDataType *type) const
Definition: generate.cpp:1028
void SetCombiningFileName(const string &file)
Definition: generate.hpp:89
map< string, AutoPtr< CFileCode > > TOutputFiles
Definition: generate.hpp:50
void UndoGenerateCode(void)
Definition: generate.cpp:292
bool IsGitRepository(const string &dir) const
Definition: generate.cpp:667
const string & GetDefFile(void) const
Definition: generate.hpp:110
void ResetDefaultNamespace(void)
Definition: generate.cpp:124
TOutputFiles m_Files
Definition: generate.hpp:217
void GenerateModuleCPP(const string &path, list< string > &generated) const
Definition: generate.cpp:870
void CreateCvsignore(bool create)
Definition: generate.cpp:87
bool m_UseQuotedForm
Definition: generate.hpp:210
CDataType * ResolveMain(const string &fullName) const
Definition: generate.cpp:210
CFileSet m_ImportFiles
Definition: generate.hpp:200
CFileSet & GetImportModules(void)
Definition: generate.hpp:102
bool AddType(const CDataType *type)
Definition: generate.cpp:1019
string m_DoxygenIngroup
Definition: generate.hpp:212
void IncludeAllMainTypes(void)
Definition: generate.cpp:234
const CDataTypeModule * FindModuleByName(const string &name) const
Definition: generate.cpp:1240
void IncludeTypes(const string &types)
Definition: generate.cpp:279
void SetDoxygenGroupDescription(const string &str)
Definition: generate.hpp:172
virtual EFileNamePrefixSource GetFileNamePrefixSource(void) const override
Definition: generate.cpp:97
const string & ResolveFileName(const string &name) const
Definition: generate.cpp:225
set< string > TTypeNames
Definition: generate.hpp:49
void GenerateCombiningFile(const list< string > &module_inc, const list< string > &module_src, list< string > &allHpp, list< string > &allCpp)
Definition: generate.cpp:600
CMemoryRegistry –.
Definition: ncbireg.hpp:584
Definition: map.hpp:338
bool empty() const
Definition: set.hpp:133
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define head
Definition: ct_nlmzip_i.h:138
vector< string > TTypeNames
static const char * str(char *buf, int n)
Definition: stats.c:84
static const struct type types[]
Definition: type.c:22
#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::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
FILE * file
EFileNamePrefixSource
Definition: mcontainer.hpp:45
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
const CharType(& source)[N]
Definition: pointer.h:1149
Process information in the NCBI Registry, including working with configuration files.
std::istream & in(std::istream &in_, double &x_)
static const char * prefix[]
Definition: pcregrep.c:405
Definition: type.c:6
static CS_CONTEXT * context
Definition: will_convert.c:21
Modified on Wed Apr 17 13:10:49 2024 by modify_doxy.py rev. 669887