00001 #ifndef XML_Streamer_hh_
00002 #define XML_Streamer_hh_
00003
00004 #include <iostream>
00005 #include <string>
00006 #include <stack>
00007
00008 namespace XML {
00009
00010 class Streamer {
00011 public:
00012 Streamer(std::ostream& inStream, unsigned int inWidth=2) : mStream(inStream), mWidth(inWidth), mClosed(true) {}
00013
00014 void closeTag(bool inIndent=true);
00015 std::ostream& getStream();
00016 void insertAttribute(const std::string& inName, double inValue);
00017 void insertAttribute(const std::string& inName, std::string inValue);
00018 template<class Container>
00019 void insertContainer(const Container& inValue, const std::string& inName="");
00020 void insertPrimitiveTag(double invalue, const std::string& inTagName="Float", const std::string& inAttributeName="value");
00021 void insertPrimitiveTag(int invalue, const std::string& inTagName="Integer", const std::string& inAttributeName="value");
00022 void insertPrimitiveTag(const std::string& invalue, const std::string& inTagName="String", const std::string& inAttributeName="value");
00023 void insertSpecialTag(const std::string& inTag);
00024 void openTag(const std::string& inName, bool inIndent=true);
00025
00026 Streamer& operator<<(int inValue);
00027 Streamer& operator<<(double inValue);
00028 Streamer& operator<<(const std::string& inValue);
00029
00030 template<class T> Streamer& operator<<(const T& inClass) {
00031 inClass.write(*this);
00032 return *this;
00033 }
00034
00035 protected:
00036 std::ostream& mStream;
00037 std::stack<std::string> mTags;
00038 unsigned int mWidth;
00039 bool mClosed;
00040
00041 };
00042
00043 template<class Container>
00044 void Streamer::insertContainer(const Container& inContainer,
00045 const std::string& inName
00046 )
00047 {
00048
00049 if(inName != "") openTag(inName);
00050
00051 for(typename Container::const_iterator i = inContainer.begin(); i != inContainer.end(); ++i)
00052 {
00053 (*this) << (*i);
00054 }
00055 if(inName != "") closeTag();
00056 }
00057
00058 }
00059
00060 #endif // XML_Streamer_hh_