152{
153 const std::string name(
alnum_name(cl->get_name()));
154
155
156
157 if (const std::list<std::string*>* super_list = cl->direct_super_classes()) {
158 cpp_file << " // include files for classes used in inheritance hierarchy\n\n";
159
160 for (const auto& i : *super_list) {
161 oks::OksClass*
c = cl->get_kernel()->find_class(*i);
162 cpp_file <<
"#include \"" <<
get_include_dir(c, cl_info, cpp_hdr_dir) <<
".hpp\"\n";
163 }
164 }
165
166 cpp_file << std::endl;
167
168
169 {
170
171 std::set<oks::OksClass*> rclasses;
172
173
174 if (cl->direct_relationships() && !cl->direct_relationships()->empty())
175 for (const auto& i : *cl->direct_relationships())
176 rclasses.insert(i->get_class_type());
177
178
179 if (const std::list<oks::OksMethod*>* mlist = cl->direct_methods()) {
180 for (const auto& i : *mlist) {
182 const std::string mp(mi->get_prototype());
183 for (const auto& j : cl->get_kernel()->classes()) {
184 const std::string
s(j.second->get_name());
185 std::string::size_type idx = mp.find(s);
186 if (idx != std::string::npos && (idx == 0 || !isalnum(mp[idx - 1])) && !isalnum(mp[idx +
s.size()]))
187 rclasses.insert(j.second);
188 }
189 }
190 }
191 }
192
194
195 for (const auto& c : rclasses) {
196
198 continue;
199
200 ClassInfo::Map::const_iterator idx = cl_info.find(c);
201 ns_info.
add((idx != cl_info.end() ? (*idx).second.get_namespace() : cpp_ns_name),
alnum_name(
c->get_name()));
202 }
203
204 if (!ns_info.
empty()) {
205 cpp_file << " // forward declaration for classes used in relationships and algorithms\n\n";
206 ns_info.
print(cpp_file, 0);
207 cpp_file << "\n\n";
208 }
209 }
210
211
212
213 if (const std::list<oks::OksMethod*>* mlist = cl->direct_methods())
214 for (const auto& i : *mlist)
217 cpp_file << " // prologue of method " << cl->get_name() << "::" << i->get_name() << "()\n";
219 }
220
221
222
224 std::string ns_dx =
int2dx(ns_level);
225 std::string ns_dx2 = ns_dx + " ";
226
227 const char* dx = ns_dx.c_str();
228 const char* dx2 = ns_dx2.c_str();
229
230
231
232 {
233 std::string txt(
234 "Declares methods to get and put values of attributes / relationships, to print and to destroy object.\n");
235
236 txt += "<p>\n"
237 "The methods can throw several exceptions:\n"
238 "<ul>\n"
239 " <li><code>conffwk.NotFoundException</code> - in case of wrong attribute or relationship name (e.g. in "
240 "case of database schema modification)\n"
241 " <li><code>conffwk.SystemException</code> - in case of system problems (communication or implementation "
242 "database failure, schema modification, object destruction, etc.)\n"
243 "</ul>\n"
244 "<p>\n"
245 "In addition the methods modifying database (set value, destroy object) can throw "
246 "<code>conffwk.NotAllowedException</code> "
247 "exception in case, if there are no write access rights or database is already locked by other process.\n";
248
249 if (!cl->get_description().empty()) {
250 txt += "\n<p>\n";
251 txt += cl->get_description();
252 txt += "\n";
253 }
254
255 txt += "@author oksdalgen\n";
256
257 cpp_file << std::endl;
259 }
260
261
262
263 cpp_file << dx << "class " << name << " : ";
264
265
266
267 if (const std::list<std::string*>* super_list = cl->direct_super_classes()) {
268 for (std::list<std::string*>::const_iterator i = super_list->begin(); i != super_list->end();) {
269 const oks::OksClass*
c = cl->get_kernel()->find_class(**i);
271 if (++i != super_list->end())
272 cpp_file << ", ";
273 }
274 } else {
275 cpp_file << "public virtual dunedaq::conffwk::DalObject";
276 }
277
278 cpp_file << " {\n\n";
279
280
281
282 cpp_file
283 << dx << " friend class conffwk::Configuration;\n"
284 << dx << " friend class conffwk::DalObject;\n"
285 << dx << " friend class conffwk::DalFactory;\n"
286 << dx << " friend class conffwk::DalRegistry;\n\n"
287 << dx << " protected:\n\n"
288 << dx << " " << name << "(conffwk::DalRegistry& db, const conffwk::ConfigObject& obj) noexcept;\n"
289 << dx << " virtual ~" << name << "() noexcept;\n"
290 << dx << " virtual void init(bool init_children);\n\n"
291 << dx << " public:\n\n"
292 << dx << " /** The name of the configuration class. */\n\n"
293 << dx << " static const std::string& s_class_name;\n\n\n"
294 << dx << " /**\n"
295 << dx << " * \\brief Print details of the " << name << " object.\n"
296 << dx << " *\n"
297 << dx << " * Parameters are:\n"
298 << dx
299 << " * \\param offset number of spaces to shift object right (useful to print nested objects)\n"
300 << dx
301 << " * \\param print_header if false, do not print object header (to print attributes of base classes)\n"
302 << dx << " * \\param s output stream\n"
303 << dx << " */\n\n"
304 << dx << " virtual void print(unsigned int offset, bool print_header, std::ostream& s) const;\n\n\n"
305 << dx << " /**\n"
306 << dx
307 << " * \\brief Get values of relationships and results of some algorithms as a vector of "
308 "dunedaq::conffwk::DalObject pointers.\n"
309 << dx << " *\n"
310 << dx << " * Parameters are:\n"
311 << dx << " * \\param name name of the relationship or algorithm\n"
312 << dx << " * \\return value of relationship or result of algorithm\n"
313 << dx
314 << " * \\throw std::exception if there is no relationship or algorithm with such name in "
315 "this and base classes\n"
316 << dx << " */\n\n"
317 << dx
318 << " virtual std::vector<const dunedaq::conffwk::DalObject *> get(const std::string& name, bool "
319 "upcast_unregistered = true) const;\n\n\n"
320 << dx << " protected:\n\n"
321 << dx
322 << " bool get(const std::string& name, std::vector<const dunedaq::conffwk::DalObject *>& vec, bool "
323 "upcast_unregistered, bool first_call) const;\n\n\n";
324
325
326
327
328 if (cl->direct_attributes() || cl->direct_relationships() || cl->direct_methods()) {
329 cpp_file << dx << " private:\n\n";
330
331
332
333
334
335 if (const std::list<oks::OksAttribute*>* alist = cl->direct_attributes()) {
336 for (const auto& i : *alist) {
337 const std::string aname(
alnum_name(i->get_name()));
338 std::string cpp_type =
get_type(i->get_data_type(),
true);
339
340 if (i->get_is_multi_values())
341 cpp_file << dx << " std::vector<" << cpp_type << "> m_" << aname << ";\n";
342 else
343 cpp_file << dx << " " << cpp_type << " m_" << aname << ";\n";
344 }
345 }
346
347
348
349
350
351 if (const std::list<oks::OksRelationship*>* rlist = cl->direct_relationships()) {
352 for (const auto& i : *rlist) {
353 const std::string rname(
alnum_name(i->get_name()));
356 cpp_file << dx << " std::vector<const " << full_class_name << "*> m_" << rname << ";\n";
357 else
358 cpp_file << dx << " const " << full_class_name << "* m_" << rname << ";\n";
359 }
360 }
361
362
363
364 if (const std::list<oks::OksMethod*>* mlist = cl->direct_methods()) {
365 for (const auto& i : *mlist) {
368 if (!method_extension.empty()) {
369 cpp_file << "\n"
370 << dx << " // extension of method " << cl->get_name() << "::" << i->get_name() << "()\n";
372 }
373 }
374 }
375 }
376
377 cpp_file << std::endl << std::endl << dx << " public:\n\n";
378
379
380
381
382
383
384
385
386 if (const std::list<oks::OksAttribute*>* alist = cl->direct_attributes()) {
387
388 cpp_file << dx << " // attribute names\n\n";
389
390 for (const auto& i : *alist) {
391 const std::string& aname(i->get_name());
392 cpp_file << dx <<
" inline static const std::string s_" <<
alnum_name(aname) <<
" = \"" << aname <<
"\";\n";
393 }
394
395 cpp_file << "\n";
396
397 for (const auto& i : *alist) {
398 const std::string& cpp_aname(
alnum_name(i->get_name()));
399 cpp_file << dx << " static const std::string& __get_" << cpp_aname << "_str() noexcept { return s_"
400 << cpp_aname << "; }\n";
401 }
402
403 cpp_file << std::endl << std::endl;
404
405 for (const auto& i : *alist) {
406 const std::string aname(
alnum_name(i->get_name()));
407
408
409
411 std::string description("Valid enumeration values to compare with value returned by get_");
412 description += aname;
413 description += "() and to pass value to set_";
414 description += aname;
415 description += "() methods.";
416
418
419 description += "\nUse toString() method to compare and to pass the values. Do not use name() method.";
420
422
424 std::string token;
425 while (!(token = t.next()).empty()) {
427 << token << "\";\n";
428 }
429
430 cpp_file << dx << " };\n\n";
431 }
432
433
434
435 {
436
437 std::string description("Get \"");
438 description += i->get_name();
439 description += "\" attribute value.\n\n";
440 description += i->get_description();
441
442 std::string description2("\\brief ");
443 description2 += description;
444 description2 += "\n\\return the attribute value\n";
445 description2 += "\\throw dunedaq::conffwk::Generic, dunedaq::conffwk::DeletedObject\n";
446
448 }
449
450
451
452 cpp_file << dx << " ";
453
454 std::string cpp_type =
get_type(i->get_data_type(),
true);
455
456 if (i->get_is_multi_values()) {
457 cpp_file << "const std::vector<" << cpp_type << ">&";
458 } else {
459 if (cpp_type == "std::string")
460 cpp_file << "const std::string&";
461 else
462 cpp_file << cpp_type;
463 }
464
465 cpp_file << '\n'
466 << dx << " get_" << aname << "() const\n"
467 << dx << " {\n"
468 << dx << " std::lock_guard scoped_lock(m_mutex);\n"
469 << dx << " check();\n"
470 << dx << " check_init();\n"
471 << dx << " return m_" << aname << ";\n"
472 << dx << " }\n\n";
473
474
475
476 {
477 std::string description("Set \"");
478 description += i->get_name();
479 description += "\" attribute value.\n\n";
480 description += i->get_description();
481
482 std::string description2("\\brief ");
483 description2 += description;
484 description2 += "\n\\param value new attribute value\n";
485 description2 += "\\throw dunedaq::conffwk::Generic, dunedaq::conffwk::DeletedObject\n";
486
488 }
489
490
491
492 cpp_file << dx << " void\n" << dx << " set_" << aname << '(';
493
494 if (i->get_is_multi_values()) {
495 cpp_file << "const std::vector<" << cpp_type << ">&";
496 } else {
497 if (cpp_type == "std::string") {
498 cpp_file << "const std::string&";
499 } else {
500 cpp_file << cpp_type;
501 }
502 }
503
504 cpp_file << " value)\n"
505 << dx << " {\n"
506 << dx << " std::lock_guard scoped_lock(m_mutex);\n"
507 << dx << " check();\n"
508 << dx << " clear();\n"
509 << dx << " p_obj.";
510
512 cpp_file << "set_by_ref";
514 cpp_file << "set_enum";
516 cpp_file << "set_class";
518 cpp_file << "set_date";
520 cpp_file << "set_time";
521 } else {
522 cpp_file << "set_by_val";
523 }
524
525 cpp_file << "(s_" << aname << ", value);\n" << dx << " }\n\n\n";
526 }
527 }
528
529
530
531
532
533
534
535
536 if (const std::list<oks::OksRelationship*>* rlist = cl->direct_relationships()) {
537
538 cpp_file << dx << " // relationship names\n\n";
539
540 for (const auto& i : *rlist) {
541 const std::string& rname(i->get_name());
542 cpp_file << dx <<
" inline static const std::string s_" <<
alnum_name(rname) <<
" = \"" << rname <<
"\";\n";
543 }
544
545 cpp_file << "\n";
546
547 for (const auto& i : *rlist) {
548 const std::string& cpp_rname(
alnum_name(i->get_name()));
549 cpp_file << dx << " static const std::string& __get_" << cpp_rname << "_str() noexcept { return s_"
550 << cpp_rname << "; }\n";
551 }
552
553 cpp_file << std::endl << std::endl;
554
555 for (const auto& i : *rlist) {
556
557
558
559 {
560 std::string description("Get \"");
561 description += i->get_name();
562 description += "\" relationship value.\n\n";
563 description += i->get_description();
564
565 std::string description2("\\brief ");
566 description2 += description;
567 description2 += "\n\\return the relationship value\n";
568 description2 += "\\throw dunedaq::conffwk::Generic, dunedaq::conffwk::DeletedObject\n";
569
571 }
572
573
574
575 cpp_file << dx << " const ";
576
577 const std::string rname(
alnum_name(i->get_name()));
579
581 cpp_file << "std::vector<const " << full_cpp_class_name << "*>&";
582 } else {
583 cpp_file << full_cpp_class_name << " *";
584 }
585
586 cpp_file << "\n"
587 << dx << " get_" << rname << "() const\n"
588 << dx << " {\n"
589 << dx << " std::lock_guard scoped_lock(m_mutex);\n"
590 << dx << " check();\n"
591 << dx << " check_init();\n";
592
595 cpp_file << dx << " if (!m_" << rname << ")\n"
596 << dx << " {\n"
597 << dx << " std::ostringstream text;\n"
598 << dx << " text << \"relationship \\\"\" << s_" << rname
599 << " << \"\\\" of object \" << this << \" is not set\";\n"
600 << dx << " throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());\n"
601 << dx << " }\n";
602 } else {
603 cpp_file << dx << " if (m_" << rname << ".empty())\n"
604 << dx << " {\n"
605 << dx << " std::ostringstream text;\n"
606 << dx << " text << \"relationship \\\"\" << s_" << rname
607 << " << \"\\\" of object \" << this << \" is empty\";\n"
608 << dx << " throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());\n"
609 << dx << " }\n";
610 }
611 }
612
613 cpp_file << dx << " return m_" << rname << ";\n" << dx << " }\n\n\n";
614
615
616
617 {
618 std::string description("Set \"");
619 description += i->get_name();
620 description += "\" relationship value.\n\n";
621 description += i->get_description();
622
623 std::string description2("\\brief ");
624 description2 += description;
625 description2 += "\n\\param value new relationship value\n";
626 description2 += "\\throw dunedaq::conffwk::Generic, dunedaq::conffwk::DeletedObject\n";
627
629 }
630
631 cpp_file << dx << " void\n" << dx << " set_" << rname << "(const ";
632
634 cpp_file << "std::vector<const " << full_cpp_class_name << "*>&";
635 } else {
636 cpp_file << full_cpp_class_name << " *";
637 }
638
639 cpp_file << " value);\n\n";
640 }
641 }
642 }
643
644
645
646 if (const std::list<oks::OksMethod*>* mlist = cl->direct_methods()) {
647 bool cpp_comment_is_printed = false;
648
649 for (const auto& i : *mlist) {
650
651
652
654 if (cpp_comment_is_printed == false) {
655 cpp_file << std::endl << dx << " public:\n\n" << dx << " // user-defined algorithms\n\n";
656 cpp_comment_is_printed = true;
657 } else {
658 cpp_file << "\n\n";
659 }
660
661
662
664
665
666
667 cpp_file << dx << " " << mi->get_prototype() << ";\n";
668
669
670
672 if (!public_method_extension.empty()) {
673 cpp_file << "\n" << " // extension of method " << cl->get_name() << "::" << i->get_name() << "()\n";
675 }
676 }
677 }
678 }
679
680
681
682 cpp_file << dx << "};\n\n";
683
684
685
686 cpp_file << dx << " // out stream operator\n\n"
687 << dx << "inline std::ostream& operator<<(std::ostream& s, const " << name << "& obj)\n"
688 << dx << " {\n"
689 << dx << " return obj.print_object(s);\n"
690 << dx << " }\n\n"
691 << dx << "typedef std::vector<const " << name << "*>::const_iterator " << name << "Iterator;\n\n";
692
693
694
696
697
698
699 if (const std::list<oks::OksMethod*>* mlist = cl->direct_methods()) {
700 for (const auto& i : *mlist) {
703 cpp_file << " // epilogue of method " << cl->get_name() << "::" << i->get_name() << "()\n";
705 }
706 }
707 }
708}
std::string get_public_section(oks::OksMethodImplementation *mi)
std::string get_type(oks::OksData::Type oks_type, bool is_cpp)
std::string get_method_header_prologue(oks::OksMethodImplementation *)
std::string get_private_section(oks::OksMethodImplementation *mi)
std::string get_method_header_epilogue(oks::OksMethodImplementation *)
void print_indented(std::ostream &s, const std::string &text, const char *dx)
std::string capitalize_name(const std::string &in)
void print(std::ostream &s, int level) const
void add(const std::string &ns_name, const std::string &class_name)