ximol/xml/cdata.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 cdata Interface.
00024         
00025         \author Tournois Florent
00026         \version 1.0
00027 
00028     $Id: cdata.hpp,v 1.7 2004/02/25 18:59:13 tournois Exp $
00029     $Log: cdata.hpp,v $
00030     Revision 1.7  2004/02/25 18:59:13  tournois
00031     imporve the gcc compatibility.
00032 
00033     Revision 1.6  2004/02/22 10:27:34  tournois
00034     Add some doc.
00035 
00036     Revision 1.5  2004/02/22 09:54:21  tournois
00037     Change years on the copyright.
00038 
00039     Revision 1.4  2004/01/29 20:52:35  tournois
00040     doc and tutorial.
00041 
00042     Revision 1.3  2004/01/19 20:40:55  tournois
00043     Add min, max and digits facet.
00044     Create the control flow file.
00045 
00046     Revision 1.2  2004/01/08 20:02:30  tournois
00047     Add XIMOL_XML_NAMESPACE_PATH::comment and assignment mainuplator.
00048 
00049     Revision 1.1  2004/01/07 21:13:10  tournois
00050     no message
00051 
00052 
00053   */
00054 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00055 #ifndef XIMOL_XML_CDATA_HPP_
00056 #define XIMOL_XML_CDATA_HPP_
00057 
00058 #include <ximol/parser/utils.hpp>
00059 #include <ximol/assignment.hpp>
00060 #include <ximol/str_cast.hpp>
00061 
00062 XIMOL_XML_BEGIN_NAMESPACE
00063 
00064 //=============================================================================
00065 /// class for the qualified name
00066 //=============================================================================
00067 template < typename T >
00068 class manipulator_cdata
00069 {
00070 public:
00071     typedef T object_type;
00072 
00073 public:
00074     manipulator_cdata(object_type & x)
00075         :x_(x)
00076     {};
00077 
00078     manipulator_cdata(const manipulator_cdata<T> & x)
00079         :x_(x.x_)
00080     {};
00081 
00082     void set(const object_type & x)
00083     {
00084         assignment_std::equality(x_, x);
00085     };
00086 
00087     void set_string(const xstring & xstr)
00088     {
00089         assignment_char_serialization::equality(x_, xstr);
00090     };
00091 
00092     const object_type & get() const
00093     {
00094         return x_;
00095     };
00096 
00097     xstring get_string() const
00098     {
00099         return str<std::wstring>::cast(x_);
00100     };
00101 
00102 private:
00103     const manipulator_cdata<T> & operator=(const manipulator_cdata<T> & x);
00104 
00105 private:
00106     object_type & x_;
00107 
00108 }; // end of class manipulator_cdata<T>
00109 
00110 //-----------------------------------------------------------------------------
00111 // PutTo operator for the cdata.
00112 //-----------------------------------------------------------------------------
00113 template < typename T >
00114 xostream& operator<<(xostream& xos, const manipulator_cdata<T>& m)
00115 {
00116         XIMOL_PARSER_USING_NAMESPACE;
00117     write_cd_sect(xos,m.get_string());
00118         return xos;
00119 };
00120 
00121 //-----------------------------------------------------------------------------
00122 // PutTo operator for the cdata.
00123 //-----------------------------------------------------------------------------
00124 template < typename T >
00125 xistream& operator>>(xistream& xis, manipulator_cdata<T>& m)
00126 {
00127         XIMOL_PARSER_USING_NAMESPACE;
00128     xstring xstr;
00129     read_cd_sect(xis,xstr);
00130     m.set_string(xstr);
00131         return xis;
00132 };
00133 
00134 template < typename T > manipulator_cdata<T> cdata( T & t) 
00135 { 
00136     return manipulator_cdata<T>(t); 
00137 };
00138 
00139 /// Start the CDATA section.
00140 /** @ingroup xml */
00141 XIMOL_EXPORT
00142 xostream& cdata_start(xostream& xos);
00143 
00144 /// Start the CDATA section.
00145 /** @ingroup xml */
00146 XIMOL_EXPORT
00147 xistream& cdata_start(xistream& xis);
00148 
00149 /// Finish the CDATA section.
00150 /** @ingroup xml */
00151 XIMOL_EXPORT
00152 xostream& cdata_end(xostream& xos);
00153 
00154 /// Finish the CDATA section.
00155 /** @ingroup xml */
00156 XIMOL_EXPORT
00157 xistream& cdata_end(xistream& xis);
00158 
00159 XIMOL_XML_END_NAMESPACE
00160 
00161 #endif // #ifndef XIMOL_XML_CDATA_HPP_


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