DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
utils.cpp File Reference
#include "class_info.hpp"
#include "oks/kernel.hpp"
#include "oks/method.hpp"
#include <ctype.h>
#include <algorithm>
#include <ctime>
#include <initializer_list>
#include <iomanip>
#include <iostream>
Include dependency graph for utils.cpp:

Go to the source code of this file.

Functions

char cvt_symbol (char c)
 
std::string alnum_name (const std::string &in)
 
std::string capitalize_name (const std::string &in)
 
void print_description (std::ostream &s, const std::string &text, const char *dx)
 
void print_indented (std::ostream &s, const std::string &text, const char *dx)
 
std::string get_type (OksData::Type oks_type, bool is_cpp)
 
void gen_dump_application (std::ostream &s, std::list< std::string > &class_names, const std::string &cpp_ns_name, const std::string &cpp_hdr_dir, const char *conf_header, const char *conf_name, const char *headres_prologue, const char *main_function_prologue)
 
void write_info_file (std::ostream &s, const std::string &cpp_namespace, const std::string &cpp_header_dir, const std::set< const OksClass *, std::less< const OksClass * > > &classes)
 
std::string get_full_cpp_class_name (const OksClass *c, const ClassInfo::Map &cl_info, const std::string &cpp_ns_name)
 
std::string get_include_dir (const OksClass *c, const ClassInfo::Map &cl_info, const std::string &cpp_hdr_dir)
 
bool process_external_class (ClassInfo::Map &cl_info, const OksClass *c, const std::list< std::string > &include_dirs, const std::list< std::string > &user_classes, bool verbose)
 
std::string int2dx (int level)
 
int open_cpp_namespace (std::ostream &s, const std::string &value)
 
void close_cpp_namespace (std::ostream &s, int level)
 
const std::string begin_header_prologue ("BEGIN_HEADER_PROLOGUE")
 
const std::string end_header_prologue ("END_HEADER_PROLOGUE")
 
const std::string begin_header_epilogue ("BEGIN_HEADER_EPILOGUE")
 
const std::string end_header_epilogue ("END_HEADER_EPILOGUE")
 
const std::string begin_public_section ("BEGIN_PUBLIC_SECTION")
 
const std::string end_public_section ("END_PUBLIC_SECTION")
 
const std::string begin_private_section ("BEGIN_PRIVATE_SECTION")
 
const std::string end_private_section ("END_PRIVATE_SECTION")
 
const std::string begin_member_initializer_list ("BEGIN_MEMBER_INITIALIZER_LIST")
 
const std::string end_member_initializer_list ("END_MEMBER_INITIALIZER_LIST")
 
const std::string has_add_algo_1 ("ADD_ALGO_1")
 
const std::string has_add_algo_n ("ADD_ALGO_N")
 
static std::string get_method_header_x_logue (OksMethodImplementation *mi, const std::string &begin, const std::string &end)
 
std::string get_method_header_prologue (OksMethodImplementation *mi)
 
std::string get_method_header_epilogue (OksMethodImplementation *mi)
 
std::string get_public_section (OksMethodImplementation *mi)
 
std::string get_private_section (OksMethodImplementation *mi)
 
std::string get_member_initializer_list (OksMethodImplementation *mi)
 
bool get_add_algo_1 (OksMethodImplementation *mi)
 
bool get_add_algo_n (OksMethodImplementation *mi)
 
static void remove_string_section (std::string &s, const std::string &begin, const std::string &end)
 
std::string get_method_implementation_body (OksMethodImplementation *mi)
 
static OksMethodImplementationfind_method_implementation (const OksMethod *method, std::initializer_list< std::string > names)
 
OksMethodImplementationfind_cpp_method_implementation (const OksMethod *method)
 

Function Documentation

◆ alnum_name()

std::string alnum_name ( const std::string & in)

Definition at line 32 of file utils.cpp.

33{
34 std::string s(in);
35 std::transform(s.begin(), s.end(), s.begin(), cvt_symbol);
36 return s;
37}
char cvt_symbol(char c)
Definition utils.cpp:26

◆ begin_header_epilogue()

const std::string begin_header_epilogue ( "BEGIN_HEADER_EPILOGUE" )

◆ begin_header_prologue()

const std::string begin_header_prologue ( "BEGIN_HEADER_PROLOGUE" )

◆ begin_member_initializer_list()

const std::string begin_member_initializer_list ( "BEGIN_MEMBER_INITIALIZER_LIST" )

◆ begin_private_section()

const std::string begin_private_section ( "BEGIN_PRIVATE_SECTION" )

◆ begin_public_section()

const std::string begin_public_section ( "BEGIN_PUBLIC_SECTION" )

◆ capitalize_name()

std::string capitalize_name ( const std::string & in)

Definition at line 40 of file utils.cpp.

41{
42 std::string s(in);
43 if (!in.empty())
44 {
45 if (isalpha(in[0]))
46 {
47 if (islower(in[0]))
48 s[0] = toupper(in[0]);
49 }
50 else
51 {
52 s.insert(s.begin(), '_');
53 }
54 }
55 return s;
56}

◆ close_cpp_namespace()

void close_cpp_namespace ( std::ostream & s,
int level )

Definition at line 657 of file utils.cpp.

658{
659 while (level > 0)
660 {
661 std::string dx = int2dx(--level);
662 s << dx << "}\n";
663 }
664}
std::string int2dx(int level)
Definition utils.cpp:629

◆ cvt_symbol()

char cvt_symbol ( char c)

The functions cvt_symbol() and alnum_name() are used to replace all symbols allowed in names of classes, attributes and relationships, but misinterpreted by c++.

Definition at line 26 of file utils.cpp.

27{
28 return (isalnum(c) ? c : '_');
29}

◆ end_header_epilogue()

const std::string end_header_epilogue ( "END_HEADER_EPILOGUE" )

◆ end_header_prologue()

const std::string end_header_prologue ( "END_HEADER_PROLOGUE" )

◆ end_member_initializer_list()

const std::string end_member_initializer_list ( "END_MEMBER_INITIALIZER_LIST" )

◆ end_private_section()

const std::string end_private_section ( "END_PRIVATE_SECTION" )

◆ end_public_section()

const std::string end_public_section ( "END_PUBLIC_SECTION" )

◆ find_cpp_method_implementation()

OksMethodImplementation * find_cpp_method_implementation ( const OksMethod * method)

Definition at line 785 of file utils.cpp.

786{
787 return find_method_implementation(method, { "c++", "C++" });
788}
static OksMethodImplementation * find_method_implementation(const OksMethod *method, std::initializer_list< std::string > names)
Definition utils.cpp:772

◆ find_method_implementation()

static OksMethodImplementation * find_method_implementation ( const OksMethod * method,
std::initializer_list< std::string > names )
static

Definition at line 772 of file utils.cpp.

773{
774 for (const auto& name : names)
775 {
776 if (OksMethodImplementation * mi = method->find_implementation(name))
777 if (mi->get_prototype().empty() == false)
778 return mi;
779 }
780
781 return nullptr;
782}
OKS method implementation class.
Definition method.hpp:35
OksMethodImplementation * find_implementation(const std::string &language) const
Find method implementation.
Definition method.cpp:354

◆ gen_dump_application()

void gen_dump_application ( std::ostream & s,
std::list< std::string > & class_names,
const std::string & cpp_ns_name,
const std::string & cpp_hdr_dir,
const char * conf_header,
const char * conf_name,
const char * headres_prologue,
const char * main_function_prologue )

Definition at line 162 of file utils.cpp.

171{
172 s <<
173 " // *** this file is generated by oksdalgen ***\n"
174 "\n"
175 "#include \"conffwk/ConfigObject.hpp\"\n"
176 "#include \"" << conf_header << "\"\n\n";
177
178 // generate list of includes
179 for (const auto& i : class_names)
180 {
181 std::string hname(cpp_hdr_dir);
182 if (!hname.empty())
183 hname += '/';
184 hname += i;
185 s << "#include \"" << hname << ".hpp\"\n";
186 }
187
188 if (headres_prologue && *headres_prologue)
189 {
190 s << "\n // db implementation-specific headrers prologue\n\n" << headres_prologue << "\n";
191 }
192
193 s <<
194 "\n"
195 "\n"
196 "static void usage(const char * s)\n"
197 "{\n"
198 " std::cout << s << \" -d db-name -c class-name [-q query | -i object-id] [-t]\\n\"\n"
199 " \"\\n\"\n"
200 " \"Options/Arguments:\\n\"\n"
201 " \" -d | --data db-name mandatory name of the database\\n\"\n"
202 " \" -c | --class-name class-name mandatory name of class\\n\"\n"
203 " \" -q | --query query optional query to select class objects\\n\"\n"
204 " \" -i | --object-id object-id optional identity to select one object\\n\"\n"
205 " \" -t | --init-children all referenced objects are initialized (is used\\n\"\n"
206 " \" for debug purposes and performance measurements)\\n\"\n"
207 " \" -h | --help print this message\\n\"\n"
208 " \"\\n\"\n"
209 " \"Description:\\n\"\n"
210 " \" The program prints out object(s) of given class.\\n\"\n"
211 " \" If no query or object id is provided, all objects of the class are printed.\\n\"\n"
212 " \" It is automatically generated by oksdalgen utility.\\n\"\n"
213 " \"\\n\";\n"
214 "}\n"
215 "\n"
216 "static void no_param(const char * s)\n"
217 "{\n"
218 " std::cerr << \"ERROR: the required argument for option \\\'\" << s << \"\\\' is missing\\n\\n\";\n"
219 " exit (EXIT_FAILURE);\n"
220 "}\n"
221 "\n"
222 "int main(int argc, char *argv[])\n"
223 "{\n";
224
225 if (main_function_prologue && *main_function_prologue)
226 {
227 s << " // db implementation-specific main function prologue\n\n " << main_function_prologue << "\n\n";
228 }
229
230 s <<
231 " // parse parameters\n"
232 "\n"
233 " const char * db_name = nullptr;\n"
234 " const char * object_id = nullptr;\n"
235 " const char * query = \"\";\n"
236 " std::string class_name;\n"
237 " bool init_children = false;\n"
238 "\n"
239 " for(int i = 1; i < argc; i++) {\n"
240 " const char * cp = argv[i];\n"
241 " if(!strcmp(cp, \"-h\") || !strcmp(cp, \"--help\")) {\n"
242 " usage(argv[0]);\n"
243 " return 0;\n"
244 " }\n"
245 " if(!strcmp(cp, \"-t\") || !strcmp(cp, \"--init-children\")) {\n"
246 " init_children = true;\n"
247 " }\n"
248 " else if(!strcmp(cp, \"-d\") || !strcmp(cp, \"--data\")) {\n"
249 " if(++i == argc || argv[i][0] == '-') { no_param(cp); } else { db_name = argv[i]; }\n"
250 " }\n"
251 " else if(!strcmp(cp, \"-c\") || !strcmp(cp, \"--class-name\")) {\n"
252 " if(++i == argc || argv[i][0] == '-') { no_param(cp); } else { class_name = argv[i]; }\n"
253 " }\n"
254 " else if(!strcmp(cp, \"-i\") || !strcmp(cp, \"--object-id\")) {\n"
255 " if(++i == argc || argv[i][0] == '-') { no_param(cp); } else { object_id = argv[i]; }\n"
256 " }\n"
257 " else if(!strcmp(cp, \"-q\") || !strcmp(cp, \"--query\")) {\n"
258 " if(++i == argc || argv[i][0] == '-') { no_param(cp); } else { query = argv[i]; }\n"
259 " }\n"
260 " else {\n"
261 " std::cerr << \"ERROR: bad parameter \" << cp << std::endl;\n"
262 " usage(argv[0]);\n"
263 " return (EXIT_FAILURE);\n"
264 " }\n"
265 " }\n"
266 "\n"
267 " if(db_name == nullptr) {\n"
268 " std::cerr << \"ERROR: no database name provided\\n\";\n"
269 " return (EXIT_FAILURE);\n"
270 " }\n"
271 "\n"
272 " if(class_name.empty()) {\n"
273 " std::cerr << \"ERROR: no class name provided\\n\";\n"
274 " return (EXIT_FAILURE);\n"
275 " }\n"
276 "\n"
277 " if(*query != 0 && object_id != nullptr) {\n"
278 " std::cerr << \"ERROR: only one parameter -i or -q can be provided\\n\";\n"
279 " return (EXIT_FAILURE);\n"
280 " }\n"
281 "\n"
282 "\n"
283 "std::cout << std::boolalpha;\n"
284 "\n";
285
286 if (conf_name)
287 {
288 s <<
289 " " << conf_name << " impl_conf;\n"
290 "\n"
291 " {\n"
292 " dunedaq::conffwk::Configuration conf(db_name, &impl_conf);\n";
293 }
294 else
295 {
296 s <<
297 " try {\n"
298 " dunedaq::conffwk::Configuration conf(db_name);\n";
299 }
300
301 s <<
302 "\n"
303 " if(!conf.loaded()) {\n"
304 " std::cerr << \"Can not load database: \" << db_name << std::endl;\n"
305 " return (EXIT_FAILURE);\n"
306 " }\n"
307 " \n"
308 " std::vector< dunedaq::conffwk::ConfigObject > objects;\n"
309 " \n"
310 " if(object_id) {\n"
311 " dunedaq::conffwk::ConfigObject obj;\n"
312 " try {\n"
313 " conf.get(class_name, object_id, obj, 1);\n"
314 " }\n"
315 " catch (dunedaq::conffwk::NotFound & ex) {\n"
316 " std::cerr << \"Can not get object \\'\" << object_id << \"\\' of class \\'\" << class_name << \"\\':\\n\" << ex << std::endl;\n"
317 " return (EXIT_FAILURE);\n"
318 " }\n"
319 " objects.push_back(obj);\n"
320 " }\n"
321 " else {\n"
322 " try {\n"
323 " conf.get(class_name, objects, query, 1);\n"
324 " }\n"
325 " catch (dunedaq::conffwk::NotFound & ex) {\n"
326 " std::cerr << \"Can not get objects of class \\'\" << class_name << \"\\':\\n\" << ex << std::endl;\n"
327 " return (EXIT_FAILURE);\n"
328 " }\n"
329 " }\n"
330 " \n"
331 " struct SortByUId {\n"
332 " bool operator() (const dunedaq::conffwk::ConfigObject * o1, const dunedaq::conffwk::ConfigObject * o2) const {\n"
333 " return (o1->UID() < o2->UID());\n"
334 " };\n"
335 " };\n"
336 " \n"
337 " std::set< dunedaq::conffwk::ConfigObject *, SortByUId > sorted_objects;\n"
338 " \n"
339 " for(auto& i : objects)\n"
340 " sorted_objects.insert(&i);\n"
341 " \n"
342 " for(auto& i : sorted_objects) {\n";
343
344 for (std::list<std::string>::iterator i = class_names.begin(); i != class_names.end(); ++i)
345 {
346 const char * op = (i == class_names.begin() ? "if" : "else if");
347 std::string cname(cpp_ns_name);
348
349 if (!cname.empty())
350 cname += "::";
351
352 cname += *i;
353
354 s <<
355 " " << op << "(class_name == \"" << *i << "\") {\n"
356 " std::cout << *conf.get<" << cname << ">(*i, init_children) << std::endl;\n"
357 " }\n";
358 }
359
360 s <<
361 " else {\n"
362 " std::cerr << \"ERROR: do not know how to dump object of \" << class_name << \" class\\n\";\n"
363 " return (EXIT_FAILURE);\n"
364 " }\n"
365 " }\n"
366 " }\n"
367 " catch (dunedaq::conffwk::Exception & ex) {\n"
368 " std::cerr << \"Caught \" << ex << std::endl;\n"
369 " return (EXIT_FAILURE);\n"
370 " }\n"
371 "\n"
372 " return 0;\n"
373 "}\n";
374}

◆ get_add_algo_1()

bool get_add_algo_1 ( OksMethodImplementation * mi)

Definition at line 724 of file utils.cpp.

725{
726 return (mi->get_body().find(has_add_algo_1, 0) != std::string::npos);
727}
const std::string & get_body() const noexcept
Definition method.hpp:99
const std::string has_add_algo_1("ADD_ALGO_1")

◆ get_add_algo_n()

bool get_add_algo_n ( OksMethodImplementation * mi)

Definition at line 730 of file utils.cpp.

731{
732 return (mi->get_body().find(has_add_algo_n, 0) != std::string::npos);
733}
const std::string has_add_algo_n("ADD_ALGO_N")

◆ get_full_cpp_class_name()

std::string get_full_cpp_class_name ( const OksClass * c,
const ClassInfo::Map & cl_info,
const std::string & cpp_ns_name )

The function get_full_cpp_class_name() returns name of class with it's namespace (e.g. "NAMESPACE_A::CLASS_X")

Definition at line 404 of file utils.cpp.

405{
406 std::string s;
407 ClassInfo::Map::const_iterator idx = cl_info.find(c);
408
409 if (idx != cl_info.end())
410 s = (*idx).second.get_namespace();
411 else
412 s = cpp_ns_name;
413
414 if (!s.empty())
415 s += "::";
416
417 s += alnum_name(c->get_name());
418
419 return s;
420}
std::string alnum_name(const std::string &in)
Definition utils.cpp:32

◆ get_include_dir()

std::string get_include_dir ( const OksClass * c,
const ClassInfo::Map & cl_info,
const std::string & cpp_hdr_dir )

Definition at line 424 of file utils.cpp.

425{
426 std::string s;
427
428 ClassInfo::Map::const_iterator idx = cl_info.find(c);
429
430 if (idx != cl_info.end())
431 {
432 const std::string include_prefix = (*idx).second.get_include_prefix();
433 if (!include_prefix.empty())
434 {
435 s = include_prefix;
436 s += '/';
437 }
438 }
439 else if (!cpp_hdr_dir.empty())
440 {
441 s = cpp_hdr_dir;
442 s += '/';
443 }
444
445 s += alnum_name(c->get_name());
446
447 return s;
448}

◆ get_member_initializer_list()

std::string get_member_initializer_list ( OksMethodImplementation * mi)

Definition at line 718 of file utils.cpp.

719{
721}
static std::string get_method_header_x_logue(OksMethodImplementation *mi, const std::string &begin, const std::string &end)
Definition utils.cpp:682
const std::string begin_member_initializer_list("BEGIN_MEMBER_INITIALIZER_LIST")
const std::string end_member_initializer_list("END_MEMBER_INITIALIZER_LIST")

◆ get_method_header_epilogue()

std::string get_method_header_epilogue ( OksMethodImplementation * mi)

Definition at line 700 of file utils.cpp.

701{
703}
const std::string end_header_epilogue("END_HEADER_EPILOGUE")
const std::string begin_header_epilogue("BEGIN_HEADER_EPILOGUE")

◆ get_method_header_prologue()

std::string get_method_header_prologue ( OksMethodImplementation * mi)

Definition at line 694 of file utils.cpp.

695{
697}
const std::string begin_header_prologue("BEGIN_HEADER_PROLOGUE")
const std::string end_header_prologue("END_HEADER_PROLOGUE")

◆ get_method_header_x_logue()

static std::string get_method_header_x_logue ( OksMethodImplementation * mi,
const std::string & begin,
const std::string & end )
static

Definition at line 682 of file utils.cpp.

683{
684 std::string::size_type begix_idx = mi->get_body().find(begin, 0);
685 if (begix_idx == std::string::npos)
686 return "";
687 std::string::size_type end_idx = mi->get_body().find(end, begix_idx + begin.size());
688 if (end_idx == std::string::npos)
689 return "";
690 return mi->get_body().substr(begix_idx + begin.size(), end_idx - begix_idx - begin.size());
691}

◆ get_method_implementation_body()

std::string get_method_implementation_body ( OksMethodImplementation * mi)

Definition at line 754 of file utils.cpp.

755{
756 std::string s = mi->get_body();
764
765 if(std::all_of(s.begin(),s.end(),isspace))
766 return "";
767 else
768 return s;
769}
const std::string end_private_section("END_PRIVATE_SECTION")
static void remove_string_section(std::string &s, const std::string &begin, const std::string &end)
Definition utils.cpp:736
const std::string begin_public_section("BEGIN_PUBLIC_SECTION")
const std::string begin_private_section("BEGIN_PRIVATE_SECTION")
const std::string end_public_section("END_PUBLIC_SECTION")

◆ get_private_section()

std::string get_private_section ( OksMethodImplementation * mi)

Definition at line 712 of file utils.cpp.

◆ get_public_section()

std::string get_public_section ( OksMethodImplementation * mi)

Definition at line 706 of file utils.cpp.

◆ get_type()

std::string get_type ( OksData::Type oks_type,
bool is_cpp )

Definition at line 99 of file utils.cpp.

100{
101 switch (oks_type)
102 {
104 return "UNKNOWN";
106 return (is_cpp ? "int8_t" : "char");
108 return (is_cpp ? "uint8_t" : "byte");
110 return (is_cpp ? "int16_t" : "short");
112 return (is_cpp ? "uint16_t" : "short");
114 return (is_cpp ? "int32_t" : "int");
116 return (is_cpp ? "uint32_t" : "int");
118 return (is_cpp ? "int64_t" : "long");
120 return (is_cpp ? "uint64_t" : "long");
122 return "float";
124 return "double";
126 return (is_cpp ? "bool" : "boolean");
127
133 return (is_cpp ? "std::string" : "String");
134
139 return "funnytype";
140 }
141
142 return "invalid";
143}

◆ has_add_algo_1()

const std::string has_add_algo_1 ( "ADD_ALGO_1" )

◆ has_add_algo_n()

const std::string has_add_algo_n ( "ADD_ALGO_N" )

◆ int2dx()

std::string int2dx ( int level)

Definition at line 629 of file utils.cpp.

630{
631 return std::string(level * 2, ' ');
632}

◆ open_cpp_namespace()

int open_cpp_namespace ( std::ostream & s,
const std::string & value )

Definition at line 635 of file utils.cpp.

636{
637 int level = 0;
638 std::string dx;
639
640 if (!value.empty())
641 {
642 Oks::Tokenizer t(value, ":");
643 std::string token;
644
645 while (!(token = t.next()).empty())
646 {
647 s << dx << "namespace " << token << " {\n";
648 level++;
649 dx += " ";
650 }
651 }
652
653 return level;
654}
String tokenizer.
Definition defs.hpp:58

◆ print_description()

void print_description ( std::ostream & s,
const std::string & text,
const char * dx )

The function print_description() is used for printing of the multi-line text with right alignment.

Definition at line 65 of file utils.cpp.

66{
67 if (!text.empty())
68 {
69 s << dx << " /**\n";
70
71 Oks::Tokenizer t(text, "\n");
72 std::string token;
73
74 while (!(token = t.next()).empty())
75 {
76 s << dx << " * " << token << std::endl;
77 }
78
79 s << dx << " */\n\n";
80 }
81}

◆ print_indented()

void print_indented ( std::ostream & s,
const std::string & text,
const char * dx )

Definition at line 84 of file utils.cpp.

85{
86 if (!text.empty())
87 {
88 Oks::Tokenizer t(text, "\n");
89 std::string token;
90
91 while (!(token = t.next()).empty())
92 {
93 s << dx << token << std::endl;
94 }
95 }
96}

◆ process_external_class()

bool process_external_class ( ClassInfo::Map & cl_info,
const OksClass * c,
const std::list< std::string > & include_dirs,
const std::list< std::string > & user_classes,
bool verbose )

Definition at line 469 of file utils.cpp.

475{
476 if (cl_info.find(c) != cl_info.end())
477 return true;
478
479 // process list of user-defined classes first
480
481 for (const auto &s : user_classes)
482 {
483 std::string::size_type idx = s.find("::");
484 std::string::size_type idx2 = s.find("@", idx + 2);
485
486 std::string cpp_ns_name;
487 std::string class_name;
488 std::string cpp_dir_name;
489
490 if (idx == std::string::npos)
491 {
492 class_name = s.substr(0, idx2);
493 }
494 else
495 {
496 cpp_ns_name = s.substr(0, idx);
497 class_name = s.substr(idx + 2, idx2 - idx - 2);
498 }
499
500 if (idx2 != std::string::npos)
501 cpp_dir_name = s.substr(idx2 + 1);
502
503 if (class_name == c->get_name())
504 {
505 cl_info[c] = ClassInfo(cpp_ns_name, cpp_dir_name);
506 if (verbose)
507 {
508 std::cout << " * class " << c->get_name() << " is defined by user in ";
509
510 if (cpp_ns_name.empty())
511 std::cout << "global namespace";
512 else
513 std::cout << "namespace \"" << cpp_ns_name << '\"';
514
515 if (!cpp_dir_name.empty())
516 std::cout << " with \"" << cpp_dir_name << "\" include prefix";
517
518 std::cout << std::endl;
519 }
520
521 return true;
522 }
523 }
524
525 // process oksdalgen files
526
527 if (verbose)
528 std::cout << "Looking for oksdalgen info files ...\n";
529
530 bool found_class_declaration = false;
531
532 for (const auto& i : include_dirs)
533 {
534 std::string file_name(i);
535 file_name += "/oksdalgen.info";
536
537 std::ifstream f(file_name.c_str());
538
539 if (f)
540 {
541 if (verbose)
542 std::cout << " *** found file \"" << file_name << "\" ***\n";
543
544 std::string cpp_ns_name;
545 std::string cpp_dir_name;
546 // std::string java_pname;
547 bool is_class = false;
548
549 std::string s;
550 while (std::getline(f, s))
551 {
552 if (s.find("//") != std::string::npos)
553 {
554 if (verbose)
555 std::cout << " - skip comment \"" << s << "\"\n";
556 }
557 else if (s.find("classes:") != std::string::npos)
558 {
559 if (verbose)
560 std::cout << " - found classes keyword\n";
561 is_class = true;
562 }
563 else
564 {
565 const char s1[] = "c++-namespace=";
566 std::string::size_type idx = s.find(s1);
567 if (idx != std::string::npos)
568 {
569 cpp_ns_name = s.substr(sizeof(s1) - 1);
570 if (verbose)
571 std::cout << " - c++ namespace = \"" << cpp_ns_name << "\"\n";
572 }
573 else
574 {
575 const char s2[] = "c++-header-dir-prefix=";
576 std::string::size_type idx = s.find(s2);
577 if (idx != std::string::npos)
578 {
579 cpp_dir_name = s.substr(sizeof(s2) - 1);
580 if (verbose)
581 std::cout << " - c++ header dir prefix name = \"" << cpp_dir_name << "\"\n";
582 }
583 // else
584 // {
585 // const char s3[] = "java-package-name=";
586 // std::string::size_type idx = s.find(s3);
587 // if (idx != std::string::npos)
588 // {
589 // java_pname = s.substr(sizeof(s3) - 1);
590 // if (verbose)
591 // std::cout << " - java package name = \"" << java_pname << "\"\n";
592 // }
593 else if (is_class)
594 {
595 std::string cname = s.substr(2);
596 OksClass * cl = c->get_kernel()->find_class(cname);
597 if (cl && cl_info.find(cl) == cl_info.end())
598 {
599 cl_info[cl] = ClassInfo(cpp_ns_name, cpp_dir_name);
600 if (verbose)
601 std::cout << " * class " << cl->get_name() << " is defined by " << file_name << " in namespace \"" << cpp_ns_name << "\" with include prefix \"" << cpp_dir_name << "\"\n";
602 if (cl == c)
603 found_class_declaration = true;
604 }
605 else if (verbose)
606 {
607 std::cout << " - skip class \"" << cname << "\" declaration\n";
608 }
609 }
610 else
611 {
612 std::cerr << "Failed to parse line \"" << s << "\"\n";
613 }
614 // }
615 }
616 }
617 }
618 }
619 else if (verbose)
620 {
621 std::cout << " *** file \"" << file_name << "\" does not exist ***\n";
622 }
623 }
624
625 return found_class_declaration;
626}
The OKS class.
Definition class.hpp:200
const std::string & get_name() const noexcept
Definition class.hpp:363

◆ remove_string_section()

static void remove_string_section ( std::string & s,
const std::string & begin,
const std::string & end )
static

Definition at line 736 of file utils.cpp.

737{
738 std::string::size_type begix_idx = s.find(begin, 0);
739 if (begix_idx == std::string::npos)
740 return;
741
742 std::string::size_type end_idx = (end.empty() ? (begix_idx + begin.size()) : s.find(end, begix_idx + begin.size()));
743 if (end_idx == std::string::npos)
744 return;
745
746 end_idx += end.size();
747 while (s[end_idx] == '\n')
748 end_idx++;
749
750 s.erase(begix_idx, end_idx - begix_idx);
751}

◆ write_info_file()

void write_info_file ( std::ostream & s,
const std::string & cpp_namespace,
const std::string & cpp_header_dir,
const std::set< const OksClass *, std::less< const OksClass * > > & classes )

Definition at line 378 of file utils.cpp.

383{
384 std::time_t now = std::time(nullptr);
385
386 s << "// the file is generated " << std::put_time(std::localtime(&now), "%F %T %Z") << " by oksdalgen utility\n"
387 "// *** do not modify the file ***\n"
388 "c++-namespace=" << cpp_namespace << "\n"
389 "c++-header-dir-prefix=" << cpp_header_dir << "\n"
390 // "java-package-name=" << java_pname << "\n"
391 "classes:\n";
392
393 for (const auto& i : classes)
394 s << " " << i->get_name() << std::endl;
395}
static int64_t now()