5 #include "fileoutputstream.h" 10 using Poco::DirectoryIterator;
13 using Poco::Util::AbstractConfiguration;
14 using Poco::Util::Application;
15 using Poco::Util::HelpFormatter;
16 using Poco::Util::Option;
17 using Poco::Util::OptionCallback;
18 using Poco::Util::OptionSet;
22 inline void getAPIName(
string name,
const string &apiFile,
string &apiName)
24 std::transform(name.begin(), name.end(), name.begin(), ::tolower);
26 std::transform(name.begin(), name.begin() + 1, name.begin(), ::toupper);
28 string fileName = p.getBaseName();
29 std::string::size_type pos = fileName.find(
'.');
30 if (pos != std::string::npos)
31 apiName = fileName.substr(0, pos) + name;
33 apiName = fileName + name;
34 std::transform(apiName.begin(), apiName.begin() + 1, apiName.begin(), ::toupper);
41 : _nameSpace(nameSpace)
44 if (!_nameSpace.empty())
46 stream <<
"namespace " << _nameSpace <<
" {" << endl;
54 if (!_nameSpace.empty())
57 _stream <<
"} //" << _nameSpace << endl;
66 template <
class StreamType = ApiFileOutputStream >
class ScopedStream 75 ScopedStream(StreamType &stream,
bool brackets =
true, IndentType indent = INC)
81 stream <<
"{" << endl;
95 _stream <<
"}" << endl;
103 template <
size_t N,
class StreamType = ApiFileOutputStream >
class ScopedClass 105 array< const char *, N > parentClasses;
108 template <
typename... T,
typename enable_if<
sizeof...(T) == N,
int >::type = 0 >
109 ScopedClass(StreamType &stream,
const string &className, T... args)
110 : parentClasses{{args}...}
112 , _className(className)
114 stream <<
"class " << className;
116 for (
auto &parentClass : parentClasses)
122 stream <<
" public " << parentClass;
132 stream <<
"public:" << endl;
140 if (!_className.empty())
143 _stream <<
"}; //" << _className << endl;
153 template <
size_t N,
class StreamType = ApiFileOutputStream >
class ScopedStruct 155 array< const char *, N > parentClasses;
158 template <
typename... T,
typename enable_if<
sizeof...(T) == N,
int >::type = 0 >
159 ScopedStruct(StreamType &stream,
const string &className, T... args)
160 : parentClasses{args...}
162 , _className(className)
164 stream <<
"struct " << className;
166 for (
auto &parentClass : parentClasses)
172 stream <<
" public " << parentClass;
183 if (!_className.empty())
186 _stream << trader::endl;
187 _stream <<
"}" << trader::cendl;
188 _stream << trader::endl;
199 stream <<
"#pragma once " << endl;
201 va_start(arguments, num);
202 for (Int32 cnt = 0; cnt < num; cnt++)
204 const char *fileName = va_arg(arguments,
const char *);
205 stream <<
"#include \"" << fileName <<
"\"" << endl;
214 stream <<
"#include \"stdafx.h\" " << endl;
216 va_start(arguments, num);
217 for (Int32 cnt = 0; cnt < num; cnt++)
219 const char *fileName = va_arg(arguments,
const char *);
220 stream <<
"#include \"" << fileName <<
"\"" << endl;
228 cpp << className <<
"::" << className <<
"() ";
232 va_start(arguments, num);
233 poco_assert(num % 2 == 0);
234 for (Int32 cnt = 0; cnt < num; cnt += 2)
236 const char *str = va_arg(arguments,
const char *);
237 cpp << str <<
" = \"" << va_arg(arguments,
const char *) <<
"\"" << cendl;
242 cpp << className <<
"::~" << className <<
"() ";
249 inline void construct_header(
ApiFileOutputStream &stream,
const string &className, Int32 num, ...)
251 stream << className <<
"(";
253 va_start(arguments, num);
254 poco_assert(num % 2 == 0);
255 for (Int32 cnt = 0; cnt < num; cnt += 2)
259 const char *str = va_arg(arguments,
const char *);
260 stream << str <<
" " << va_arg(arguments,
const char *);
262 stream <<
")" << cendl;
265 stream <<
"~" << className <<
"()" << cendl;
269 inline void construct_ex(
ApiFileOutputStream &cpp,
const string &className, Int32 numParams, Int32 numInitializer,
270 Int32 numStatements, ...)
272 cpp << className <<
"::" << className <<
"(";
274 va_start(arguments, numStatements);
275 poco_assert(numParams % 2 == 0);
276 for (Int32 cnt = 0; cnt < numParams; cnt += 2)
280 const char *str = va_arg(arguments,
const char *);
281 cpp << str <<
" " << va_arg(arguments,
const char *);
286 poco_assert(numInitializer % 2 == 0);
287 for (Int32 cnt = 0; cnt < numInitializer; cnt += 2)
289 const char *str = va_arg(arguments,
const char *);
290 cpp << str <<
" = " << va_arg(arguments,
const char *) << trader::cendl;
292 for (Int32 cnt = 0; cnt < numStatements; cnt++)
294 cpp << va_arg(arguments,
const char *) << trader::endl;
299 cpp << className <<
"::~" << className <<
"() ";
306 inline std::string &replace(std::string &str,
const char *from,
const char *to)
308 size_t start_pos = 0;
309 while ((start_pos = str.find(from, start_pos)) != std::string::npos)
311 str.replace(start_pos, strlen(from), to);
312 start_pos += strlen(to);
319 #define CODEGEN_DEBUG(x) x 321 #define CODEGEN_DEBUG(x) Definition: fileoutputstream.h:61
Definition: helpers.h:103
Definition: fileoutputstream.h:3
Definition: helpers.h:153