CMS 3D CMS Logo

XercesStrUtils.h
Go to the documentation of this file.
1 #ifndef UTILITIES_XERCES_STRING_UTILS_H
2 #define UTILITIES_XERCES_STRING_UTILS_H
3 
4 #include <xercesc/util/XercesDefs.hpp>
5 #include <xercesc/util/XMLString.hpp>
6 #include <memory>
7 
8 #ifdef XERCES_CPP_NAMESPACE_USE
10 #endif
11 
12 namespace cms {
13  namespace xerces {
14  inline void dispose(XMLCh* ptr) { XMLString::release(&ptr); }
15  inline void dispose(char* ptr) { XMLString::release(&ptr); }
16 
17  template< class CharType >
18  class ZStr // Zero-terminated string.
19  {
20  public:
21  ZStr(CharType const* str)
22  : m_array(const_cast<CharType*>(str), &dispose)
23  {}
24 
25  CharType const* ptr() const { return m_array.get(); }
26 
27  private:
28  std::unique_ptr< CharType, void (*)(CharType*) > m_array;
29  };
30 
31  inline ZStr<XMLCh> uStr(char const* str) {
32  return ZStr<XMLCh>(XMLString::transcode(str));
33  }
34 
35  inline ZStr<char> cStr(XMLCh const* str) {
36  return ZStr<char>(XMLString::transcode(str));
37  }
38 
39  inline std::string toString(XMLCh const* toTranscode) {
40  return std::string(cStr(toTranscode).ptr());
41  }
42 
43  inline unsigned int toUInt(XMLCh const* toTranscode) {
44  std::istringstream iss(toString(toTranscode));
45  unsigned int returnValue;
46  iss >> returnValue;
47  return returnValue;
48  }
49 
50  inline bool toBool(XMLCh const* toTranscode) {
51  std::string value = toString(toTranscode);
52  if ((value == "true") || (value == "1"))
53  return true;
54  return false;
55  }
56 
57  inline double toDouble(XMLCh const* toTranscode) {
58  std::istringstream iss(toString(toTranscode));
59  double returnValue;
60  iss >> returnValue;
61  return returnValue;
62  }
63  }
64 }
65 
66 #endif
double toDouble(XMLCh const *toTranscode)
void dispose(XMLCh *ptr)
std::string toString(XMLCh const *toTranscode)
ZStr(CharType const *str)
ZStr< char > cStr(XMLCh const *str)
unsigned int toUInt(XMLCh const *toTranscode)
ZStr< XMLCh > uStr(char const *str)
Definition: value.py:1
CharType const * ptr() const
std::unique_ptr< CharType, void(*)(CharType *) > m_array
bool toBool(XMLCh const *toTranscode)