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 #include <sstream>
8 
9 #ifdef XERCES_CPP_NAMESPACE_USE
11 #endif
12 
13 namespace cms {
14  namespace xerces {
15  inline void dispose(XMLCh* ptr) { XMLString::release(&ptr); }
16  inline void dispose(char* ptr) { XMLString::release(&ptr); }
17 
18  template< class CharType >
19  class ZStr // Zero-terminated string.
20  {
21  public:
22  ZStr(CharType const* str)
23  : m_array(const_cast<CharType*>(str), &dispose)
24  {}
25 
26  CharType const* ptr() const { return m_array.get(); }
27 
28  private:
29  std::unique_ptr< CharType, void (*)(CharType*) > m_array;
30  };
31 
32  inline ZStr<XMLCh> uStr(char const* str) {
33  return ZStr<XMLCh>(XMLString::transcode(str));
34  }
35 
36  inline ZStr<char> cStr(XMLCh const* str) {
37  return ZStr<char>(XMLString::transcode(str));
38  }
39 
40  inline std::string toString(XMLCh const* toTranscode) {
41  return std::string(cStr(toTranscode).ptr());
42  }
43 
44  inline unsigned int toUInt(XMLCh const* toTranscode) {
45  std::istringstream iss(toString(toTranscode));
46  unsigned int returnValue;
47  iss >> returnValue;
48  return returnValue;
49  }
50 
51  inline bool toBool(XMLCh const* toTranscode) {
52  std::string value = toString(toTranscode);
53  if ((value == "true") || (value == "1"))
54  return true;
55  return false;
56  }
57 
58  inline double toDouble(XMLCh const* toTranscode) {
59  std::istringstream iss(toString(toTranscode));
60  double returnValue;
61  iss >> returnValue;
62  return returnValue;
63  }
64  }
65 }
66 
67 #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
Namespace of DDCMS conversion namespace.
CharType const * ptr() const
std::unique_ptr< CharType, void(*)(CharType *) > m_array
#define str(s)
bool toBool(XMLCh const *toTranscode)