DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DalObjectPrint.hpp
Go to the documentation of this file.
1//
2// DUNE DAQ modification notice:
3// This file has been modified from the original ATLAS config source for the DUNE DAQ project.
4// Fork baseline commit: 67a24e731 (2022-10-27).
5// Renamed since fork: yes (from config/DalObjectPrint.h to include/conffwk/DalObjectPrint.hpp).
6//
7
14
15#ifndef CONFFWK_DAL_OBJECT_PRINT_H_
16#define CONFFWK_DAL_OBJECT_PRINT_H_
17
18#include <iostream>
19namespace dunedaq {
20namespace conffwk {
27
28template<class T>
29void
30p_val(std::ostream& s, const T& data)
31{
32 s << data;
33}
34
35template<>
36void inline p_val<uint8_t>(std::ostream& s, const uint8_t& data)
37{
38 s << static_cast<uint16_t>(data);
39}
40
41template<>
42void inline p_val<int8_t>(std::ostream& s, const int8_t& data)
43{
44 s << static_cast<int16_t>(data);
45}
46
47template<PrintNumBase NUM_BASE = dec>
48void
49p_base_start(std::ostream& s) noexcept
50{
51 if constexpr (NUM_BASE == hex)
52 s.setf(std::ios::hex, std::ios::basefield);
53 else if constexpr (NUM_BASE == oct)
54 s.setf(std::ios::oct, std::ios::basefield);
55
56 if constexpr (NUM_BASE != dec)
57 s.setf(std::ios::showbase);
58}
59
60template<PrintNumBase NUM_BASE>
61void
62p_base_end(std::ostream& s) noexcept
63{
64 if constexpr (NUM_BASE != dec)
65 s.setf(std::ios::dec, std::ios::basefield);
66}
67
69template<PrintNumBase NUM_BASE = dec, class T>
70void
71p_sv_attr(std::ostream& s, const std::string& str, const std::string& name, const T& val) noexcept
72{
73 s << str << name << ": ";
75 p_val(s, val);
77 s << '\n';
78}
79
81template<PrintNumBase NUM_BASE = dec, class T>
82void
83p_mv_attr(std::ostream& s, const std::string& str, const std::string& name, const T& val) noexcept
84{
85 if (!val.empty()) {
86 s << str << val.size() << " value(s) in " << name << ": ";
88 for (const auto& x : val) {
89 if (x != *val.begin())
90 s << ", ";
91 p_val(s, x);
92 }
94 s << '\n';
95 } else {
96 s << str << name << " value is empty\n";
97 }
98}
99
101void
102p_sv_rel(std::ostream& s, const std::string& str, const std::string& name, const DalObject* obj);
103
105template<class T>
106void
107p_sv_rel(std::ostream& s, const std::string& str, unsigned int indent, const std::string& name, const T* obj) noexcept
108{
109 s << str << name << ":\n";
110
111 if (obj)
112 obj->print(indent + 4, true, s);
113 else
114 s << str << " (null)\n";
115}
116
118template<class T>
119void
120p_mv_rel(std::ostream& s, const std::string& str, const std::string& name, const T& objs) noexcept
121{
122 if (auto len = objs.size())
123 s << str << len << " object(s) in " << name << ": ";
124 else
125 s << str << name << " value is empty";
126
127 for (const auto& x : objs) {
128 if (x != *objs.begin())
129 s << ", ";
130 s << x;
131 }
132
133 s << '\n';
134}
135
137template<class T>
138void
139p_mv_rel(std::ostream& s, const std::string& str, unsigned int indent, const std::string& name, const T& objs) noexcept
140{
141 if (auto len = objs.size())
142 s << str << len << " object(s) in " << name << ":\n";
143 else
144 s << str << name << " value is empty\n";
145
146 for (const auto& x : objs)
147 x->print(indent + 4, true, s);
148}
149
150} // namespace conffwk
151} // namespace dunedaq
152
153#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
The DUNE-DAQ namespace.
msgpack::object obj