ximol/xml/stag.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 stag Interface.
00024         
00025         \author Tournois Florent
00026         \version 1.0
00027 
00028     $Id: stag.hpp,v 1.17 2004/03/19 18:28:39 tournois Exp $
00029     $Log: stag.hpp,v $
00030     Revision 1.17  2004/03/19 18:28:39  tournois
00031     packaging for the version 0.8
00032 
00033     Revision 1.16  2004/03/04 18:45:29  tournois
00034     Compatibility with gcc.
00035 
00036     Revision 1.15  2004/03/03 22:05:30  tournois
00037     Add a short roadmap.
00038     Add BOOST_NO_STD_WSTRING for gcc.
00039 
00040     Revision 1.14  2004/02/25 18:59:13  tournois
00041     imporve the gcc compatibility.
00042 
00043     Revision 1.13  2004/02/22 10:27:34  tournois
00044     Add some doc.
00045 
00046     Revision 1.12  2004/02/22 09:54:21  tournois
00047     Change years on the copyright.
00048 
00049     Revision 1.11  2004/02/21 20:03:58  tournois
00050     Change the stag, etag, open_stag, box and rebox template with macro.
00051 
00052     Revision 1.10  2004/02/09 12:41:25  tournois
00053     Fix bug about error message.
00054     Add a read_optionnal_space before the stag read.
00055 
00056     Revision 1.9  2004/01/27 21:49:52  tournois
00057     Add docs and tutorial.
00058 
00059     Revision 1.8  2004/01/25 17:33:09  tournois
00060     no message
00061 
00062     Revision 1.7  2004/01/15 21:26:01  tournois
00063     no message
00064 
00065     Revision 1.6  2004/01/09 18:26:29  tournois
00066     Add box and content manipulator.
00067 
00068     Revision 1.5  2003/12/10 20:32:18  tournois
00069     Fix somes bugs about attributes and now tests are all check.
00070 
00071     Revision 1.4  2003/12/09 19:57:28  tournois
00072     Fix some bugs about attributes classes.
00073 
00074     Revision 1.3  2003/12/03 12:50:37  hfp
00075     include dependencies and type forwarding
00076 
00077     Revision 1.2  2003/11/27 15:31:55  hfp
00078     partially adapted to vc6.
00079 
00080     Revision 1.1  2003/11/19 20:52:54  tournois
00081     Add new manipulator for stag and etag.
00082     Correct bugs and add tests.
00083 
00084 
00085   */
00086 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00087 #ifndef XIMOL_XML_STAG_HPP_
00088 #define XIMOL_XML_STAG_HPP_
00089 
00090 #include <ximol/qname.hpp>
00091 #include <ximol/parser/utils.hpp>
00092 
00093 
00094 XIMOL_XML_BEGIN_NAMESPACE
00095 
00096 //=============================================================================
00097 /// Manipulator for the start tag.
00098 //=============================================================================
00099 template < typename Qname, typename Attributes >
00100 struct manipulator_stag
00101 {
00102     manipulator_stag(Qname qname):qname_(new Qname(qname)),att_(NULL){};
00103     manipulator_stag(Qname qname, Attributes & att):qname_(new Qname(qname)),att_(&att){};
00104     manipulator_stag(const manipulator_stag<Qname, Attributes> & x):qname_(new Qname(*x.qname_)),att_(x.att_){};
00105     ~manipulator_stag(){ delete qname_; };
00106 
00107     Qname * qname_;
00108     Attributes * att_;
00109 private:
00110     manipulator_stag<Qname, Attributes> & operator=(const manipulator_stag<Qname, Attributes> & x);
00111 };
00112 
00113 //-----------------------------------------------------------------------------
00114 // PutTo operator for the stag.
00115 //-----------------------------------------------------------------------------
00116 template < typename Qname, typename Attributes >
00117 xostream& operator<<(xostream& xos, const manipulator_stag<Qname,Attributes>& m)
00118 {
00119         XIMOL_PARSER_USING_NAMESPACE;
00120     if (m.att_==NULL) {
00121         if (m.qname_->is_prefix_set())
00122             write_stag(xos,m.qname_->get_local(),m.qname_->get_prefix());
00123         else 
00124             write_stag(xos,m.qname_->get_local());
00125     } else {
00126         if (m.qname_->is_prefix_set())
00127             write_stag(xos,m.qname_->get_local(),*(m.att_),m.qname_->get_prefix());
00128         else {
00129             write_stag(xos,m.qname_->get_local(),*(m.att_));
00130         };
00131     };
00132         return xos;
00133 };
00134 
00135 //-----------------------------------------------------------------------------
00136 // PutTo operator for the stag.
00137 //-----------------------------------------------------------------------------
00138 template < typename Qname, typename Attributes >
00139 xistream& operator>>(xistream& xis, manipulator_stag<Qname,Attributes> m)
00140 {
00141         XIMOL_PARSER_USING_NAMESPACE;
00142 
00143     if (has_skip_whitespace(xis)) 
00144         read_optionnal_space(xis);
00145 
00146     xstring prefix, local;
00147     bool has_an_open_stag=xis.context.is_open_stag();
00148     if (m.att_==NULL) {
00149         read_stag(xis, local, prefix);
00150     } else {
00151         read_stag(xis, local, *(m.att_), prefix);
00152     };
00153 
00154     try {
00155         m.qname_->set_local(local);
00156     } catch ( std::exception & ) {
00157         if (!has_an_open_stag) throw;
00158     };
00159 
00160     try {
00161         if (m.qname_->is_prefix_set())
00162         {
00163             try {
00164                 m.qname_->set_prefix(prefix);
00165             } catch (std::exception&) {
00166                 m.qname_->set_prefix(xis.context.get_short_namespace(prefix));
00167             };
00168         };
00169     } catch (std::exception&) {
00170         if (!has_an_open_stag) throw;
00171     }; 
00172 
00173         return xis;
00174 };
00175 
00176 //-----------------------------------------------------------------------------
00177 /** Start tag manipulator creator.
00178  * This function create the start tag manipulator with the adjusted type.
00179  * Only the local part of the tag name will be written or read from the stream.
00180  * This manipulator read or write start tag on the stream. The writer does not
00181  * make any problem, but the reader could. If the lement is const, the 
00182  * manipulator only check the equality.
00183  *
00184  * The following code write the start tag on the stream:
00185  * \code
00186  *   xos << xml::stag("tag");
00187  * \code
00188  * If you want to read the tag, you could write:
00189  * \code 
00190  *   std::string tag;
00191  *   xis >> xml::stag(tag);
00192  * \endcode
00193  * The probleme is the wide character conversion, because with this code,
00194  * you could not read the wide character tag. You could also write:
00195  * \code 
00196  *   std::xstring tag;
00197  *   xis >> xml::stag(tag);
00198  * \endcode
00199  * And if you only want to verify the tag, you could write:
00200  * \code
00201  *   xis >> xml::stag("Tag");
00202  * \endcode
00203  * or 
00204  * \code
00205  *   xis >> xml::stag(L"Tag");
00206  * \endcode
00207  *
00208  * requirement: The character of the String1 must be managed by str<T>::cast
00209  *
00210  * You could see examples.
00211  */
00212 //-----------------------------------------------------------------------------
00213 // define all function stag(string1, string2, attributes)
00214 #define XIMOL_HEADER_DEFINE_FUNCTION(type1, type2, type3) \
00215     XIMOL_EXPORT manipulator_stag< qualified_name<type1, type2>, type3> stag(type1 & prefix, type2 & local, type3 & att); 
00216 #include <ximol/config/define_functions_prefix_local_attributes.hpp>
00217 
00218 // define all function stag(string1, string2)
00219 #define XIMOL_HEADER_DEFINE_FUNCTION(type1, type2) \
00220     XIMOL_EXPORT manipulator_stag< qualified_name<type1, type2>, xml::attributes> stag(type1 & prefix, type2 & local); 
00221 #include <ximol/config/define_functions_prefix_local.hpp>
00222 
00223 // define all function stag(string1, attribute)
00224 #define XIMOL_HEADER_DEFINE_FUNCTION(type1, type3) \
00225     XIMOL_EXPORT manipulator_stag< qualified_name<type1, type1>, type3> stag(type1 & local, type3 & att); 
00226 #include <ximol/config/define_functions_local_attributes.hpp>
00227 
00228 // define all function stag(string1)
00229 #define XIMOL_HEADER_DEFINE_FUNCTION(type1) \
00230     XIMOL_EXPORT manipulator_stag< qualified_name<type1, type1>, xml::attributes> stag(type1 & local); 
00231 #include <ximol/config/define_functions_local.hpp>
00232 
00233 XIMOL_XML_END_NAMESPACE
00234 
00235 #endif // #ifndef XIMOL_XML_STAG_HPP_


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