ximol/qname.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 qualified name (declaration).
00024 
00025         \author Tournois Florent
00026         \version 1.0
00027 
00028     $Id: qname.hpp,v 1.17 2004/02/22 10:27:32 tournois Exp $
00029     $Log: qname.hpp,v $
00030     Revision 1.17  2004/02/22 10:27:32  tournois
00031     Add some doc.
00032 
00033     Revision 1.16  2004/02/22 09:54:19  tournois
00034     Change years on the copyright.
00035 
00036     Revision 1.15  2004/02/21 20:03:58  tournois
00037     Change the stag, etag, open_stag, box and rebox template with macro.
00038 
00039     Revision 1.14  2004/01/19 20:40:55  tournois
00040     Add min, max and digits facet.
00041     Create the control flow file.
00042 
00043     Revision 1.13  2004/01/18 11:40:58  tournois
00044     Add the pattern facet.
00045 
00046     Revision 1.12  2004/01/08 20:02:29  tournois
00047     Add XIMOL_XML_NAMESPACE_PATH::comment and assignment mainuplator.
00048 
00049     Revision 1.11  2004/01/07 21:13:10  tournois
00050     no message
00051 
00052     Revision 1.10  2004/01/06 21:04:10  tournois
00053     no message
00054 
00055     Revision 1.9  2003/12/10 20:32:18  tournois
00056     Fix somes bugs about attributes and now tests are all check.
00057 
00058     Revision 1.8  2003/12/09 19:57:27  tournois
00059     Fix some bugs about attributes classes.
00060 
00061     Revision 1.7  2003/12/03 12:59:34  hfp
00062     include dependencies and type forwarding
00063 
00064     Revision 1.6  2003/11/27 15:31:55  hfp
00065     partially adapted to vc6.
00066 
00067     Revision 1.5  2003/11/19 20:52:54  tournois
00068     Add new manipulator for stag and etag.
00069     Correct bugs and add tests.
00070 
00071     Revision 1.4  2003/11/18 18:54:51  tournois
00072     Add str_cast and drop the transformation.hpp file.
00073 
00074     Revision 1.3  2003/11/16 13:25:25  tournois
00075     Change the error to use wide string.
00076     Change the translation to use wide string.
00077 
00078     Revision 1.2  2003/11/14 11:45:04  tournois
00079     First try for the stag.
00080 
00081     Revision 1.1  2003/11/13 20:38:48  tournois
00082     no message
00083 
00084 
00085   */
00086 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00087 #ifndef XIMOL_QNAME_HPP_
00088 #define XIMOL_QNAME_HPP_
00089 
00090 #include <ximol/error.hpp>
00091 #include <ximol/typedefs.hpp>
00092 #include <ximol/translation.hpp>
00093 #include <ximol/str_cast.hpp>
00094 #include <ximol/assignment.hpp>
00095 
00096 XIMOL_BEGIN_NAMESPACE
00097 
00098 //=============================================================================
00099 /// class for the qualified name
00100 //=============================================================================
00101 template < typename Prefix, typename Local >
00102 class qualified_name
00103 {
00104 public:
00105     typedef Prefix prefix_type;
00106     typedef Local  local_type;
00107 
00108 public:
00109     qualified_name( prefix_type & prefix, local_type & local )
00110         :prefix_(&prefix)
00111         ,local_(local)
00112     {};
00113 
00114     qualified_name(local_type & local )
00115         :prefix_(NULL)
00116         ,local_(local)
00117     {};
00118 
00119     qualified_name(const qualified_name<Prefix, Local> & x)
00120         :prefix_(x.prefix_)
00121         ,local_(x.local_)
00122     {};
00123 
00124     template < typename T >
00125     void set_local(const T & local)
00126     {
00127         assignment_to_string::equality(local_, local);
00128     };
00129 
00130     xstring get_local() const { return str< ::std::wstring>::cast(local_); };
00131 
00132     template < typename T >
00133     void set_prefix(const T & prefix)
00134     {
00135         if (prefix_==NULL) 
00136             XIMOL_THROW << _(L"The prefix could not be set") << XIMOL_AS_ERROR; 
00137         assignment_to_string::equality(*prefix_, prefix);
00138     };
00139 
00140     bool is_prefix_set() const { return prefix_!=NULL; }; 
00141     xstring get_prefix() const { return str< ::std::wstring>::cast(*prefix_); };
00142 
00143 private:
00144     const qualified_name<Prefix, Local> & operator=(const qualified_name<Prefix, Local> & x);
00145 
00146 private:
00147     prefix_type * prefix_;
00148     local_type & local_;
00149 }; // end of class qualified_name<Uri,Name>
00150 
00151 template < typename T, typename U >
00152 qualified_name<T,U> qname(T & prefix, U & local)
00153 {
00154     return qualified_name<T,U>(prefix,local);
00155 };
00156 
00157 template < typename T>
00158 qualified_name<T,T> qname(T & local)
00159 {
00160     return qualified_name<T,T>(local);
00161 };
00162 
00163 XIMOL_END_NAMESPACE
00164 
00165 #endif // #ifndef XIMOL_QNAME_HPP_


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