Commit ccb609bc authored by Pavel Vainerman's avatar Pavel Vainerman

VMonitor: добавил ещё helper-функиции pretty_str(...)

parent 9b14a94b
...@@ -31,14 +31,17 @@ ...@@ -31,14 +31,17 @@
#ifndef VMON_DEF_FUNC #ifndef VMON_DEF_FUNC
#define VMON_DEF_FUNC(T) \ #define VMON_DEF_FUNC(T) \
void add( const std::string& name, const T& v );\ void add( const std::string& name, const T& v );\
const std::string pretty_str( const std::string& name, const T* v ) static const std::string pretty_str( const std::string& name, const T* v, int width = NameWidth ); \
static const std::string pretty_str( const std::string& name, const T& v, int width = NameWidth )
#endif #endif
#ifndef VMON_DEF_FUNC2 #ifndef VMON_DEF_FUNC2
#define VMON_DEF_FUNC2(T) \ #define VMON_DEF_FUNC2(T) \
void add( const std::string& name, const T& v );\ void add( const std::string& name, const T& v );\
void add( const std::string& name, const unsigned T& v );\ void add( const std::string& name, const unsigned T& v );\
const std::string pretty_str( const std::string& name, const T* v );\ static const std::string pretty_str( const std::string& name, const T* v, int width = NameWidth );\
const std::string pretty_str( const std::string& name, const unsigned T* v ) static const std::string pretty_str( const std::string& name, const unsigned T* v, int width = NameWidth ); \
static const std::string pretty_str( const std::string& name, const T& v, int width = NameWidth );\
static const std::string pretty_str( const std::string& name, const unsigned T& v, int width = NameWidth )
#endif #endif
#ifndef VMON_DEF_MAP #ifndef VMON_DEF_MAP
...@@ -114,6 +117,8 @@ class VMonitor ...@@ -114,6 +117,8 @@ class VMonitor
friend std::ostream& operator<<(std::ostream& os, VMonitor& m ); friend std::ostream& operator<<(std::ostream& os, VMonitor& m );
static const int NameWidth = { 30 };
std::string str(); std::string str();
std::string pretty_str(); std::string pretty_str();
...@@ -128,17 +133,10 @@ class VMonitor ...@@ -128,17 +133,10 @@ class VMonitor
// VMON_DEF_FUNC(UniSetTypes::ObjectId); // <--- long // VMON_DEF_FUNC(UniSetTypes::ObjectId); // <--- long
void add( const std::string& name, const std::string& v ); void add( const std::string& name, const std::string& v );
const std::string pretty_str( const std::string& name, const std::string* v );
inline int getNameWidth()
{
return nameWidth;
}
inline void setNameWidth( int w )
{
nameWidth = w;
}
static const std::string pretty_str( const std::string& name, const std::string* v, int width = NameWidth );
static const std::string pretty_str( const std::string& name, const std::string& v, int width = NameWidth );
protected: protected:
private: private:
...@@ -152,8 +150,6 @@ class VMonitor ...@@ -152,8 +150,6 @@ class VMonitor
VMON_DEF_MAP(double); VMON_DEF_MAP(double);
// VMON_DEF_MAP3(UniSetTypes::ObjectId,ObjectId); // <-- long // VMON_DEF_MAP3(UniSetTypes::ObjectId,ObjectId); // <-- long
VMON_DEF_MAP3(std::string, string); VMON_DEF_MAP3(std::string, string);
int nameWidth = { 30 };
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#endif #endif
...@@ -9,11 +9,15 @@ ...@@ -9,11 +9,15 @@
m_##T.emplace(&v,name); \ m_##T.emplace(&v,name); \
} \ } \
\ \
const std::string VMonitor::pretty_str( const std::string& name, const T* v ) \ const std::string VMonitor::pretty_str( const std::string& name, const T* v, int nwidth ) \
{ \ { \
std::ostringstream s; \ std::ostringstream s; \
s << std::right << std::setw(nameWidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \ s << std::right << std::setw(nwidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \
return std::move(s.str()); \ return std::move(s.str()); \
} \
const std::string VMonitor::pretty_str( const std::string& name, const T& v, int nwidth ) \
{ \
return pretty_str(name,&v,nwidth); \
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#define VMON_IMPL_ADD2(T) \ #define VMON_IMPL_ADD2(T) \
...@@ -25,28 +29,40 @@ ...@@ -25,28 +29,40 @@
{\ {\
m_unsigned_##T.emplace(&v,name); \ m_unsigned_##T.emplace(&v,name); \
} \ } \
const std::string VMonitor::pretty_str( const std::string& name, const T* v ) \ const std::string VMonitor::pretty_str( const std::string& name, const T* v, int nwidth ) \
{ \ { \
std::ostringstream s; \ std::ostringstream s; \
s << std::right << std::setw(nameWidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \ s << std::right << std::setw(nwidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \
return std::move(s.str()); \ return std::move(s.str()); \
} \ } \
const std::string VMonitor::pretty_str( const std::string& name, const unsigned T* v ) \ const std::string VMonitor::pretty_str( const std::string& name, const unsigned T* v, int nwidth ) \
{ \ { \
std::ostringstream s; \ std::ostringstream s; \
s << std::right << std::setw(nameWidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \ s << std::right << std::setw(nwidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \
return std::move(s.str()); \ return std::move(s.str()); \
} \
const std::string VMonitor::pretty_str( const std::string& name, const T& v, int nwidth ) \
{ \
return pretty_str(name,&v,nwidth); \
} \
const std::string VMonitor::pretty_str( const std::string& name, const unsigned T& v, int nwidth ) \
{ \
return pretty_str(name,&v,nwidth); \
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#define VMON_IMPL_ADD3(T,M) void VMonitor::add( const std::string& name, const T& v ) \ #define VMON_IMPL_ADD3(T,M) void VMonitor::add( const std::string& name, const T& v ) \
{\ {\
m_##M.emplace(&v,name); \ m_##M.emplace(&v,name); \
} \ } \
const std::string VMonitor::pretty_str( const std::string& name, const T* v ) \ const std::string VMonitor::pretty_str( const std::string& name, const T* v, int nwidth ) \
{ \ { \
std::ostringstream s; \ std::ostringstream s; \
s << std::right << std::setw(nameWidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \ s << std::right << std::setw(nwidth) << name << std::left << " = " << std::right << std::setw(6) << *(v); \
return std::move(s.str()); \ return std::move(s.str()); \
} \
const std::string VMonitor::pretty_str( const std::string& name, const T& v, int nwidth ) \
{ \
return pretty_str(name,&v,nwidth); \
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#define VMON_IMPL_PRN(M,T) \ #define VMON_IMPL_PRN(M,T) \
...@@ -91,10 +107,10 @@ ...@@ -91,10 +107,10 @@
#define VMON_IMPL_PRET_CHAR \ #define VMON_IMPL_PRET_CHAR \
{\ {\
for( const auto& e: m_char ) \ for( const auto& e: m_char ) \
os << std::right << std::setw(nameWidth) << e.second << std::left << " = " << std::right << std::setw(6) << (int)(*(e.first)) << std::endl;\ os << std::right << std::setw(NameWidth) << e.second << std::left << " = " << std::right << std::setw(6) << (int)(*(e.first)) << std::endl;\
\ \
for( const auto& e: m_unsigned_char ) \ for( const auto& e: m_unsigned_char ) \
os << std::right << std::setw(nameWidth) << e.second << std::left << " = " << std::right << std::setw(6) << (int)(*(e.first)) << std::endl;\ os << std::right << std::setw(NameWidth) << e.second << std::left << " = " << std::right << std::setw(6) << (int)(*(e.first)) << std::endl;\
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
VMON_IMPL_ADD2(int) VMON_IMPL_ADD2(int)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment