diff --git a/py/modules/IcePy/Types.cpp b/py/modules/IcePy/Types.cpp index 347e5f7..17eef23 100644 --- a/py/modules/IcePy/Types.cpp +++ b/py/modules/IcePy/Types.cpp @@ -915,7 +915,7 @@ IcePy::PrimitiveInfo::unmarshal(const Ice::InputStreamPtr& is, const UnmarshalCa } void -IcePy::PrimitiveInfo::print(PyObject* value, IceUtilInternal::Output& out, PrintObjectHistory*) +IcePy::PrimitiveInfo::print(PyObject* value, PrintHelper& out, PrintObjectHistory*) { if(!validate(value)) { @@ -1050,7 +1050,7 @@ IcePy::EnumInfo::unmarshal(const Ice::InputStreamPtr& is, const UnmarshalCallbac } void -IcePy::EnumInfo::print(PyObject* value, IceUtilInternal::Output& out, PrintObjectHistory*) +IcePy::EnumInfo::print(PyObject* value, PrintHelper& out, PrintObjectHistory*) { if(!validate(value)) { @@ -1311,7 +1311,7 @@ IcePy::StructInfo::unmarshal(const Ice::InputStreamPtr& is, const UnmarshalCallb } void -IcePy::StructInfo::print(PyObject* value, IceUtilInternal::Output& out, PrintObjectHistory* history) +IcePy::StructInfo::print(PyObject* value, PrintHelper& out, PrintObjectHistory* history) { if(!validate(value)) { @@ -1571,7 +1571,7 @@ IcePy::SequenceInfo::unmarshal(const Ice::InputStreamPtr& is, const UnmarshalCal } void -IcePy::SequenceInfo::print(PyObject* value, IceUtilInternal::Output& out, PrintObjectHistory* history) +IcePy::SequenceInfo::print(PyObject* value, PrintHelper& out, PrintObjectHistory* history) { if(!validate(value)) { @@ -2409,7 +2409,7 @@ IcePy::CustomInfo::unmarshal(const Ice::InputStreamPtr& is, const UnmarshalCallb } void -IcePy::CustomInfo::print(PyObject* value, IceUtilInternal::Output& out, PrintObjectHistory* history) +IcePy::CustomInfo::print(PyObject* value, PrintHelper& out, PrintObjectHistory* history) { if(!validate(value)) { @@ -2615,7 +2615,7 @@ IcePy::DictionaryInfo::unmarshaled(PyObject* val, PyObject* target, void* closur } void -IcePy::DictionaryInfo::print(PyObject* value, IceUtilInternal::Output& out, PrintObjectHistory* history) +IcePy::DictionaryInfo::print(PyObject* value, PrintHelper& out, PrintObjectHistory* history) { if(!validate(value)) { @@ -2816,7 +2816,7 @@ IcePy::ClassInfo::unmarshal(const Ice::InputStreamPtr& is, const UnmarshalCallba } void -IcePy::ClassInfo::print(PyObject* value, IceUtilInternal::Output& out, PrintObjectHistory* history) +IcePy::ClassInfo::print(PyObject* value, PrintHelper& out, PrintObjectHistory* history) { if(!validate(value)) { @@ -2881,7 +2881,7 @@ IcePy::ClassInfo::destroy() } void -IcePy::ClassInfo::printMembers(PyObject* value, IceUtilInternal::Output& out, PrintObjectHistory* history) +IcePy::ClassInfo::printMembers(PyObject* value, PrintHelper& out, PrintObjectHistory* history) { if(base) { @@ -3035,7 +3035,7 @@ IcePy::ProxyInfo::unmarshal(const Ice::InputStreamPtr& is, const UnmarshalCallba } void -IcePy::ProxyInfo::print(PyObject* value, IceUtilInternal::Output& out, PrintObjectHistory*) +IcePy::ProxyInfo::print(PyObject* value, PrintHelper& out, PrintObjectHistory*) { if(!validate(value)) { @@ -3487,7 +3487,7 @@ IcePy::ExceptionInfo::unmarshal(const Ice::InputStreamPtr& is) } void -IcePy::ExceptionInfo::print(PyObject* value, IceUtilInternal::Output& out) +IcePy::ExceptionInfo::print(PyObject* value, PrintHelper& out) { if(!PyObject_IsInstance(value, pythonType.get())) { @@ -3505,7 +3505,7 @@ IcePy::ExceptionInfo::print(PyObject* value, IceUtilInternal::Output& out) } void -IcePy::ExceptionInfo::printMembers(PyObject* value, IceUtilInternal::Output& out, PrintObjectHistory* history) +IcePy::ExceptionInfo::printMembers(PyObject* value, PrintHelper& out, PrintObjectHistory* history) { if(base) { @@ -4233,7 +4233,7 @@ IcePy_stringify(PyObject*, PyObject* args) assert(info); ostringstream ostr; - IceUtilInternal::Output out(ostr); + PrintHelper out(ostr); PrintObjectHistory history; history.index = 0; info->print(value, out, &history); @@ -4258,7 +4258,7 @@ IcePy_stringifyException(PyObject*, PyObject* args) assert(info); ostringstream ostr; - IceUtilInternal::Output out(ostr); + PrintHelper out(ostr); info->print(value, out); string str = ostr.str(); diff --git a/py/modules/IcePy/Types.h b/py/modules/IcePy/Types.h index 81d77f7..3a0d780 100644 --- a/py/modules/IcePy/Types.h +++ b/py/modules/IcePy/Types.h @@ -69,6 +69,50 @@ struct PrintObjectHistory std::map objects; }; +struct PrintHelper +{ + std::ostream& os; + Ice::Long indent; + + PrintHelper(std::ostream& o): os(o), indent(0) {} + void newline() + { + os << "\n" << std::string(indent * 4, ' '); + os.flush(); + } + + void sb() + { + newline(); + os << "{"; + ++indent; + } + + void eb() + { + --indent; + newline(); + os << "}"; + } +}; + +template +inline PrintHelper& +operator<<(PrintHelper& ph, const T& val) +{ + ph.os << val; + return ph; +} + +template<> +inline PrintHelper& +operator<<(PrintHelper& ph, const IceUtilInternal::NextLine&) +{ + ph.newline(); + return ph; +} + + // // The delayed nature of class unmarshaling in the Ice protocol requires us to // handle unmarshaling using a callback strategy. An instance of UnmarshalCallback @@ -127,7 +171,7 @@ public: virtual void unmarshal(const Ice::InputStreamPtr&, const UnmarshalCallbackPtr&, PyObject*, void*, bool, const Ice::StringSeq* = 0) = 0; - virtual void print(PyObject*, IceUtilInternal::Output&, PrintObjectHistory*) = 0; + virtual void print(PyObject*, PrintHelper&, PrintObjectHistory*) = 0; }; typedef IceUtil::Handle TypeInfoPtr; @@ -164,7 +208,7 @@ public: virtual void unmarshal(const Ice::InputStreamPtr&, const UnmarshalCallbackPtr&, PyObject*, void*, bool, const Ice::StringSeq* = 0); - virtual void print(PyObject*, IceUtilInternal::Output&, PrintObjectHistory*); + virtual void print(PyObject*, PrintHelper&, PrintObjectHistory*); const Kind kind; }; @@ -193,7 +237,7 @@ public: virtual void unmarshal(const Ice::InputStreamPtr&, const UnmarshalCallbackPtr&, PyObject*, void*, bool, const Ice::StringSeq* = 0); - virtual void print(PyObject*, IceUtilInternal::Output&, PrintObjectHistory*); + virtual void print(PyObject*, PrintHelper&, PrintObjectHistory*); const std::string id; const PyObjectHandle pythonType; @@ -240,7 +284,7 @@ public: virtual void unmarshal(const Ice::InputStreamPtr&, const UnmarshalCallbackPtr&, PyObject*, void*, bool, const Ice::StringSeq* = 0); - virtual void print(PyObject*, IceUtilInternal::Output&, PrintObjectHistory*); + virtual void print(PyObject*, PrintHelper&, PrintObjectHistory*); virtual void destroy(); @@ -278,7 +322,7 @@ public: virtual void unmarshal(const Ice::InputStreamPtr&, const UnmarshalCallbackPtr&, PyObject*, void*, bool, const Ice::StringSeq* = 0); - virtual void print(PyObject*, IceUtilInternal::Output&, PrintObjectHistory*); + virtual void print(PyObject*, PrintHelper&, PrintObjectHistory*); virtual void destroy(); @@ -338,7 +382,7 @@ public: virtual void unmarshal(const Ice::InputStreamPtr&, const UnmarshalCallbackPtr&, PyObject*, void*, bool, const Ice::StringSeq* = 0); - virtual void print(PyObject*, IceUtilInternal::Output&, PrintObjectHistory*); + virtual void print(PyObject*, PrintHelper&, PrintObjectHistory*); virtual void destroy(); @@ -371,7 +415,7 @@ public: const Ice::StringSeq* = 0); virtual void unmarshaled(PyObject*, PyObject*, void*); - virtual void print(PyObject*, IceUtilInternal::Output&, PrintObjectHistory*); + virtual void print(PyObject*, PrintHelper&, PrintObjectHistory*); virtual void destroy(); @@ -420,11 +464,11 @@ public: virtual void unmarshal(const Ice::InputStreamPtr&, const UnmarshalCallbackPtr&, PyObject*, void*, bool, const Ice::StringSeq* = 0); - virtual void print(PyObject*, IceUtilInternal::Output&, PrintObjectHistory*); + virtual void print(PyObject*, PrintHelper&, PrintObjectHistory*); virtual void destroy(); - void printMembers(PyObject*, IceUtilInternal::Output&, PrintObjectHistory*); + void printMembers(PyObject*, PrintHelper&, PrintObjectHistory*); const std::string id; const Ice::Int compactId; @@ -462,7 +506,7 @@ public: virtual void unmarshal(const Ice::InputStreamPtr&, const UnmarshalCallbackPtr&, PyObject*, void*, bool, const Ice::StringSeq* = 0); - virtual void print(PyObject*, IceUtilInternal::Output&, PrintObjectHistory*); + virtual void print(PyObject*, PrintHelper&, PrintObjectHistory*); virtual void destroy(); @@ -482,8 +526,8 @@ public: void marshal(PyObject*, const Ice::OutputStreamPtr&, ObjectMap*); PyObject* unmarshal(const Ice::InputStreamPtr&); - void print(PyObject*, IceUtilInternal::Output&); - void printMembers(PyObject*, IceUtilInternal::Output&, PrintObjectHistory*); + void print(PyObject*, PrintHelper&); + void printMembers(PyObject*, PrintHelper&, PrintObjectHistory*); std::string id; bool preserve;