ximol/xml/context.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 the XML context. .
00024         @ingroup xml
00025 
00026         \author Tournois Florent
00027         \version 1.0
00028 
00029     $Id: context.hpp,v 1.7 2004/02/22 10:27:34 tournois Exp $
00030     $Log: context.hpp,v $
00031     Revision 1.7  2004/02/22 10:27:34  tournois
00032     Add some doc.
00033 
00034     Revision 1.6  2004/02/22 09:54:21  tournois
00035     Change years on the copyright.
00036 
00037     Revision 1.5  2004/01/29 20:52:35  tournois
00038     doc and tutorial.
00039 
00040     Revision 1.4  2003/11/16 11:03:35  tournois
00041     no message
00042 
00043     Revision 1.3  2003/11/02 19:23:01  tournois
00044     Go to the boost coding standard.
00045     Change all name to lower case.
00046 
00047     Revision 1.2  2003/10/25 13:53:40  hfp
00048     review and separation
00049 
00050     Revision 1.1  2003/09/24 08:28:18  tournois
00051     Create the namespace Encoders, Parser, Xml
00052     Change the library organization.
00053     add VC7.1 project for this organization.
00054 
00055   */
00056 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00057 #ifndef XIMOL_CONTEXT_HPP_
00058 #define XIMOL_CONTEXT_HPP_
00059 
00060 #include <ximol/xml/attributes.hpp>
00061 
00062 #include <list>
00063 
00064 
00065 XIMOL_XML_BEGIN_NAMESPACE
00066 
00067 //=============================================================================
00068 /// Class context.
00069 /** @ingroup interface parser
00070 
00071         This class contain all information about reding and write XML.
00072         Entity and parameter entity are saved in this class.
00073 
00074         \author Tournois Florent.
00075         \todo this class must be commented.
00076   */
00077 //=============================================================================
00078 class XIMOL_EXPORT context
00079 {
00080         public:
00081                 /// Small struct for Notation Declartion.
00082                 struct XIMOL_EXPORT notation_decl_type
00083                 {
00084                         xstring system_literal_;
00085                         xstring pubid_literal_;
00086                 }; // end of struct notation_decl_type
00087 
00088                 /// Small struct for Parameter Entity Declartion.
00089                 struct XIMOL_EXPORT pe_def_type
00090                 {
00091                         xstring entity_value;
00092                         xstring system_literal_;
00093                         xstring pubid_literal_;
00094                 }; // end of struct Parameter Entity Declartion
00095 
00096                 /// Small struct for Entity Definition.
00097                 struct XIMOL_EXPORT entity_def_type
00098                 {
00099                         xstring entity_value;
00100                         xstring system_literal_;
00101                         xstring pubid_literal_;
00102                         xstring name_;
00103                 }; // end of struct Entity Definition
00104 
00105 
00106                 /// struct to save information about the XML level.
00107                 struct XIMOL_EXPORT level
00108                 {
00109                         xstring tag_;        ///<name fo the tag.
00110                         xstring uri_tag_;
00111                         bool           is_open_stag;  ///<Test if the tag is still open.
00112                         bool           is_open_etag;  ///<Test if the tag is still open.
00113                         XIMOL_XML_NAMESPACE_PATH::attributes att_;         ///<attributes of this level.
00114                 }; // End of class level.
00115 
00116                 typedef class XIMOL_EXPORT ::std::map<xstring,xstring>          map_type;
00117                 typedef class XIMOL_EXPORT ::std::map<xstring,entity_def_type>    entity_def_map_type;
00118                 typedef class XIMOL_EXPORT ::std::map<xstring,pe_def_type>        pe_def_map_type;
00119                 typedef class XIMOL_EXPORT ::std::map<xstring,notation_decl_type> notation_decl_map_type;
00120                 typedef class XIMOL_EXPORT ::std::list<level>                   levels_type;
00121                 typedef class XIMOL_EXPORT ::std::map<xstring,void*>            key_map_type;
00122 
00123         public:
00124                 /// add some predefined entities
00125                 /** <pre>
00126                         <!ENTITY lt     "&#38;#60;">
00127             <!ENTITY gt     "&#62;">
00128             <!ENTITY amp    "&#38;#38;">
00129             <!ENTITY apos   "&#39;">
00130             <!ENTITY quot   "&#34;">
00131                         </pre>
00132           */
00133                 context();
00134 
00135                 ///@name add functions
00136                 //@{
00137                 bool add_entity(const xstring& entity_name, const xstring& entity_value, const xstring& system_literal = L"", const xstring& pubid_literal = L"", const xstring& ndata_name = L"");
00138                 bool add_paramter_entity(const xstring& entity_name, const xstring& entity_value, const xstring& system_literal = L"", const xstring& pubid_literal = L"");
00139                 bool add_notation_decl(const xstring& name, const xstring& system_literal, const xstring& pubid_literal);
00140                 bool add_processing_instruction(const xstring& pi_target, const xstring& value);
00141                 //@}
00142 
00143                 ///@name Get functions
00144                 //@{
00145                 const xstring&          get_entity               (const xstring& entity_name) const;
00146                 const xstring&          get_parameter_entity      (const xstring& entity_name) const;
00147                 const notation_decl_type& get_notation_decl         (const xstring& name) const;
00148                 const xstring&          get_processing_instruction(const xstring& pi_target) const;
00149                 const xstring&          get_version_num           () const;
00150                 bool                    get_sd_decl               () const;
00151                 const xstring&          get_encoding_decl         () const;
00152                 //@}
00153 
00154                 ///@name Set functions
00155                 //@{
00156                 void set_version_num  (const xstring& ver);
00157                 void set_sd_decl      (bool           sddecl);
00158                 void set_encoding_decl(const xstring& encoding_name);
00159                 //@}
00160 
00161                 ///\name level functions
00162                 //@{
00163                 context& add_new_level(const xstring& uri, const xstring &tag, const XIMOL_XML_NAMESPACE_PATH::attributes& att, bool open_start=false, bool open_end=false);
00164                 context& destroy_level();
00165                 bool is_open_stag() const;
00166                 bool is_open_etag() const;
00167                 context& close_open_stag();
00168                 context& close_open_etag();
00169                 context& set_open_stag();
00170                 context& set_open_etag();
00171                 const xstring & get_level_tag() const;
00172                 const xstring & get_level_ns_tag() const;
00173                 const xstring & get_level_short_ns_tag() const;
00174                 const XIMOL_XML_NAMESPACE_PATH::attributes & get_level_attributes() const;
00175                 XIMOL_XML_NAMESPACE_PATH::attributes get_attributes() const;
00176                 int get_depth() const;
00177                 context& add_level_attributes(const XIMOL_XML_NAMESPACE_PATH::attributes & att);
00178 
00179                 const xstring& get_namespace(const xstring &short_ns) const;
00180                 const xstring& get_short_namespace(const xstring &uri) const;
00181                 const xstring& get_default_namespace() const;
00182                 //@}
00183 
00184                 ///\name doctype functions.
00185                 //@{
00186                 const xstring &          get_doc_type_name() const;
00187                 void                     set_doc_type_name(const xstring& name);
00188                 const notation_decl_type & get_doctype_external_id() const;
00189                 void                     set_doctype_external_id(const xstring& system_literal, const xstring& pubid_literal);
00190                 //@}
00191 
00192                 ///\name keyType functions.
00193                 //@{
00194                 template<class T>
00195                 bool set_id(const xstring & key, T* t)
00196                 {
00197                         if (key_map_.find(key)!=key_map_.end()) return false;
00198                         key_map_[key]=(void*)t;
00199                         return true;
00200                 };
00201 
00202                 template<class T>
00203                 bool get_id(const xstring & key, T* t)
00204                 {
00205                         key_map_type::const_iterator i(key_map_.find(key));
00206                         if (i==key_map_.end()) return false;
00207                         t=dynamic_cast<T*>((*i).second);
00208                         return (t!=NULL);
00209                 };
00210                 //@}
00211 
00212         private:
00213                 entity_def_map_type    entities_;               ///<Map entities <-> values
00214                 pe_def_map_type        parameter_entities_;      ///<Map PEntities <-> values
00215                 map_type             processing_instructions_; ///<Map PI <-> values
00216                 notation_decl_map_type notations_decl_;          ///<Map Notations <-> values
00217                 xstring                         version_num_;             ///<Version number of the doc
00218                 bool                            standalone_decl_;         ///<SDDL of the doc
00219                 xstring                         encoding_decl_;           ///<encoding of the doc
00220                 levels_type          levels_;                 ///<All level open
00221                 xstring                         doctype_name_;
00222                 notation_decl_type    doctype_external_id_;
00223                 key_map_type          key_map_;
00224 
00225 }; // end of class context
00226 
00227 XIMOL_XML_END_NAMESPACE
00228 
00229 
00230 #endif // #ifndef XIMOL_CONTEXT_H


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