[Zrouter-src] ZRouter.org: push to zconf++ zconf++/model.cc

zrouter-src at zrouter.org zrouter-src at zrouter.org
Thu Dec 15 07:53:07 UTC 2011


details:   /rev/48621451aa1e
changeset: 27:48621451aa1e
user:      "Nicolai Petri <nicolai at petri.dk>"
date:      Thu Dec 15 08:52:00 2011 +0100
description:
Don't write out any action leaf.

diffstat:

 zconf++/model.cc |  31 +++++++++++++++++++++----------
 1 files changed, 21 insertions(+), 10 deletions(-)

diffs (72 lines):

diff -r 092d0ce69f6c -r 48621451aa1e zconf++/model.cc
--- a/zconf++/model.cc	Thu Dec 08 00:05:15 2011 +0100
+++ b/zconf++/model.cc	Thu Dec 15 08:52:00 2011 +0100
@@ -89,11 +89,15 @@
 			LeafMap::iterator it = m.begin();
 			bool first = true;
 			while (it != m.end()) {
-				rv += indent;
-				if (it != m.begin()) {
-					rv += ",";
+				if (it->second.type() != action_leaf) {
+					rv += indent;
+					if (first == false) {
+						rv += ",";
+					} else {
+						first = false;
+					}
+					rv += format_json_string(it->first) + ": " + write(it->second, indent+"    ") + "\n";
 				}
-				rv += format_json_string(it->first) + ": " + write(it->second, indent+"    ") + "\n";
 				it++;
 			}
 			rv += indent + "}";
@@ -114,8 +118,9 @@
 			rv += format_json_real(l.get_real());
 		} else if (l.type() == numeric_leaf) {
 			rv += format_json_int(l.get_int());
+/* Actions should only be dumped on request */
 		} else if (l.type() == action_leaf) {
-			rv += "\"@ACTION@\"";
+			rv += "\"@ACTION@\""; 
 		} else if (l.type() == empty_leaf) {
 			rv += "null";
 		} else if (l.type() == boolean_leaf) {
@@ -130,6 +135,7 @@
 
 void ModelWriter::write(std::stringstream &buf, Leaf& l, const std::string &indent) {
 //	for (int c=0; c < l.numChildren(); c++) {
+		buf << indent;
 		if (l.type() == string_leaf) {
 	//		cout << "  dumping " << " => " << l.get_string() << endl;
 			//cout << indent << l.get_string() << endl;
@@ -141,11 +147,15 @@
 			LeafMap::iterator it = m.begin();
 			bool first = true;
 			while (it != m.end()) {
-				buf << indent;
-				if (it != m.begin()) {
-					buf << ",";
+				if (it->second.type() != action_leaf) {
+					buf << indent;
+					if (first == false) {
+						buf << ",";
+					} else {
+						first = false;
+					}
+					buf << format_json_string(it->first) << ": " << write(it->second, indent+"    ") << "\n";
 				}
-				buf << format_json_string(it->first) << ": " << write(it->second, indent+"    ") << "\n";
 				it++;
 			}
 			buf << indent << "}";
@@ -159,7 +169,8 @@
 			buf << "[\n";
 			LeafArray &a = l.array();
 			for (int c=0; c < a.size(); c++) {
-				buf << indent /*+ Int2String(c) + " => "*/ << (c>0 ? "," : "")  << write(a[c], indent+"    ") << "\n";
+				if (a[c].type() != action_leaf)
+					buf << indent /*+ Int2String(c) + " => "*/ << (c>0 ? "," : "")  << write(a[c], indent+"    ") << "\n";
 			}
 			buf << indent << "]";
 		} else if (l.type() == real_leaf) {


More information about the Zrouter-src mailing list