Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

XercesStringConverter.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------*
00002  | Library QgarLib, graphics analysis and recognition                  |
00003  | Copyright (C) 2003  Qgar Project, LORIA                             |
00004  |                                                                     |
00005  | This library is free software; you can redistribute it and/or       |
00006  | modify it under the terms of the GNU Lesser General Public          |
00007  | License version 2.1, as published by the Free Software Foundation.  |
00008  |                                                                     |
00009  | This library is distributed in the hope that it will be useful,     |
00010  | but WITHOUT ANY WARRANTY; without even the implied warranty of      |
00011  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                |
00012  | See the GNU Lesser General Public License for more details.         |
00013  |                                                                     |
00014  | The GNU Lesser General Public License is included in the file       |
00015  | LICENSE.LGPL, in the root directory of the Qgar packaging. See      |
00016  | http://www.gnu.org/licenses/lgpl.html for the terms of the license. |
00017  | To receive a paper copy, write to the Free Software Foundation,     |
00018  | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.       |
00019  |                                                                     |
00020  | Contact Project Qgar for any information:                           |
00021  |   LORIA - équipe Qgar                                               |
00022  |   B.P. 239, 54506 Vandoeuvre-lès-Nancy Cedex, France                |
00023  |   email: qgar-contact@loria.fr                                      |
00024  |   http://www.qgar.org/                                              |
00025  *---------------------------------------------------------------------*/
00026 
00027 
00028 #ifndef __XERCESSTRINGCONVERTER_H_INCLUDED__
00029 #define __XERCESSTRINGCONVERTER_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file     XercesStringConverter.H
00034  * @brief    Header file of class qgxml::XercesStringConverter
00035  *
00036  * @author   <a href="mailto:qgar-contact@loria.fr?subject=Qgar fwd Jan Rendek">Jan Rendek</a>
00037  * @date     March 28, 2003  11:27
00038  * @since    Qgar 2.1
00039  */
00040 
00041 
00042 // For RCS/CVS use: Do not delete
00043 /* $Id: XercesStringConverter.H,v 1.1 2003/04/29 13:25:10 rendek Exp $ */
00044 
00045 
00046 // STD
00047 #include <string>
00048 
00049 // XERCES
00050 #include <xercesc/util/XMLString.hpp>
00051 
00052 namespace qgxml {
00053 
00054 class XercesStr {
00055 
00056 public:  
00057   
00058   XercesStr(XMLCh * str) : _str(str)
00059   { /* NOP */ }
00060 
00061   XercesStr(const XercesStr& rhs) 
00062   {
00063     _str = xercesc::XMLString::replicate(rhs._str);
00064   }
00065 
00066   ~XercesStr() 
00067   { 
00068     xercesc::XMLString::release(&_str); 
00069   }
00070 
00071   operator XMLCh*() { 
00072     return _str; 
00073   }
00074 
00075 private:
00076   XMLCh * _str;
00077 
00078   XercesStr& operator=(const XercesStr&);
00079 };
00080 
00081 
00082 /**
00083  * @class XercesStringConverter XercesStringConverter.H
00084  *
00085  * @todo Comment this class!
00086  * 
00087  * @author <a href="mailto:qgar-contact@loria.fr?subject=Qgar fwd Jan Rendek">Jan Rendek</a>
00088  * @date   March 28, 2003  11:27
00089  * @since  Qgar 2.1
00090  */
00091 class XercesStringConverter {
00092 
00093 // -------------------------------------------------------------------
00094 // P U B L I C    M E M B E R S
00095 // -------------------------------------------------------------------
00096 public:
00097 
00098   // ----------------------------------------------------
00099   // USING DEFAULT CONSTRUCTORS, DESTRUCTOR AND OPERATOR.
00100   // ----------------------------------------------------
00101 
00102 
00103   static std::string convert(const XMLCh * xString) 
00104   {
00105     if (xString) {
00106 
00107       // Convert string.
00108       char * s =  xercesc::XMLString::transcode(xString);
00109       std::string retval(s);
00110 
00111       // Cleanup
00112       xercesc::XMLString::release(&s);      
00113 
00114       return retval;
00115     }
00116 
00117     else {
00118 
00119       return std::string("");
00120     }    
00121   }
00122 
00123 // -------------------------------------------------------------------
00124 
00125   static XercesStr convert(const std::string& stlString) 
00126   {
00127     return XercesStr(xercesc::XMLString::transcode(stlString.c_str()));
00128   }
00129 
00130 // -------------------------------------------------------------------
00131 
00132   std::string operator()(const XMLCh * xString)
00133   {
00134     return convert(xString);
00135   }
00136   
00137 // -------------------------------------------------------------------
00138 
00139   XercesStr operator()(const std::string& stlString)
00140   {
00141     return convert(stlString);
00142   }
00143 
00144 // -------------------------------------------------------------------
00145 
00146 }; // class XercesStringConverter
00147 
00148 } // namespace qgxml
00149 
00150 
00151 #endif /* __XERCESSTRINGCONVERTER_H_INCLUDED__ */