ximol/control_flow.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 control flow (declaration).
00024     @ingroup stream
00025     In this file we group all function to control the xml stream, 
00026     like wait a tag, test the incoming tag, etc. 
00027     
00028         \author Tournois Florent
00029         \version 1.0
00030 
00031     $Id: control_flow.hpp,v 1.13 2004/03/03 22:05:30 tournois Exp $
00032     $Log: control_flow.hpp,v $
00033     Revision 1.13  2004/03/03 22:05:30  tournois
00034     Add a short roadmap.
00035     Add BOOST_NO_STD_WSTRING for gcc.
00036 
00037     Revision 1.12  2004/02/25 15:57:06  tournois
00038     no message
00039 
00040     Revision 1.11  2004/02/22 10:27:32  tournois
00041     Add some doc.
00042 
00043     Revision 1.10  2004/02/22 09:54:19  tournois
00044     Change years on the copyright.
00045 
00046     Revision 1.9  2004/02/09 12:41:25  tournois
00047     Fix bug about error message.
00048     Add a read_optionnal_space before the stag read.
00049 
00050     Revision 1.8  2004/02/02 19:51:44  tournois
00051     Add a control_flow and finish the attribute tutorial.
00052 
00053     Revision 1.7  2004/01/29 20:52:35  tournois
00054     doc and tutorial.
00055 
00056     Revision 1.6  2004/01/27 21:49:51  tournois
00057     Add docs and tutorial.
00058 
00059     Revision 1.5  2004/01/22 22:06:52  tournois
00060     no message
00061 
00062     Revision 1.4  2004/01/21 21:06:41  tournois
00063     no message
00064 
00065     Revision 1.3  2004/01/19 20:40:55  tournois
00066     Add min, max and digits facet.
00067     Create the control flow file.
00068 
00069 
00070   */
00071 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00072 #ifndef XIMOL_CONTROL_FLOW_HPP_
00073 #define XIMOL_CONTROL_FLOW_HPP_
00074 
00075 #include <ximol/namespace_defs.hpp>
00076 #include <ximol/export_defs.hpp>
00077 #include <ximol/stream.hpp>
00078 
00079 XIMOL_BEGIN_NAMESPACE
00080 
00081 //-----------------------------------------------------------------------------
00082 /** Test the flag to eat all white space.
00083  *  Drop first white spaces in the stream before reading stag and etag
00084  *  <pre>
00085  *      S ::= (x20 | x9 | xD | xA) 
00086  *  </pre>
00087  *  
00088  *  @ingroup stream 
00089  *  @param xis the stream
00090  *  @return the test result
00091  */
00092 //-----------------------------------------------------------------------------
00093 XIMOL_EXPORT
00094 bool has_skip_whitespace(xistream& xis);
00095 
00096 //-----------------------------------------------------------------------------
00097 /** Turn on the flag to eat all white space.
00098  *  Drop first white spaces in the stream before reading stag and etag
00099  *  <pre>
00100  *      S ::= (x20 | x9 | xD | xA) 
00101  *  </pre>
00102  *  
00103  *  @ingroup stream 
00104  *  @param xis the stream
00105  *  @return the input stream
00106  */
00107 //-----------------------------------------------------------------------------
00108 XIMOL_EXPORT
00109 xistream& skip_whitespace(xistream& xis);
00110 
00111 //-----------------------------------------------------------------------------
00112 /** Turn off the flag to eat all white space.
00113  *  Drop first white spaces in the stream before reading stag and etag
00114  *  <pre>
00115  *      S ::= (x20 | x9 | xD | xA) 
00116  *  </pre>
00117  *  
00118  *  @ingroup stream 
00119  *  @param xis the stream
00120  *  @return the input stream
00121  */
00122 //-----------------------------------------------------------------------------
00123 XIMOL_EXPORT
00124 xistream& no_skip_whitespace(xistream& xis);
00125 
00126 //-----------------------------------------------------------------------------
00127 /** Eat all white space.
00128  *  Drop first white spaces in the stream. White space are defined by:
00129  *  <pre>
00130  *      S ::= (x20 | x9 | xD | xA) 
00131  *  </pre>
00132  *  
00133  *  @ingroup stream 
00134  *  @param xis the stream
00135  *  @return the input stream
00136  */
00137 //-----------------------------------------------------------------------------
00138 XIMOL_EXPORT
00139 xistream& drop_space(xistream& xis);
00140 
00141 //-----------------------------------------------------------------------------
00142 /** Eat the content until the next end or start tag.
00143  *  @ingroup stream 
00144  *  
00145  *  Following the W3C definition:
00146  *  \code
00147  *      [Definition: The text between the start-tag and end-tag 
00148  *                              is called the element's content:]
00149  *      [content    ::=    CharData? ((element | Reference | CDSect | 
00150  *                                                   PI | Comment) CharData?)* 
00151  *  \endcode
00152  *  This function is really usefull to drop the comment or wait a precise tag. 
00153  *
00154  *  @param xis the stream
00155  *  @return the input stream
00156  */
00157 //-----------------------------------------------------------------------------
00158 XIMOL_EXPORT
00159 xistream& drop_content(xistream& xis);
00160 
00161 //-----------------------------------------------------------------------------
00162 /** Test next element.
00163  *  @ingroup stream 
00164  *  test if the incoming element is a start tag. This function could be use 
00165  *  with the drop_content to do some loop.
00166  *  \code
00167  *    while ((drop_content(xis) && (is_stag(xis)) 
00168  *      ...;
00169  *  \endcode
00170  * 
00171  *  @param xis the stream
00172  *  @return the result of the test
00173  */
00174 //-----------------------------------------------------------------------------
00175 XIMOL_EXPORT
00176 bool is_stag(xistream& xis);
00177 
00178 //-----------------------------------------------------------------------------
00179 /** Test next element.
00180  *  @ingroup stream 
00181  *  test if the incoming element is a start tag. 
00182  *
00183  *  @param xis the stream
00184  *  @return the result of the test
00185  */
00186 //-----------------------------------------------------------------------------
00187 XIMOL_EXPORT
00188 bool is_etag(xistream& xis);
00189 
00190 //-----------------------------------------------------------------------------
00191 /** Drop next element
00192  *  @ingroup stream 
00193  *  This function drop the nest element if the stream is at a start tag.
00194  *  If an element is useless, then it is a good way to drop it.
00195  *
00196  *  @param xis the stream
00197  *  @return the input stream
00198  */
00199 //-----------------------------------------------------------------------------
00200 XIMOL_EXPORT
00201 xistream& drop_next_element(xistream& xis);
00202 
00203 //-----------------------------------------------------------------------------
00204 /** Drop next element
00205  *  @ingroup stream
00206  *  a simple combinaison of function to control the flow. 
00207  *  Here is the equivalent code
00208  *  \code
00209  *    while (drop_content(xis) && is_stag(xis)) drop_next_element(xis);
00210  *  \endcode
00211  *
00212  *  @param xis the stream
00213  *  @return the input stream
00214  */
00215 //-----------------------------------------------------------------------------
00216 XIMOL_EXPORT
00217 xistream& drop_element_until_etag(xistream& xis);
00218 
00219 //-----------------------------------------------------------------------------
00220 /** Wait for a pricise tag at this level.
00221  *  @ingroup stream
00222  *  drop the content and elements until it find an end tag or the tag.
00223  *
00224  *  @param xis the stream
00225  *  @param ns the namespace
00226  *  @param tag the tag
00227  *  @return true if the tag is found false if not.
00228  */
00229 //-----------------------------------------------------------------------------
00230 template < typename String1, typename String2 >
00231 bool wait_stag(xistream& xis, String1 ns, String2 tag)
00232 {
00233     xstring tag_read, ns_read;
00234     xstring real_ns=xis.context.get_short_namespace(ns);
00235     bool ok_find=false;
00236     while ((ok_find==false) && drop_content(xis) && is_stag(xis))
00237     {
00238         xis >> xml::open_stag(ns_read,tag_read);
00239         if((ns_read==str<xstring>::cast(real_ns)) && (tag_read==str<xstring>::cast(tag)))
00240         {
00241             ok_find=true;
00242         } else {
00243             drop_next_element(xis);
00244         };
00245     };
00246     return ok_find;
00247 };
00248 
00249 //-----------------------------------------------------------------------------
00250 /** Wait for a pricise tag at this level.
00251  *  @ingroup stream
00252  *  drop the content and elements until it find an end tag or the tag.
00253  *
00254  *  @param xis the stream
00255  *  @param tag the tag
00256  *  @return true if the tag is found false if not.
00257  */
00258 //-----------------------------------------------------------------------------
00259 template < typename String1 >
00260 bool wait_stag(xistream& xis, String1 tag)
00261 {
00262     xstring tag_read, ns_read;
00263     bool ok_find=false;
00264     while ((ok_find==false) && drop_content(xis) && is_stag(xis))
00265     {
00266         xis >> xml::open_stag(ns_read,tag_read);
00267         if (tag_read==str<xstring>::cast(tag))
00268         {
00269             ok_find=true;
00270         } else {
00271             drop_next_element(xis);
00272         };
00273     };
00274     return ok_find;
00275 };
00276 
00277 XIMOL_END_NAMESPACE
00278 
00279 #endif // #ifndef XIMOL_CONTROL_FLOW_HPP_


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