00001
00002 #ifndef AKAXISO2_XML_SERIALIZER_SERIALIZER_H__
00003 #define AKAXISO2_XML_SERIALIZER_SERIALIZER_H__
00004
00010 #include <akaxiso2/framework/membertype.h>
00011 #include <akaxiso2/framework/any.h>
00012 #include <akaxiso2/framework/document.h>
00013 #include <akaxiso2/framework/document_factory.h>
00014 #include <akaxiso2/framework/entity_complements.h>
00015 #include <akaxiso2/XML/serializer/formatter_base.h>
00016 #include <akaxiso2/util/shared_ptr.h>
00017 #include <set>
00018 #include <stack>
00019
00020 namespace aka2 {
00021
00029 void serialize(const document &doc, std::ostream &ostm);
00030
00032 class serializer {
00033 public:
00034 serializer(int tab);
00035 virtual ~serializer();
00036
00037 void set_entity_complements(entity_complements &pcd);
00038
00043 void using_prefix(const std::string &prefix);
00044
00049 void using_uri(const std::string &uri);
00050
00055 void default_ns_prefix(const std::string &prefix);
00056
00061 void default_ns_uri(const std::string &uri);
00062
00068 void serialize(const document &doc, std::ostream &ostm);
00069
00076 template <class R>
00077 void serialize(const R &root, const std::string &name, std::ostream &ostm) {
00078 aka2::qname qn(name);
00079 const element_props &props = system_document_factory().get_props(qn);
00080 do_serialize(&root, props, qn, ostm);
00081 }
00082
00083 private:
00084 void do_serialize(const void *e, const element_props &props, const qname &name, std::ostream &ostm);
00085 virtual void serialize_internal(const void *e, const element_props &props,
00086 const qname &name) = 0;
00087
00088 int indent_;
00089 std::string indent_str_;
00090
00091 int any_depth_;
00092
00093 protected:
00094 const prefix_map& get_prefixes() const {
00095 return ecomp_->get_prefixes();
00096 }
00097
00098 void inc_indent_level() { ++indent_; }
00099 void dec_indent_level() { --indent_; }
00100 void new_line();
00101
00102 void inc_ns_depth();
00103 void dec_ns_depth();
00104 bool is_new_ns(id_type id) const;
00105 void use_temp_nsdecl(id_type id);
00106
00107 static bool is_sequence_empty(const void *e, const member_types &mtypes);
00108 static bool is_all_empty(const void *e, const member_map &mmap);
00109 static bool is_member_empty(const void *e, const member_type &mtype);
00110 static bool is_any_empty(const void *e, const member_type &mtype);
00111 static bool is_fixed_empty(const void *e, const member_type &mtype);
00112
00114 shared_ptr<formatter_base> formatter_;
00115 bool is_root_;
00116
00117 typedef std::vector<id_type> ids;
00118 ids nsids_;
00119
00120 typedef std::set<id_type> ns_set;
00121 typedef std::stack<ns_set> ns_stack;
00122 ns_stack ns_stack_;
00123 entity_complements *ecomp_;
00124 shared_ptr<entity_complements> ecomp_holder_;
00125 };
00126
00127 }
00128
00129 #endif