Helper-classes.hh

00001 #ifndef HELPER_CLASSES_H
00002 #define HELPER_CLASSES_H
00003 
00004 /*
00005 This file is part of the sample code for the article,
00006 "Processing XML with Xerces and SAX" by Ethan McCallum (2005/11/10)
00007 
00008 Published on ONLamp.com (http://www.onlamp.com/)
00009 http://www.onlamp.com/pub/a/onlamp/2005/11/10/xerces_sax.html
00010 */
00011 
00012 /*
00013 Misc utility classes and routines for using Xerces-C++
00014 */
00015 
00016 
00017 // = = = = = = = = = = = = = = = = = = = =
00018 
00019 #include <algorithm>
00020 #include <functional>
00021 #include <iterator>
00022 
00023 #include <xercesc/util/XMLString.hpp>
00024 
00034 struct FreeXercesString {
00035 
00036     static void releaseXMLString( XMLCh* str ) {
00037         xercesc::XMLString::release( &str ) ;
00038         return ;
00039     }
00040 
00041     static void releaseCString( char* str ) {
00042         xercesc::XMLString::release( &str ) ;
00043         return ;
00044     }
00045 
00046 } ; // FreeXercesString
00047 
00048 // = = = = = = = = = = = = = = = = = = = =
00049 
00068 #include<string>
00069 #include<xercesc/util/XMLString.hpp>
00070 
00071 class DualString {
00072 
00073     public :
00074     DualString( const XMLCh* const original ) ;
00075 
00076     DualString( const XMLCh* const original , int length ) ;
00077 
00078     DualString( const char* const original ) ;
00079 
00080     DualString( const char* const original , int length ) ;
00081 
00082     DualString( const std::string& original ) ;
00083 
00084     ~DualString() throw() ;
00085 
00086 
00087     const char* asCString() const throw() ;
00088 
00089     const XMLCh* asXMLString() const throw() ;
00090 
00091     std::ostream& print( std::ostream& s ) const ;
00092 
00093 
00094     protected:
00095     // empty
00096 
00097 
00098     private :
00099     char*   cString_ ;
00100     XMLCh*  xmlString_ ;
00101 
00102 } ; // class DualString
00103 
00104 
00105 std::ostream& operator<<( std::ostream& s, const DualString& obj ) ;
00106 
00107 
00108 // = = = = = = = = = = = = = = = = = = = =
00109 
00110 #include<list>
00111 #include<stdexcept>
00112 
00113 #include<xercesc/util/XMLString.hpp>
00114 
00144 class StringManager {
00145 
00146     private:
00147     typedef std::list< XMLCh* > XMLStringList ;
00148     typedef std::list< char* > CStringList ;
00149 
00150     XMLStringList xmlStrings_ ;
00151     CStringList cStrings_ ;
00152 
00153     protected:
00154     // empty
00155 
00156     public:
00157     StringManager() ;
00158 
00160     ~StringManager() throw() ;
00161 
00162 
00164     void drain() throw() ;
00165 
00166 
00172     char* disown( char* str ) throw( std::logic_error ) ;
00173 
00174 
00180     XMLCh* disown( XMLCh* str ) throw( std::logic_error ) ;
00181 
00182 
00190     XMLCh* convert( const char* str ) ;
00191 
00192 
00200     XMLCh* convert( const std::string& str ) ;
00201 
00202 
00209     char* convert( const XMLCh* str ) ;
00210 
00211 } ; // class StringManager 
00212 
00213 
00214 
00215 #endif // #ifndef HELPER_CLASSES_H

Generated on Sat Jun 23 16:07:23 2007 for Stechec/TBT by  doxygen 1.4.7