1212#include < set>
1313#include < sstream>
1414#include < string>
15+ #include < string_view>
1516#include < system_error>
1617#include < type_traits>
1718#include < variant>
@@ -29,7 +30,7 @@ namespace GridKit
2930 namespace VariableMonitorDetail
3031 {
3132 template <typename RealT>
32- std::string formatReal ( RealT value)
33+ void formatReal ( std::string& out, RealT value)
3334 {
3435 std::array<char , 128 > buffer{};
3536 constexpr auto precision = std::numeric_limits<RealT>::digits10 + 1 ;
@@ -42,13 +43,14 @@ namespace GridKit
4243
4344 if (ec == std::errc{})
4445 {
45- return std::string (buffer.data (), ptr);
46+ out.append (buffer.data (), ptr);
47+ return ;
4648 }
4749
4850 std::ostringstream os;
4951 os.precision (precision);
5052 os << std::scientific << value;
51- return os.str ();
53+ out += os.str ();
5254 }
5355 } // namespace VariableMonitorDetail
5456
@@ -63,6 +65,16 @@ namespace GridKit
6365 YAML // /< YAML format
6466 };
6567
68+ /* *
69+ * @enum VariableMonitorLayout
70+ * Available table layouts for monitor output
71+ */
72+ enum class VariableMonitorLayout
73+ {
74+ WIDE , // /< One row per sample with one column per variable
75+ LONG // /< One record per sample and variable
76+ };
77+
6678 /* *
6779 * @brief Abstract class for managing output of monitored variables
6880 *
@@ -94,8 +106,20 @@ namespace GridKit
94106 {
95107 };
96108
109+ // / Type used for dispatch
110+ struct Wide
111+ {
112+ };
113+
114+ // / Type used for dispatch
115+ struct Long
116+ {
117+ };
118+
97119 // / Short alias for local use
98120 using Format = VariableMonitorFormat;
121+ // / Short alias for local use
122+ using Layout = VariableMonitorLayout;
99123
100124 /* *
101125 * @brief Defines information necessary to create a monitor sink
@@ -108,6 +132,8 @@ namespace GridKit
108132 std::string file_name{};
109133 // / Delimiter (used only with CSV format currently)
110134 std::string delim{" ," };
135+ // / Table layout
136+ Layout layout{Layout::WIDE };
111137 };
112138
113139 virtual ~VariableMonitorBase ()
@@ -119,50 +145,27 @@ namespace GridKit
119145 */
120146 virtual bool empty () const = 0;
121147
122- protected:
123- // /@{
124- /* *
125- * @brief Print items relevant to the start of a file
126- */
127- virtual void appendHeader (std::string&, Csv) const = 0;
148+ // / Appends the formatted current value of a monitored variable
149+ using ValueFormatter = std::function<void (std::string&)>;
128150
129- virtual void appendHeader (std::string&, Json) const
130- {
131- }
132-
133- virtual void appendHeader (std::string&, Yaml) const
134- {
135- }
136-
137- // /@}
138-
139- // /@{
140- /* *
141- * @brief Print monitored variables at current state
142- */
143- virtual void append (std::string&, Csv) const = 0;
144- virtual void append (std::string&, Json) const = 0;
145- virtual void append (std::string&, Yaml) const = 0;
146-
147- // /@}
148-
149- // /@{
150151 /* *
151- * @brief Print items relevant to the end of a file
152+ * @brief Monitored variable and the formatter of its current value
152153 */
153- virtual void appendFooter (std::string&, Csv) const
154+ struct Entry
154155 {
155- }
156-
157- virtual void appendFooter (std::string&, Json) const
158- {
159- }
160-
161- virtual void appendFooter (std::string&, Yaml) const
162- {
163- }
156+ // / Device class, such as `Genrou`
157+ std::string_view device_class;
158+ // / Device identifier within its class
159+ std::string_view id;
160+ // / Variable name
161+ std::string_view variable;
162+ // / Formats the current value
163+ const ValueFormatter* value;
164+ };
164165
165- // /@}
166+ protected:
167+ // / Append one entry per monitored variable
168+ virtual void appendEntries (std::vector<Entry>&) const = 0;
166169 };
167170
168171 template <typename eval_type, template <typename , typename > typename model_data_type>
0 commit comments