DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DalObjectPrint.hpp
Go to the documentation of this file.
1
7#ifndef CONFFWK_DAL_OBJECT_PRINT_H_
8#define CONFFWK_DAL_OBJECT_PRINT_H_
9
10#include <iostream>
11namespace dunedaq {
12namespace conffwk {
14
15 template<class T>
16 void
17 p_val(std::ostream& s, const T & data)
18 {
19 s << data;
20 }
21
22 template<>
23 void inline
24 p_val<uint8_t>(std::ostream& s, const uint8_t & data)
25 {
26 s << static_cast<uint16_t>(data);
27 }
28
29 template<>
30 void inline
31 p_val<int8_t>(std::ostream& s, const int8_t & data)
32 {
33 s << static_cast<int16_t>(data);
34 }
35
36
37 template<PrintNumBase NUM_BASE = dec>
38 void
39 p_base_start(std::ostream &s) noexcept
40 {
41 if constexpr (NUM_BASE == hex)
42 s.setf(std::ios::hex, std::ios::basefield);
43 else if constexpr (NUM_BASE == oct)
44 s.setf(std::ios::oct, std::ios::basefield);
45
46 if constexpr (NUM_BASE != dec)
47 s.setf(std::ios::showbase);
48 }
49
50 template<PrintNumBase NUM_BASE>
51 void
52 p_base_end(std::ostream &s) noexcept
53 {
54 if constexpr (NUM_BASE != dec)
55 s.setf(std::ios::dec, std::ios::basefield);
56 }
57
59 template<PrintNumBase NUM_BASE=dec, class T>
60 void
61 p_sv_attr(std::ostream &s, const std::string &str, const std::string &name, const T &val) noexcept
62 {
63 s << str << name << ": ";
65 p_val(s, val);
67 s << '\n';
68 }
69
71 template<PrintNumBase NUM_BASE=dec, class T>
72 void
73 p_mv_attr(std::ostream &s, const std::string &str, const std::string &name, const T &val) noexcept
74 {
75 if (!val.empty())
76 {
77 s << str << val.size() << " value(s) in " << name << ": ";
79 for (const auto &x : val)
80 {
81 if (x != *val.begin())
82 s << ", ";
83 p_val(s, x);
84 }
86 s << '\n';
87 }
88 else
89 {
90 s << str << name << " value is empty\n";
91 }
92 }
93
95 void
96 p_sv_rel(std::ostream &s, const std::string &str, const std::string &name, const DalObject *obj);
97
99 template<class T>
100 void
101 p_sv_rel(std::ostream &s, const std::string &str, unsigned int indent, const std::string &name, const T *obj) noexcept
102 {
103 s << str << name << ":\n";
104
105 if (obj)
106 obj->print(indent + 4, true, s);
107 else
108 s << str << " (null)\n";
109 }
110
112 template<class T>
113 void
114 p_mv_rel(std::ostream &s, const std::string &str, const std::string &name, const T &objs) noexcept
115 {
116 if (auto len = objs.size())
117 s << str << len << " object(s) in " << name << ": ";
118 else
119 s << str << name << " value is empty";
120
121 for (const auto &x : objs)
122 {
123 if (x != *objs.begin())
124 s << ", ";
125 s << x;
126 }
127
128 s << '\n';
129 }
130
132 template<class T>
133 void
134 p_mv_rel(std::ostream &s, const std::string &str, unsigned int indent, const std::string &name, const T &objs) noexcept
135 {
136 if (auto len = objs.size())
137 s << str << len << " object(s) in " << name << ":\n";
138 else
139 s << str << name << " value is empty\n";
140
141 for (const auto &x : objs)
142 x->print(indent + 4, true, s);
143 }
144
145} // namespace conffwk
146} // namespace dunedaq
147
148
149#endif // CONFFWK_CONFIGOBJECT_H_
void p_sv_rel(std::ostream &s, const std::string &str, const std::string &name, const DalObject *obj)
print weak single-value relationship
void p_mv_rel(std::ostream &s, const std::string &str, const std::string &name, const T &objs) noexcept
print weak multi-value relationship
void p_mv_attr(std::ostream &s, const std::string &str, const std::string &name, const T &val) noexcept
print multi-value attribute
void p_sv_attr(std::ostream &s, const std::string &str, const std::string &name, const T &val) noexcept
print single-value attribute
void p_base_start(std::ostream &s) noexcept
void p_val(std::ostream &s, const T &data)
void p_base_end(std::ostream &s) noexcept
void p_val< uint8_t >(std::ostream &s, const uint8_t &data)
void p_val< int8_t >(std::ostream &s, const int8_t &data)
Including Qt Headers.