Author: sayer
Date: 2009-03-13 18:19:59 +0100 (Fri, 13 Mar 2009)
New Revision: 1314

Modified:
   trunk/core/AmArg.cpp
   trunk/core/AmArg.h
Log:
print function for AmArg to represent in debug output

thanks to Bogdan Pintea



Modified: trunk/core/AmArg.cpp
===================================================================
--- trunk/core/AmArg.cpp        2009-03-12 12:53:30 UTC (rev 1313)
+++ trunk/core/AmArg.cpp        2009-03-13 17:19:59 UTC (rev 1314)
@@ -27,6 +27,7 @@
 
 #include "AmArg.h"
 #include "log.h"
+#include "AmUtils.h"
 
 const char* t2str(int type) {
   switch (type) {
@@ -354,3 +355,39 @@
 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>";
+}

Modified: trunk/core/AmArg.h
===================================================================
--- trunk/core/AmArg.h  2009-03-12 12:53:30 UTC (rev 1313)
+++ trunk/core/AmArg.h  2009-03-13 17:19:59 UTC (rev 1314)
@@ -280,6 +280,8 @@
 
   void clear();
   friend bool operator==(const AmArg& lhs, const AmArg& rhs);
+
+  static string print(const AmArg &a);
 };
 
 // equality

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to