Line data Source code
1 : #ifndef __OKSDALGEN_CLASS_INFO__
2 : #define __OKSDALGEN_CLASS_INFO__
3 :
4 : #include "oks/class.hpp"
5 :
6 : #include <map>
7 : #include <ostream>
8 : #include <set>
9 : #include <string>
10 :
11 : namespace dunedaq {
12 : namespace oksdalgen {
13 :
14 : class ClassInfo {
15 :
16 : public:
17 :
18 : struct SortByName {
19 0 : bool operator() (const oks::OksClass * c1, const oks::OksClass * c2) const {
20 0 : return c1->get_name() < c2->get_name();
21 : }
22 : };
23 :
24 : typedef std::map<const oks::OksClass *, ClassInfo, SortByName> Map;
25 :
26 0 : ClassInfo() {};
27 :
28 0 : ClassInfo(const std::string& cpp_ns_name, const std::string& dir_prefix) :
29 0 : p_namespace (cpp_ns_name), p_include_prefix (dir_prefix) {};
30 :
31 0 : const std::string& get_namespace() const {return p_namespace;}
32 0 : const std::string& get_include_prefix() const {return p_include_prefix;}
33 :
34 :
35 : private:
36 :
37 : std::string p_namespace;
38 : std::string p_include_prefix;
39 :
40 : };
41 :
42 : struct NameSpaceInfo
43 : {
44 : std::set<std::string> m_classes;
45 : std::map<std::string, NameSpaceInfo> m_nested;
46 :
47 : bool
48 0 : empty() const
49 : {
50 0 : return (m_classes.empty() && m_nested.empty());
51 : }
52 :
53 : void
54 0 : add(const std::string &ns_name, const std::string &class_name)
55 : {
56 0 : if (!ns_name.empty())
57 : {
58 0 : std::string::size_type idx = ns_name.find_first_of(':');
59 0 : NameSpaceInfo &ns = m_nested[ns_name.substr(0, idx)];
60 0 : if (idx != std::string::npos)
61 0 : ns.add(ns_name.substr(ns_name.find_first_not_of(':', idx)), class_name);
62 : else
63 0 : ns.add("", class_name);
64 : }
65 : else
66 0 : m_classes.insert(class_name);
67 0 : }
68 :
69 : void
70 0 : print(std::ostream &s, int level) const
71 : {
72 0 : std::string dx(level * 2, ' ');
73 :
74 0 : for (const auto &x : m_nested)
75 : {
76 0 : s << dx << "namespace " << x.first << " {\n";
77 0 : x.second.print(s, level + 1);
78 0 : s << dx << "}\n";
79 : }
80 :
81 0 : for (const auto &x : m_classes)
82 0 : s << dx << "class " << x << ";\n";
83 0 : }
84 : };
85 :
86 : } // namespace oksdalgen
87 : } // namespace dunedaq
88 : #endif
|