diff options
| -rw-r--r-- | project2/common/rowView.cpp | 21 | ||||
| -rw-r--r-- | project2/common/rowView.h | 1 | ||||
| -rw-r--r-- | project2/json/presenter.cpp | 11 | 
3 files changed, 24 insertions, 9 deletions
diff --git a/project2/common/rowView.cpp b/project2/common/rowView.cpp index efcf017..41eceec 100644 --- a/project2/common/rowView.cpp +++ b/project2/common/rowView.cpp @@ -13,9 +13,10 @@ RowView::RowView(ScriptNodePtr p) :  	SourceObject(p),  	View(p),  	RowProcessor(p), -	rootName(p, "rootname"), +	rootName(p, "rootname", Null()),  	recordName(p, "recordname"), -	required(p, "required", false) +	required(p, "required", false), +	isObject(p, "isobject", true)  {  	BOOST_FOREACH(ScriptNodePtr node, p->childrenIn("columns")) {  		viewColumns.insert(Columns::value_type(node->get_name(), Variable(node))); @@ -39,7 +40,9 @@ void  RowView::rowReady(const RowState * rs) const  {  	rowsFound = true; -	presenter->addNewRow(recordName()); +	if (isObject()) { +		presenter->addNewRow(recordName()); +	}  	if (viewColumns.empty()) {  		rs->foreachColumn(boost::bind(&RowSetPresenter::addNamedValue, presenter, _2, _3));  	} @@ -48,8 +51,10 @@ RowView::rowReady(const RowState * rs) const  			presenter->addNamedValue(col.first, col.second);  		}  	} -	executeChildren(); -	presenter->finishRow(); +	if (isObject()) { +		executeChildren(); +		presenter->finishRow(); +	}  	BOOST_FOREACH(SetAggregateCPtr s, setAggregates) {  		s->pushValue();  	} @@ -63,8 +68,10 @@ RowView::execute(const MultiRowSetPresenter * p) const  {  	rowsFound = false;  	presenter = p; -	presenter->addNewRowSet(rootName()); -	ScopeObject pres(boost::bind(&MultiRowSetPresenter::finishRowSet, p)); +	if (!rootName().isNull()) { +		presenter->addNewRowSet(rootName()); +	} +	ScopeObject pres(rootName().isNull() ? ScopeObject::Event() : boost::bind(&MultiRowSetPresenter::finishRowSet, p));  	{  		presenter->addNewArray(recordName(), true);  		ScopeObject pres(boost::bind(&MultiRowSetPresenter::finishArray, p, true)); diff --git a/project2/common/rowView.h b/project2/common/rowView.h index 250d54e..9ba4699 100644 --- a/project2/common/rowView.h +++ b/project2/common/rowView.h @@ -19,6 +19,7 @@ class RowView : public View, public RowProcessor {  		const Variable rootName;  		const Variable recordName;  		const Variable required; +		const Variable isObject;  	protected:  		typedef std::map<Glib::ustring, Variable> Columns; diff --git a/project2/json/presenter.cpp b/project2/json/presenter.cpp index 00ed334..01bb915 100644 --- a/project2/json/presenter.cpp +++ b/project2/json/presenter.cpp @@ -11,7 +11,8 @@ class JsonPresenter : public MultiRowSetPresenter, public ContentPresenter, publ  			TransformSource(s),  			ContentPresenter("application/json"),  			SourceOf<json::Object>(s), -			SourceOf<WritableContent>(s) { +			SourceOf<WritableContent>(s), +			returnObject(s, "object", Null()) {  			curRowSet.push(&object);  			vaStack.push(&JsonPresenter::addValueToObject);  		} @@ -72,10 +73,16 @@ class JsonPresenter : public MultiRowSetPresenter, public ContentPresenter, publ  			return ClassData;  		}  		void writeTo(std::ostream & o, const std::string & encoding) const { -			serializeObject(object, o, encoding); +			if (returnObject().isNull()) { +				serializeObject(object, o, encoding); +			} +			else { +				serializeValue(*object[returnObject()], o, encoding); +			}  		}  	private: +		Variable returnObject;  		mutable json::Object object;  		mutable std::stack<json::Object *> curRowSet;  		mutable std::stack<json::Array *> curRowArray;  | 
