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