ximol/xml/xml_decl.hpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002  *                                                                           *
00003  * library XiMoL                                                             *
00004  * Copyright (C) 2002, 2003, 2004 Florent Tournois                           *
00005  *                                                                           *
00006  * This library is free software; you can redistribute it and/or             *
00007  * modify it under the terms of the GNU Lesser General Public                *
00008  * License as published by the Free Software Foundation; either              *
00009  * version 2.1 of the License, or (at your option) any later version.        *
00010  *                                                                           *
00011  * This library is distributed in the hope that it will be useful,           *
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00014  * Lesser General Public License for more details.                           *
00015  *                                                                           *
00016  * You should have received a copy of the GNU Lesser General Public          *
00017  * License along with this library; if not, write to the Free Software       *
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   *
00019  *                                                                           *
00020 \*****************************************************************************/
00021 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00022 /** \file 
00023         \brief Define xml_decl Interface.
00024         
00025         \author Tournois Florent
00026         \version 1.0
00027 
00028     $Id: xml_decl.hpp,v 1.8 2004/02/25 18:59:13 tournois Exp $
00029     $Log: xml_decl.hpp,v $
00030     Revision 1.8  2004/02/25 18:59:13  tournois
00031     imporve the gcc compatibility.
00032 
00033     Revision 1.7  2004/02/22 10:27:34  tournois
00034     Add some doc.
00035 
00036     Revision 1.6  2004/02/22 09:54:21  tournois
00037     Change years on the copyright.
00038 
00039     Revision 1.5  2004/01/19 20:40:56  tournois
00040     Add min, max and digits facet.
00041     Create the control flow file.
00042 
00043     Revision 1.4  2004/01/18 11:40:58  tournois
00044     Add the pattern facet.
00045 
00046     Revision 1.3  2004/01/08 20:02:30  tournois
00047     Add XIMOL_XML_NAMESPACE_PATH::comment and assignment mainuplator.
00048 
00049     Revision 1.2  2004/01/07 12:16:36  tournois
00050     no message
00051 
00052     Revision 1.1  2004/01/06 21:04:10  tournois
00053     no message
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 /// class for the qualified name
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 }; // end of class xml_declaration<VersionInfo,EncodingDecl,SDDecl>
00146 
00147 //-----------------------------------------------------------------------------
00148 // PutTo operator for the xml declaration.
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 // PutTo operator for the stag.
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 // PutTo operator for the xml declaration.
00232 //-----------------------------------------------------------------------------
00233 XIMOL_EXPORT xostream& operator<<(xostream& xos, const xml_declaration_alone&);
00234 
00235 //-----------------------------------------------------------------------------
00236 // PutTo operator for the stag.
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_


Donate to the XiMoL project SourceForge.net Logo If you have any questions about XiMoL, you could write to tournois@users.sourceforge.net.