|
UniSet
2.2.1
|
00001 /* File: This file is part of the UniSet project 00002 * Copyright (C) 2002 Vitaly Lipatov, Pavel Vainerman 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 // -------------------------------------------------------------------------- 00022 // -------------------------------------------------------------------------- 00023 #ifndef VMonitor_H_ 00024 #define VMonitor_H_ 00025 // -------------------------------------------------------------------------- 00026 #include <string> 00027 #include <list> 00028 #include <ostream> 00029 #include <unordered_map> 00030 #include "UniSetTypes.h" 00031 // -------------------------------------------------------------------------- 00032 #ifndef VMON_DEF_FUNC 00033 #define VMON_DEF_FUNC(T) \ 00034 void add( const std::string& name, const T& v );\ 00035 static const std::string pretty_str( const std::string& name, const T* v, int width = NameWidth ); \ 00036 static const std::string pretty_str( const std::string& name, const T& v, int width = NameWidth ) 00037 #endif 00038 #ifndef VMON_DEF_FUNC2 00039 #define VMON_DEF_FUNC2(T) \ 00040 void add( const std::string& name, const T& v );\ 00041 void add( const std::string& name, const unsigned T& v );\ 00042 static const std::string pretty_str( const std::string& name, const T* v, int width = NameWidth );\ 00043 static const std::string pretty_str( const std::string& name, const unsigned T* v, int width = NameWidth ); \ 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 #endif 00047 00048 #ifndef VMON_DEF_MAP 00049 #define VMON_DEF_MAP(T) std::unordered_map<const T*,const std::string> m_##T 00050 #endif 00051 00052 #ifndef VMON_DEF_MAP2 00053 #define VMON_DEF_MAP2(T) \ 00054 std::unordered_map<const T*,const std::string> m_##T; \ 00055 std::unordered_map<const unsigned T*,const std::string> m_unsigned_##T 00056 #endif 00057 00058 #ifndef VMON_DEF_MAP3 00059 #define VMON_DEF_MAP3(T,M) std::unordered_map<const T*,const std::string> m_##M 00060 #endif 00061 00062 // -------------------------------------------------------------------------- 00063 /* EXAMPLE HELPER MACROS 00064 00065 #ifndef vmonit 00066 #define vmonit( var ) add( #var, var ) 00067 #endif 00068 00069 */ 00070 // -------------------------------------------------------------------------- 00114 class VMonitor 00115 { 00116 public: 00117 VMonitor() {} 00118 00119 friend std::ostream& operator<<(std::ostream& os, VMonitor& m ); 00120 00121 static const int NameWidth = { 30 }; 00122 static const int ColCount = { 2 }; 00123 00125 std::string str(); 00126 00131 std::string pretty_str( int namewidth = NameWidth, int colnum = ColCount ); 00132 00133 // функции добавления.. 00134 VMON_DEF_FUNC2(int); 00135 VMON_DEF_FUNC2(long); 00136 VMON_DEF_FUNC2(short); 00137 VMON_DEF_FUNC2(char); 00138 VMON_DEF_FUNC(bool); 00139 VMON_DEF_FUNC(float); 00140 VMON_DEF_FUNC(double); 00141 // VMON_DEF_FUNC(UniSetTypes::ObjectId); // <--- long 00142 00143 void add( const std::string& name, const std::string& v ); 00144 00145 static const std::string pretty_str( const std::string& name, const std::string* v, int width = NameWidth ); 00146 static const std::string pretty_str( const std::string& name, const std::string& v, int width = NameWidth ); 00147 00148 std::list<std::pair<std::string, std::string>> getList(); 00149 00150 protected: 00151 00152 private: 00153 00154 VMON_DEF_MAP2(int); 00155 VMON_DEF_MAP2(long); 00156 VMON_DEF_MAP2(short); 00157 VMON_DEF_MAP2(char); 00158 VMON_DEF_MAP(bool); 00159 VMON_DEF_MAP(float); 00160 VMON_DEF_MAP(double); 00161 VMON_DEF_MAP3(std::string, string); 00162 }; 00163 // -------------------------------------------------------------------------- 00164 #endif
1.7.6.1