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
00058 #ifndef XIMOL_XML_XML_DECL_HPP_
00059 #define XIMOL_XML_XML_DECL_HPP_
00060
00061 #include <ximol/assignment.hpp>
00062 #include <ximol/parser/utils.hpp>
00063
00064 XIMOL_XML_BEGIN_NAMESPACE
00065
00066
00067
00068
00069 template < typename VersionInfo, typename EncodingDecl , typename SDDecl >
00070 class xml_declaration
00071 {
00072 public:
00073 typedef VersionInfo version_info_type;
00074 typedef EncodingDecl encoding_decl_type;
00075 typedef SDDecl sddecl_type;
00076
00077 public:
00078 xml_declaration(version_info_type & version_info)
00079 :sddecl_(NULL)
00080 ,encoding_decl_(NULL)
00081 ,version_info_(version_info)
00082 {};
00083
00084 xml_declaration(version_info_type & version_info, encoding_decl_type & encoding_decl)
00085 :sddecl_(NULL)
00086 ,encoding_decl_(&encoding_decl)
00087 ,version_info_(version_info)
00088 {};
00089
00090 xml_declaration(version_info_type & version_info, sddecl_type & sddecl)
00091 :sddecl_(&sddecl)
00092 ,encoding_decl_(NULL)
00093 ,version_info_(version_info)
00094 {};
00095
00096 xml_declaration(version_info_type & version_info, encoding_decl_type & encoding_decl, sddecl_type & sddecl)
00097 :sddecl_(&sddecl)
00098 ,encoding_decl_(&encoding_decl)
00099 ,version_info_(version_info)
00100 {};
00101
00102 xml_declaration(const xml_declaration<VersionInfo,EncodingDecl,SDDecl> & x)
00103 :sddecl_(x.sddecl_)
00104 ,encoding_decl_(x.encoding_decl_)
00105 ,version_info_(x.version_info_)
00106 {};
00107
00108 template < typename T >
00109 void set_version_info(const T & version_info)
00110 {
00111 assignment_to_string::equality(version_info_, version_info);
00112 };
00113
00114 xstring get_version_info() const { return str< ::std::wstring>::cast(version_info_); };
00115
00116 template < typename T >
00117 void set_encoding_decl(const T & encoding_decl)
00118 {
00119 if (encoding_decl_==NULL)
00120 XIMOL_THROW << _(L"The encoding_decl could not be set") << XIMOL_AS_ERROR;
00121 assignment_to_string::equality(*encoding_decl_, encoding_decl);
00122 };
00123
00124 bool is_encoding_decl_set() const { return encoding_decl_!=NULL; };
00125 xstring get_encoding_decl() const { return str< ::std::wstring>::cast(*encoding_decl_); };
00126
00127 void set_sddecl(bool sddecl)
00128 {
00129 if (sddecl_==NULL)
00130 XIMOL_THROW << _(L"The sddecl could not be set") << XIMOL_AS_ERROR;
00131 assignment_std::equality(*sddecl_, sddecl);
00132 };
00133
00134 bool is_sddecl_set() const { return sddecl_!=NULL; };
00135 bool get_sddecl() const { return *sddecl_; };
00136
00137 private:
00138 const xml_declaration<VersionInfo,EncodingDecl,SDDecl> & operator=(const xml_declaration<VersionInfo,EncodingDecl,SDDecl> & x);
00139
00140 private:
00141 sddecl_type * sddecl_;
00142 encoding_decl_type * encoding_decl_;
00143 version_info_type & version_info_;
00144
00145 };
00146
00147
00148
00149
00150 template < typename VersionInfo, typename EncodingDecl , typename SDDecl >
00151 xostream& operator<<(xostream& xos, const xml_declaration<VersionInfo,EncodingDecl,SDDecl>& m)
00152 {
00153 XIMOL_PARSER_USING_NAMESPACE;
00154 if (m.is_sddecl_set()) {
00155 if (m.is_encoding_decl_set())
00156 write_xml_decl(xos,m.get_version_info(), m.get_encoding_decl(), m.get_sddecl() ? L"yes" : L"no");
00157 else
00158 write_xml_decl(xos,m.get_version_info(), L"" , m.get_sddecl() ? L"yes" : L"no");
00159 } else {
00160 if (m.is_encoding_decl_set())
00161 write_xml_decl(xos,m.get_version_info(), m.get_encoding_decl());
00162 else
00163 write_xml_decl(xos,m.get_version_info());
00164 };
00165 return xos;
00166 };
00167
00168
00169
00170
00171 template < typename VersionInfo, typename EncodingDecl , typename SDDecl >
00172 xistream& operator>>(xistream& xis, xml_declaration<VersionInfo,EncodingDecl,SDDecl>& m)
00173 {
00174 XIMOL_PARSER_USING_NAMESPACE;
00175 xstring ver, enc;
00176 bool sd;
00177
00178 read_xml_decl(xis, ver, enc, sd);
00179
00180 m.set_version_info(ver);
00181
00182 if (m.is_encoding_decl_set())
00183 m.set_encoding_decl(enc);
00184
00185 if (m.is_sddecl_set())
00186 m.set_sddecl(sd);
00187
00188 return xis;
00189 };
00190
00191 template < typename VersionInfo, typename EncodingDecl>
00192 xml_declaration<VersionInfo,EncodingDecl,bool> xml_decl(VersionInfo & version_info, EncodingDecl & encoding_decl, bool & sddecl )
00193 {
00194 return xml_declaration<VersionInfo,EncodingDecl,bool>(version_info, encoding_decl, sddecl);
00195 };
00196
00197 template < typename VersionInfo, typename EncodingDecl>
00198 xml_declaration<VersionInfo,EncodingDecl,const bool> xml_decl(VersionInfo & version_info, EncodingDecl & encoding_decl, const bool & sddecl )
00199 {
00200 return xml_declaration<VersionInfo,EncodingDecl,const bool>(version_info, encoding_decl, sddecl);
00201 };
00202
00203 template < typename VersionInfo, typename EncodingDecl>
00204 xml_declaration<VersionInfo,EncodingDecl,bool> xml_decl(VersionInfo & version_info, EncodingDecl & encoding_decl)
00205 {
00206 return xml_declaration<VersionInfo,EncodingDecl,bool>(version_info, encoding_decl);
00207 };
00208
00209 template < typename VersionInfo>
00210 xml_declaration<VersionInfo, const xstring, bool> xml_decl(VersionInfo & version_info, bool & sddecl )
00211 {
00212 return xml_declaration<VersionInfo, const xstring, bool>(version_info, sddecl);
00213 };
00214
00215 template < typename VersionInfo>
00216 xml_declaration<VersionInfo, const xstring, const bool> xml_decl(VersionInfo & version_info, const bool & sddecl )
00217 {
00218 return xml_declaration<VersionInfo, const xstring, const bool>(version_info, sddecl);
00219 };
00220
00221 template < typename VersionInfo>
00222 xml_declaration<VersionInfo, const xstring, const bool> xml_decl(VersionInfo & version_info)
00223 {
00224 return xml_declaration<VersionInfo, const xstring, const bool>(version_info);
00225 };
00226
00227 struct xml_declaration_alone {};
00228 inline xml_declaration_alone xml_decl(){ return xml_declaration_alone(); };
00229
00230
00231
00232
00233 XIMOL_EXPORT xostream& operator<<(xostream& xos, const xml_declaration_alone&);
00234
00235
00236
00237
00238 XIMOL_EXPORT xistream& operator>>(xistream& xis, xml_declaration_alone&);
00239
00240 XIMOL_XML_END_NAMESPACE
00241
00242 #endif // #ifndef XIMOL_XML_XML_DECL_HPP_