stats: add user settable separator string for arrayed stats

Default is '::', so no visible change unless it is overridden
This commit is contained in:
Brad Danofsky 2011-04-20 11:14:52 -07:00
parent dd38b4b83e
commit 46a538ceab
4 changed files with 28 additions and 2 deletions

View file

@ -48,6 +48,7 @@ using namespace std;
namespace Stats { namespace Stats {
std::string Info::separatorString = "::";
typedef map<const void *, Info *> MapType; typedef map<const void *, Info *> MapType;
// We wrap these in a function to make sure they're built in time. // We wrap these in a function to make sure they're built in time.

View file

@ -255,6 +255,23 @@ class DataWrap : public InfoAccess
} }
const std::string &name() const { return this->info()->name; } const std::string &name() const { return this->info()->name; }
/**
* Set the character(s) used between the name and vector number
* on vectors, dist, etc.
* @param _sep The new separator string
* @return A reference to this stat.
*/
Derived &
setSeparator(const std::string &_sep)
{
this->info()->setSeparator(_sep);
return this->self();
}
const std::string &setSeparator() const
{
return this->info()->separatorString;
}
/** /**
* Set the description and marks this stat to print at the end of * Set the description and marks this stat to print at the end of
* simulation. * simulation.

View file

@ -69,6 +69,8 @@ class Info
public: public:
/** The name of the stat. */ /** The name of the stat. */
std::string name; std::string name;
/** The separator string used for vectors, dist, etc. */
static std::string separatorString;
/** The description of the stat. */ /** The description of the stat. */
std::string desc; std::string desc;
/** The formatting flags. */ /** The formatting flags. */
@ -93,6 +95,7 @@ class Info
/** Set the name of this statistic */ /** Set the name of this statistic */
void setName(const std::string &name); void setName(const std::string &name);
void setSeparator(std::string _sep) { separatorString = _sep;}
/** /**
* Check that this stat has been set up properly and is ready for * Check that this stat has been set up properly and is ready for

View file

@ -234,6 +234,7 @@ ScalarPrint::operator()(ostream &stream) const
struct VectorPrint struct VectorPrint
{ {
string name; string name;
string separatorString;
string desc; string desc;
vector<string> subnames; vector<string> subnames;
vector<string> subdescs; vector<string> subdescs;
@ -258,7 +259,7 @@ VectorPrint::operator()(std::ostream &stream) const
} }
} }
string base = name + "::"; string base = name + separatorString;
ScalarPrint print; ScalarPrint print;
print.name = name; print.name = name;
@ -301,6 +302,7 @@ VectorPrint::operator()(std::ostream &stream) const
struct DistPrint struct DistPrint
{ {
string name; string name;
string separatorString;
string desc; string desc;
Flags flags; Flags flags;
bool descriptions; bool descriptions;
@ -336,6 +338,7 @@ void
DistPrint::init(const Text *text, const Info &info) DistPrint::init(const Text *text, const Info &info)
{ {
name = info.name; name = info.name;
separatorString = info.separatorString;
desc = info.desc; desc = info.desc;
flags = info.flags; flags = info.flags;
precision = info.precision; precision = info.precision;
@ -345,7 +348,7 @@ DistPrint::init(const Text *text, const Info &info)
void void
DistPrint::operator()(ostream &stream) const DistPrint::operator()(ostream &stream) const
{ {
string base = name + "::"; string base = name + separatorString;
ScalarPrint print; ScalarPrint print;
print.precision = precision; print.precision = precision;
@ -465,6 +468,7 @@ Text::visit(const VectorInfo &info)
VectorPrint print; VectorPrint print;
print.name = info.name; print.name = info.name;
print.separatorString = info.separatorString;
print.desc = info.desc; print.desc = info.desc;
print.flags = info.flags; print.flags = info.flags;
print.descriptions = descriptions; print.descriptions = descriptions;
@ -504,6 +508,7 @@ Text::visit(const Vector2dInfo &info)
print.subnames = info.y_subnames; print.subnames = info.y_subnames;
print.flags = info.flags; print.flags = info.flags;
print.separatorString = info.separatorString;
print.descriptions = descriptions; print.descriptions = descriptions;
print.precision = info.precision; print.precision = info.precision;