UniSet 2.32.1
VMonitor.h
1/*
2 * Copyright (c) 2015 Pavel Vainerman.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation, version 2.1.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Lesser Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16// --------------------------------------------------------------------------
20// --------------------------------------------------------------------------
21#ifndef VMonitor_H_
22#define VMonitor_H_
23// --------------------------------------------------------------------------
24#include <string>
25#include <list>
26#include <ostream>
27#include <unordered_map>
28#include <Poco/Types.h>
29#include "UniSetTypes.h"
30// --------------------------------------------------------------------------
31namespace uniset
32{
33
34#ifndef VMON_DEF_FUNC
35#define VMON_DEF_FUNC(T) \
36 void add( const std::string& name, const T& v );\
37 static const std::string pretty_str( const std::string& name, const T* v, int width = NameWidth ); \
38 static const std::string pretty_str( const std::string& name, const T& v, int width = NameWidth )
39#endif
40#ifndef VMON_DEF_FUNC2
41#define VMON_DEF_FUNC2(T) \
42 void add( const std::string& name, const T& v );\
43 void add( const std::string& name, const unsigned T& v );\
44 static const std::string pretty_str( const std::string& name, const T* v, int width = NameWidth );\
45 static const std::string pretty_str( const std::string& name, const unsigned T* v, int width = NameWidth ); \
46 static const std::string pretty_str( const std::string& name, const T& v, int width = NameWidth );\
47 static const std::string pretty_str( const std::string& name, const unsigned T& v, int width = NameWidth )
48#endif
49
50#ifndef VMON_DEF_MAP
51#define VMON_DEF_MAP(T) std::unordered_map<const T*,const std::string> m_##T
52#endif
53
54#ifndef VMON_DEF_MAP2
55#define VMON_DEF_MAP2(T) \
56 std::unordered_map<const T*,const std::string> m_##T; \
57 std::unordered_map<const unsigned T*,const std::string> m_unsigned_##T
58#endif
59
60#ifndef VMON_DEF_MAP3
61#define VMON_DEF_MAP3(T,M) std::unordered_map<const T*,const std::string> m_##M
62#endif
63
64 // --------------------------------------------------------------------------
65 /* EXAMPLE HELPER MACROS
66
67 #ifndef vmonit
68 #define vmonit( var ) add( #var, var )
69 #endif
70
71 */
72 // --------------------------------------------------------------------------
117 {
118 public:
119 VMonitor() {}
120
121 friend std::ostream& operator<<(std::ostream& os, VMonitor& m );
122
123 static const int NameWidth = { 30 };
124 static const int ColCount = { 2 };
125
127 std::string str() const;
128
133 std::string pretty_str( int namewidth = NameWidth, int colnum = ColCount ) const;
134
135 // перегрузки для стандартных типов..
136 VMON_DEF_FUNC2(int);
137 VMON_DEF_FUNC2(long);
138 VMON_DEF_FUNC2(short);
139 VMON_DEF_FUNC2(char);
140 VMON_DEF_FUNC(bool);
141 VMON_DEF_FUNC(float);
142 VMON_DEF_FUNC(double);
143
144#ifndef POCO_LONG_IS_64_BIT
145 VMON_DEF_FUNC(Poco::Int64); // <--- for timeout_t
146#endif
147
148 void add( const std::string& name, const std::string& v );
149
150 static const std::string pretty_str( const std::string& name, const std::string* v, int width = NameWidth );
151 static const std::string pretty_str( const std::string& name, const std::string& v, int width = NameWidth );
152
153 std::list<std::pair<std::string, std::string>> getList() const;
154
155 protected:
156
157 private:
158
159 // определения для стандартных типов
160 VMON_DEF_MAP2(int);
161 VMON_DEF_MAP2(long);
162 VMON_DEF_MAP2(short);
163 VMON_DEF_MAP2(char);
164 VMON_DEF_MAP(bool);
165 VMON_DEF_MAP(float);
166 VMON_DEF_MAP(double);
167#ifndef POCO_LONG_IS_64_BIT
168 std::unordered_map<const Poco::Int64*, const std::string> m_Int64;
169#endif
170 VMON_DEF_MAP3(std::string, string);
171 };
172 // -------------------------------------------------------------------------
173} // end of uniset namespace
174// --------------------------------------------------------------------------
175#endif
Definition VMonitor.h:117
std::string pretty_str(int namewidth=NameWidth, int colnum=ColCount) const
Definition VMonitor.cc:186
std::string str() const
Definition VMonitor.cc:156
Definition Calibration.h:27