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) : m_array(const_cast<CharType*>(str), &dispose) {}
23 
24  CharType const* ptr() const { return m_array.get(); }
25 
26  private:
27  std::unique_ptr<CharType, void (*)(CharType*)> m_array;
28  };
29 
30  inline ZStr<XMLCh> uStr(char const* str) { return ZStr<XMLCh>(XMLString::transcode(str)); }
31 
32  inline ZStr<char> cStr(XMLCh const* str) { return ZStr<char>(XMLString::transcode(str)); }
33 
34  inline std::string toString(XMLCh const* toTranscode) { return std::string(cStr(toTranscode).ptr()); }
35 
36  inline unsigned int toUInt(XMLCh const* toTranscode) {
37  std::istringstream iss(toString(toTranscode));
38  unsigned int returnValue;
39  iss >> returnValue;
40  return returnValue;
41  }
42 
43  inline bool toBool(XMLCh const* toTranscode) {
44  std::string value = toString(toTranscode);
45  if ((value == "true") || (value == "1"))
46  return true;
47  return false;
48  }
49 
50  inline double toDouble(XMLCh const* toTranscode) {
51  std::istringstream iss(toString(toTranscode));
52  double returnValue;
53  iss >> returnValue;
54  return returnValue;
55  }
56  } // namespace xerces
57 } // namespace cms
58 
59 #endif
cms::xerces::ZStr::ZStr
ZStr(CharType const *str)
Definition: XercesStrUtils.h:22
cms::xerces::dispose
void dispose(XMLCh *ptr)
Definition: XercesStrUtils.h:15
XERCES_CPP_NAMESPACE_USE
Definition: XMLConfigWriter.cc:40
cms::xerces::cStr
ZStr< char > cStr(XMLCh const *str)
Definition: XercesStrUtils.h:32
cms::xerces::toString
std::string toString(XMLCh const *toTranscode)
Definition: XercesStrUtils.h:34
cms::xerces::ZStr::ptr
CharType const * ptr() const
Definition: XercesStrUtils.h:24
cms::xerces::toDouble
double toDouble(XMLCh const *toTranscode)
Definition: XercesStrUtils.h:50
str
#define str(s)
Definition: TestProcessor.cc:51
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
value
Definition: value.py:1
cms::xerces::toUInt
unsigned int toUInt(XMLCh const *toTranscode)
Definition: XercesStrUtils.h:36
cms::xerces::uStr
ZStr< XMLCh > uStr(char const *str)
Definition: XercesStrUtils.h:30
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
cms::xerces::ZStr::m_array
std::unique_ptr< CharType, void(*)(CharType *)> m_array
Definition: XercesStrUtils.h:27
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
cms::xerces::toBool
bool toBool(XMLCh const *toTranscode)
Definition: XercesStrUtils.h:43
cms::xerces::ZStr
Definition: XercesStrUtils.h:19
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21