inlib  1.2.0
/Users/barrand/private/dev/softinex/old/inexlib-1.2/inlib/inlib/sg/write_exsg
Go to the documentation of this file.
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
00002 // See the file inlib.license for terms.
00003 
00004 #ifndef inlib_sg_write_exsg
00005 #define inlib_sg_write_exsg
00006 
00007 // inheritance :
00008 #include "write_action"
00009 
00010 #include "../io/xwbuf"
00011 
00012 #include "../sg/node"
00013 #include "../file"
00014 
00015 namespace inlib {
00016 namespace sg {
00017 
00018 class write_exsg : public write_action {
00019 public:
00020   virtual io::iwbuf& buffer() {return m_buffer;}
00021   virtual bool beg_node(const node& a_node) {
00022     std::string s;
00023     s  += "<";
00024     s  += a_node.s_cls();
00025     s  += ">\n";
00026     return m_buffer.write_verbatim(s.c_str());
00027   }
00028   virtual bool end_node(const node& a_node) {
00029     std::string s;
00030     s  += "\n</";
00031     s  += a_node.s_cls();
00032     s  += ">\n";
00033     return m_buffer.write_verbatim(s.c_str());
00034   }
00035 public:
00036   write_exsg(std::ostream& a_out)
00037   : write_action(a_out),m_buffer(a_out)
00038   {}
00039   virtual ~write_exsg(){}
00040 protected:
00041   write_exsg(const write_exsg& a_from)
00042   : write_action(a_from)
00043   ,m_buffer(a_from.m_out)
00044   {}
00045   write_exsg& operator=(const write_exsg& a_from){
00046     write_action::operator=(a_from);
00047     return *this;
00048   }
00049 public:
00050   bool open_buffer() {
00051     m_buffer.reset_pos();
00052 
00053     //NOTE : if changing the header, change inlib::file::is_exsg().
00054    {std::string s;
00055     s  += "<exsg>\n";
00056     if(!m_buffer.write_verbatim(s.c_str())) return false;}
00057 
00058     return true;
00059   }
00060 
00061   bool close_buffer() {
00062    {std::string s;
00063     s  += "</exsg>\n";
00064     if(!m_buffer.write_verbatim(s.c_str())) return false;}
00065     return true;
00066   }
00067 
00068   bool write_file(const std::string& a_file) const {
00069     return file::write_bytes(a_file,m_buffer.buf(),m_buffer.length());
00070   }
00071 private:
00072   io::xwbuf m_buffer;
00073 };
00074 
00075 }}
00076 
00077 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines