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