00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef XIMOL_CONTEXT_HPP_
00058 #define XIMOL_CONTEXT_HPP_
00059
00060 #include <ximol/xml/attributes.hpp>
00061
00062 #include <list>
00063
00064
00065 XIMOL_XML_BEGIN_NAMESPACE
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 class XIMOL_EXPORT context
00079 {
00080 public:
00081
00082 struct XIMOL_EXPORT notation_decl_type
00083 {
00084 xstring system_literal_;
00085 xstring pubid_literal_;
00086 };
00087
00088
00089 struct XIMOL_EXPORT pe_def_type
00090 {
00091 xstring entity_value;
00092 xstring system_literal_;
00093 xstring pubid_literal_;
00094 };
00095
00096
00097 struct XIMOL_EXPORT entity_def_type
00098 {
00099 xstring entity_value;
00100 xstring system_literal_;
00101 xstring pubid_literal_;
00102 xstring name_;
00103 };
00104
00105
00106
00107 struct XIMOL_EXPORT level
00108 {
00109 xstring tag_;
00110 xstring uri_tag_;
00111 bool is_open_stag;
00112 bool is_open_etag;
00113 XIMOL_XML_NAMESPACE_PATH::attributes att_;
00114 };
00115
00116 typedef class XIMOL_EXPORT ::std::map<xstring,xstring> map_type;
00117 typedef class XIMOL_EXPORT ::std::map<xstring,entity_def_type> entity_def_map_type;
00118 typedef class XIMOL_EXPORT ::std::map<xstring,pe_def_type> pe_def_map_type;
00119 typedef class XIMOL_EXPORT ::std::map<xstring,notation_decl_type> notation_decl_map_type;
00120 typedef class XIMOL_EXPORT ::std::list<level> levels_type;
00121 typedef class XIMOL_EXPORT ::std::map<xstring,void*> key_map_type;
00122
00123 public:
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 context();
00134
00135
00136
00137 bool add_entity(const xstring& entity_name, const xstring& entity_value, const xstring& system_literal = L"", const xstring& pubid_literal = L"", const xstring& ndata_name = L"");
00138 bool add_paramter_entity(const xstring& entity_name, const xstring& entity_value, const xstring& system_literal = L"", const xstring& pubid_literal = L"");
00139 bool add_notation_decl(const xstring& name, const xstring& system_literal, const xstring& pubid_literal);
00140 bool add_processing_instruction(const xstring& pi_target, const xstring& value);
00141
00142
00143
00144
00145 const xstring& get_entity (const xstring& entity_name) const;
00146 const xstring& get_parameter_entity (const xstring& entity_name) const;
00147 const notation_decl_type& get_notation_decl (const xstring& name) const;
00148 const xstring& get_processing_instruction(const xstring& pi_target) const;
00149 const xstring& get_version_num () const;
00150 bool get_sd_decl () const;
00151 const xstring& get_encoding_decl () const;
00152
00153
00154
00155
00156 void set_version_num (const xstring& ver);
00157 void set_sd_decl (bool sddecl);
00158 void set_encoding_decl(const xstring& encoding_name);
00159
00160
00161
00162
00163 context& add_new_level(const xstring& uri, const xstring &tag, const XIMOL_XML_NAMESPACE_PATH::attributes& att, bool open_start=false, bool open_end=false);
00164 context& destroy_level();
00165 bool is_open_stag() const;
00166 bool is_open_etag() const;
00167 context& close_open_stag();
00168 context& close_open_etag();
00169 context& set_open_stag();
00170 context& set_open_etag();
00171 const xstring & get_level_tag() const;
00172 const xstring & get_level_ns_tag() const;
00173 const xstring & get_level_short_ns_tag() const;
00174 const XIMOL_XML_NAMESPACE_PATH::attributes & get_level_attributes() const;
00175 XIMOL_XML_NAMESPACE_PATH::attributes get_attributes() const;
00176 int get_depth() const;
00177 context& add_level_attributes(const XIMOL_XML_NAMESPACE_PATH::attributes & att);
00178
00179 const xstring& get_namespace(const xstring &short_ns) const;
00180 const xstring& get_short_namespace(const xstring &uri) const;
00181 const xstring& get_default_namespace() const;
00182
00183
00184
00185
00186 const xstring & get_doc_type_name() const;
00187 void set_doc_type_name(const xstring& name);
00188 const notation_decl_type & get_doctype_external_id() const;
00189 void set_doctype_external_id(const xstring& system_literal, const xstring& pubid_literal);
00190
00191
00192
00193
00194 template<class T>
00195 bool set_id(const xstring & key, T* t)
00196 {
00197 if (key_map_.find(key)!=key_map_.end()) return false;
00198 key_map_[key]=(void*)t;
00199 return true;
00200 };
00201
00202 template<class T>
00203 bool get_id(const xstring & key, T* t)
00204 {
00205 key_map_type::const_iterator i(key_map_.find(key));
00206 if (i==key_map_.end()) return false;
00207 t=dynamic_cast<T*>((*i).second);
00208 return (t!=NULL);
00209 };
00210
00211
00212 private:
00213 entity_def_map_type entities_;
00214 pe_def_map_type parameter_entities_;
00215 map_type processing_instructions_;
00216 notation_decl_map_type notations_decl_;
00217 xstring version_num_;
00218 bool standalone_decl_;
00219 xstring encoding_decl_;
00220 levels_type levels_;
00221 xstring doctype_name_;
00222 notation_decl_type doctype_external_id_;
00223 key_map_type key_map_;
00224
00225 };
00226
00227 XIMOL_XML_END_NAMESPACE
00228
00229
00230 #endif // #ifndef XIMOL_CONTEXT_H