|
UniSet
2.6.0
|
00001 /* 00002 * Copyright (c) 2015 Pavel Vainerman. 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as 00006 * published by the Free Software Foundation, version 2.1. 00007 * 00008 * This program is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Lesser General Lesser Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00015 */ 00016 // -------------------------------------------------------------------------- 00020 // -------------------------------------------------------------------------- 00021 #ifndef VMonitor_H_ 00022 #define VMonitor_H_ 00023 // -------------------------------------------------------------------------- 00024 #include <string> 00025 #include <list> 00026 #include <ostream> 00027 #include <unordered_map> 00028 #include <Poco/Types.h> 00029 #include "UniSetTypes.h" 00030 // -------------------------------------------------------------------------- 00031 namespace uniset 00032 { 00033 00034 #ifndef VMON_DEF_FUNC 00035 #define VMON_DEF_FUNC(T) \ 00036 void add( const std::string& name, const T& v );\ 00037 static const std::string pretty_str( const std::string& name, const T* v, int width = NameWidth ); \ 00038 static const std::string pretty_str( const std::string& name, const T& v, int width = NameWidth ) 00039 #endif 00040 #ifndef VMON_DEF_FUNC2 00041 #define VMON_DEF_FUNC2(T) \ 00042 void add( const std::string& name, const T& v );\ 00043 void add( const std::string& name, const unsigned T& v );\ 00044 static const std::string pretty_str( const std::string& name, const T* v, int width = NameWidth );\ 00045 static const std::string pretty_str( const std::string& name, const unsigned T* v, int width = NameWidth ); \ 00046 static const std::string pretty_str( const std::string& name, const T& v, int width = NameWidth );\ 00047 static const std::string pretty_str( const std::string& name, const unsigned T& v, int width = NameWidth ) 00048 #endif 00049 00050 #ifndef VMON_DEF_MAP 00051 #define VMON_DEF_MAP(T) std::unordered_map<const T*,const std::string> m_##T 00052 #endif 00053 00054 #ifndef VMON_DEF_MAP2 00055 #define VMON_DEF_MAP2(T) \ 00056 std::unordered_map<const T*,const std::string> m_##T; \ 00057 std::unordered_map<const unsigned T*,const std::string> m_unsigned_##T 00058 #endif 00059 00060 #ifndef VMON_DEF_MAP3 00061 #define VMON_DEF_MAP3(T,M) std::unordered_map<const T*,const std::string> m_##M 00062 #endif 00063 00064 // -------------------------------------------------------------------------- 00065 /* EXAMPLE HELPER MACROS 00066 00067 #ifndef vmonit 00068 #define vmonit( var ) add( #var, var ) 00069 #endif 00070 00071 */ 00072 // -------------------------------------------------------------------------- 00116 class VMonitor 00117 { 00118 public: 00119 VMonitor() {} 00120 00121 friend std::ostream& operator<<(std::ostream& os, VMonitor& m ); 00122 00123 static const int NameWidth = { 30 }; 00124 static const int ColCount = { 2 }; 00125 00127 std::string str(); 00128 00133 std::string pretty_str( int namewidth = NameWidth, int colnum = ColCount ); 00134 00135 // функции добавления.. 00136 VMON_DEF_FUNC2(int); 00137 VMON_DEF_FUNC2(long); 00138 VMON_DEF_FUNC2(short); 00139 VMON_DEF_FUNC2(char); 00140 VMON_DEF_FUNC(bool); 00141 VMON_DEF_FUNC(float); 00142 VMON_DEF_FUNC(double); 00143 00144 #ifndef POCO_LONG_IS_64_BIT 00145 VMON_DEF_FUNC(Poco::Int64); // <--- for timeout_t 00146 #endif 00147 00148 void add( const std::string& name, const std::string& v ); 00149 00150 static const std::string pretty_str( const std::string& name, const std::string* v, int width = NameWidth ); 00151 static const std::string pretty_str( const std::string& name, const std::string& v, int width = NameWidth ); 00152 00153 std::list<std::pair<std::string, std::string>> getList(); 00154 00155 protected: 00156 00157 private: 00158 00159 VMON_DEF_MAP2(int); 00160 VMON_DEF_MAP2(long); 00161 VMON_DEF_MAP2(short); 00162 VMON_DEF_MAP2(char); 00163 VMON_DEF_MAP(bool); 00164 VMON_DEF_MAP(float); 00165 VMON_DEF_MAP(double); 00166 #ifndef POCO_LONG_IS_64_BIT 00167 std::unordered_map<const Poco::Int64*, const std::string> m_Int64; 00168 #endif 00169 VMON_DEF_MAP3(std::string, string); 00170 }; 00171 // ------------------------------------------------------------------------- 00172 } // end of uniset namespace 00173 // -------------------------------------------------------------------------- 00174 #endif
1.7.6.1