00001 /*************************************************************************** 00002 StrX.h - description 00003 ------------------- 00004 begin : Tue Oct 23 2001 00005 copyright : See Xerces C++ documentation 00006 email : case@ucdhep.ucdavis.edu 00007 ***************************************************************************/ 00008 00009 #ifndef STRX_H 00010 #define STRX_H 00011 00012 #include <xercesc/util/XercesDefs.hpp> 00013 #include <xercesc/util/PlatformUtils.hpp> 00014 #include <xercesc/sax2/XMLReaderFactory.hpp> 00015 #include <xercesc/sax2/SAX2XMLReader.hpp> 00016 #include <xercesc/util/XMLString.hpp> 00017 #include <string> 00018 #include <iostream> 00019 00028 // --------------------------------------------------------------------------- 00029 // This is a simple class that lets us do easy (though not terribly efficient) 00030 // trancoding of XMLCh data to local code page for display. 00031 // --------------------------------------------------------------------------- 00032 class StrX 00033 { 00034 public: 00035 typedef XERCES_CPP_NAMESPACE::XMLString XMLString; 00036 // ----------------------------------------------------------------------- 00037 // Constructors and Destructor 00038 // ----------------------------------------------------------------------- 00039 StrX(const XMLCh* const toTranscode)// : fXMLChForm(toTranscode) 00040 { 00041 fLocalForm = XMLString::transcode(toTranscode); 00042 fXMLChForm = XMLString::transcode(fLocalForm); 00043 } 00044 00045 StrX( const char* const toTranscode ) 00046 { 00047 fXMLChForm = XMLString::transcode(toTranscode); 00048 fLocalForm = XMLString::transcode(fXMLChForm); 00049 } 00050 00051 StrX( const std::string& toTranscode ) 00052 { 00053 fXMLChForm = XMLString::transcode(toTranscode.c_str()); 00054 fLocalForm = XMLString::transcode(fXMLChForm); 00055 } 00056 00057 ~StrX() 00058 { 00059 XMLString::release(&fLocalForm); 00060 XMLString::release(&fXMLChForm); 00061 } 00062 00063 // ----------------------------------------------------------------------- 00064 // Getter methods 00065 // ----------------------------------------------------------------------- 00066 const char* localForm() const 00067 { 00068 return fLocalForm; 00069 } 00070 00071 const XMLCh* xmlChForm() const 00072 { 00073 return fXMLChForm; 00074 } 00075 00076 private: 00077 XMLCh * fXMLChForm; 00078 char * fLocalForm; 00079 00080 }; 00081 00082 inline std::ostream& operator<<(std::ostream& target, const StrX& toDump) 00083 { 00084 target << toDump.localForm(); 00085 return target; 00086 } 00087 #endif