diff --git a/core/AmArg.cpp b/core/AmArg.cpp index b0a8268b..dd10a0bb 100644 --- a/core/AmArg.cpp +++ b/core/AmArg.cpp @@ -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 AmArg::asArgBlobVector() const { void AmArg::clear() { invalidate(); } + +string AmArg::print(const AmArg &a) { + string s; + switch (a.getType()) { + case Undef: + return ""; + 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 ""; +} diff --git a/core/AmArg.h b/core/AmArg.h index 3ee1a086..6d64d4ee 100644 --- a/core/AmArg.h +++ b/core/AmArg.h @@ -280,6 +280,8 @@ class AmArg void clear(); friend bool operator==(const AmArg& lhs, const AmArg& rhs); + + static string print(const AmArg &a); }; // equality