Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members Related Pages

# formatter_base.h

Go to the documentation of this file.

    00001 /* -*- c++ -*- */
    00002 #ifndef AKAXISO2_XML_SERIALIZER_FORMATTER_BASE_H__
    00003 #define AKAXISO2_XML_SERIALIZER_FORMATTER_BASE_H__
    00004
    00010 #include <akaxiso2/util/iosfwd.h>
    00011 #include <akaxiso2/util/ustring.h>
    00012 #include <akaxiso2/XML/encoding_name.h>
    00013
    00014 namespace aka2 {
    00015
    00016   struct bom {
    00017     char chars_[16];
    00018     unsigned int length_;
    00019   };
    00020
    00028   class formatter_base {
    00029   public:
    00030     formatter_base() : bom_(0), ostm_(0), fd_(-1) {}
    00031     virtual ~formatter_base() {  }
    00032
    00039     virtual void set_encoding(const std::string &encoding) = 0;
    00040
    00045     void prepare(std::ostream &ostm);
    00049     void finish();
    00050
    00051     void write(const std::string &value);
    00052     void write_attribute_entity(const std::string &entity);
    00053     void write_text_entity(const std::string &entity);
    00054
    00055   private:
    00061     virtual ustring lcp_to_ucs2(const std::string &source) = 0;
    00062
    00068     virtual void write(const ustring &entity) = 0;
    00069     void write_entity(const std::string &entity, const int escape_index);
    00070     void set_binary_mode_for_stdio();
    00071     void revert_stream_mode();
    00072
    00073   protected:
    00074     const bom* bom_;
    00075     const bom* check_bom(const std::string &encoding) const;
    00076     std::ostream *ostm_;
    00077   private:
    00078     std::string encoding_;
    00079     int saved_stream_mode_;
    00080     int fd_;
    00081   };
    00082
    00083 } // namespace aka2
    00084
    00085 #endif