print function for AmArg to represent in debug output

thanks to Bogdan Pintea



git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1314 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 18 years ago
parent 791d861ab7
commit e65a1296db

@ -27,6 +27,7 @@
#include "AmArg.h"
#include "log.h"
#include "AmUtils.h"
const char* t2str(int type) {
switch (type) {
@ -354,3 +355,39 @@ vector<ArgBlob> AmArg::asArgBlobVector() const {
void AmArg::clear() {
invalidate();
}
string AmArg::print(const AmArg &a) {
string s;
switch (a.getType()) {
case Undef:
return "<UNDEFINED>";
case Int:
return int2str(a.asInt());
case Double:
return int2str((int)a.asDouble()); //TODO: FIXME
case CStr:
return '"' + string(a.asCStr()) + '"';
case Array:
s = "[";
for (size_t i = 0; i < a.size(); i ++)
s += print(a[i]) + ", ";
if (1 < s.size())
s.resize(s.size() - 2); // strip last ", "
s += "]";
return s;
case Struct:
s = "{";
for (AmArg::ValueStruct::const_iterator it = a.asStruct()->begin();
it != a.asStruct()->end(); it ++) {
s += it->first + ":";
s += print(it->second);
s += ", ";
}
if (1 < s.size())
s.resize(s.size() - 2); // strip last ", "
s += "}";
return s;
default: break;
}
return "<UNKONWN TYPE>";
}

@ -280,6 +280,8 @@ class AmArg
void clear();
friend bool operator==(const AmArg& lhs, const AmArg& rhs);
static string print(const AmArg &a);
};
// equality

Loading…
Cancel
Save