test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
XMLUtils.h
Go to the documentation of this file.
1 #ifndef GeneratorInterface_LHEInterface_XMLUtils_h
2 #define GeneratorInterface_LHEInterface_XMLUtils_h
3 
4 #include <iostream>
5 #include <string>
6 #include <memory>
7 
8 #include <xercesc/util/XMLString.hpp>
9 #include <xercesc/util/XMLUni.hpp>
10 #include <xercesc/util/XMLChar.hpp>
11 #include <xercesc/util/BinInputStream.hpp>
12 #include <xercesc/framework/XMLPScanToken.hpp>
13 #include <xercesc/sax/InputSource.hpp>
14 #include <xercesc/sax2/DefaultHandler.hpp>
15 #include <xercesc/sax2/SAX2XMLReader.hpp>
16 #include <lzma.h>
17 
18 
19 class Storage;
20 
21 namespace lhef {
22 
23 class StorageWrap {
24  public:
25  StorageWrap(std::unique_ptr<Storage> storage);
26  ~StorageWrap();
27 
28  Storage *operator -> () { return storage.get(); }
29  const Storage *operator -> () const { return storage.get(); }
30 
31  private:
32  std::unique_ptr<Storage> storage;
33 };
34 
35 class XMLDocument {
36  public:
37  class Handler : public XERCES_CPP_NAMESPACE_QUALIFIER DefaultHandler {};
38 
39  XMLDocument(std::auto_ptr<std::istream> &in, Handler &handler);
40  XMLDocument(std::auto_ptr<StorageWrap> &in, Handler &handler);
41  virtual ~XMLDocument();
42 
43  bool parse();
44 
45  private:
47  public:
50 
51  private:
52  // do not make any kind of copies
53  XercesPlatform(const XercesPlatform &orig);
55 
56  static unsigned int instances;
57  };
58 
59  void init(Handler &handler);
60 
61  std::auto_ptr<XercesPlatform> platform;
62 
63  std::auto_ptr<XERCES_CPP_NAMESPACE_QUALIFIER InputSource> source;
64  std::auto_ptr<XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader> parser;
65 
67 
68  bool done;
69 };
70 
71 class XMLSimpleStr {
72  public:
73  XMLSimpleStr(const XMLCh *str) :
75  {}
76 
79 
80  inline operator const char *() const
81  { return string; }
82 
83  inline static bool isAllSpaces(const XMLCh *str, unsigned int length)
85  XMLChar1_0::isAllSpaces(str, length); }
86 
87  inline static bool isSpace(XMLCh ch)
89  XMLChar1_0::isWhitespace(ch); }
90 
91  private:
92  char *string;
93 };
94 
95 class XMLUniStr {
96  public:
97  XMLUniStr(const char *str) :
99  {}
100 
103 
104  operator const XMLCh *() const
105  { return unicode; }
106 
107  private:
108  XMLCh *unicode;
109 };
110 
111 template<typename T>
114  public:
115  typedef typename T::Stream_t Stream_t;
116 
117  XMLInputSourceWrapper(std::auto_ptr<Stream_t> &obj) : obj(obj) {}
119 
120  virtual XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream* makeStream() const
121  { return new T(*obj); }
122 
123  private:
124  std::auto_ptr<Stream_t> obj;
125 };
126 
127 class CBInputStream : public XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream {
128  public:
129  class Reader {
130  public:
131  virtual ~Reader();
132  virtual const std::string &data()= 0;
133  };
134 
135  typedef Reader Stream_t;
136 
138  virtual ~CBInputStream();
139 
140  virtual unsigned int curPos() const { return pos; }
141 
142  virtual unsigned int readBytes(XMLByte *const buf,
143  const unsigned int size);
144 
145  private:
148  unsigned int pos;
149 };
150 
151 class STLInputStream : public XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream {
152  public:
153  typedef std::istream Stream_t;
154 
155  STLInputStream(std::istream &in);
156  virtual ~STLInputStream();
157 
158  virtual unsigned int curPos() const { return pos; }
159 
160  virtual unsigned int readBytes(XMLByte *const buf,
161  const unsigned int size);
162 
163  private:
164  std::istream &in;
165  unsigned int pos;
166 };
167 
169  public XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream {
170  public:
172 
174  virtual ~StorageInputStream();
175 
176  virtual unsigned int curPos() const { return pos; }
177 
178  virtual unsigned int readBytes(XMLByte *const buf,
179  const unsigned int size);
180 
181  private:
183  unsigned int pos;
184  lzma_stream lstr;
186  unsigned int lasttotal_;
187 
188  unsigned int buffLoc_ = 0,buffTotal_ = 0;
189  std::vector<uint8_t> buffer_;
190  static constexpr unsigned bufferSize_ = 16*1024*1024;
191 };
192 
196 
197 } // namespace lhef
198 
199 #endif // GeneratorInterface_LHEInterface_XMLUtils_h
std::auto_ptr< XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader > parser
Definition: XMLUtils.h:64
unsigned int pos
Definition: XMLUtils.h:165
XMLInputSourceWrapper< StorageInputStream > StorageInputSource
Definition: XMLUtils.h:195
XMLInputSourceWrapper< STLInputStream > STLInputSource
Definition: XMLUtils.h:194
XMLInputSourceWrapper(std::auto_ptr< Stream_t > &obj)
Definition: XMLUtils.h:117
std::istream Stream_t
Definition: XMLUtils.h:153
void init(Handler &handler)
Definition: XMLUtils.cc:75
StorageWrap(std::unique_ptr< Storage > storage)
Definition: XMLUtils.cc:25
std::auto_ptr< XERCES_CPP_NAMESPACE_QUALIFIER InputSource > source
Definition: XMLUtils.h:63
StorageInputStream(StorageWrap &in)
Definition: XMLUtils.cc:207
std::string buffer
Definition: XMLUtils.h:147
XMLInputSourceWrapper< CBInputStream > CBInputSource
Definition: XMLUtils.h:193
virtual ~XMLDocument()
Definition: XMLUtils.cc:101
std::auto_ptr< XercesPlatform > platform
Definition: XMLUtils.h:61
virtual const std::string & data()=0
CBInputStream(Reader &in)
Definition: XMLUtils.cc:129
virtual unsigned int readBytes(XMLByte *const buf, const unsigned int size)
Definition: XMLUtils.cc:185
static bool isSpace(XMLCh ch)
Definition: XMLUtils.h:87
virtual ~StorageInputStream()
Definition: XMLUtils.cc:243
XMLDocument(std::auto_ptr< std::istream > &in, Handler &handler)
Definition: XMLUtils.cc:57
virtual ~STLInputStream()
Definition: XMLUtils.cc:181
#define XERCES_CPP_NAMESPACE_QUALIFIER
Definition: LHERunInfo.h:16
virtual unsigned int curPos() const
Definition: XMLUtils.h:176
STLInputStream(std::istream &in)
Definition: XMLUtils.cc:172
#define constexpr
unsigned int lasttotal_
Definition: XMLUtils.h:186
virtual unsigned int readBytes(XMLByte *const buf, const unsigned int size)
Definition: XMLUtils.cc:249
std::istream & in
Definition: XMLUtils.h:164
XERCES_CPP_NAMESPACE_QUALIFIER XMLPScanToken token
Definition: XMLUtils.h:66
virtual unsigned int curPos() const
Definition: XMLUtils.h:140
XercesPlatform & operator=(const XercesPlatform &orig)
static constexpr unsigned bufferSize_
Definition: XMLUtils.h:190
Storage * operator->()
Definition: XMLUtils.h:28
XMLCh * transcode(const T &fInput)
static bool isAllSpaces(const XMLCh *str, unsigned int length)
Definition: XMLUtils.h:83
std::auto_ptr< Stream_t > obj
Definition: XMLUtils.h:124
unsigned int pos
Definition: XMLUtils.h:148
XMLCh * unicode
Definition: XMLUtils.h:108
StorageWrap & in
Definition: XMLUtils.h:182
unsigned int buffLoc_
Definition: XMLUtils.h:188
StorageWrap Stream_t
Definition: XMLUtils.h:171
virtual unsigned int readBytes(XMLByte *const buf, const unsigned int size)
Definition: XMLUtils.cc:138
virtual ~XMLInputSourceWrapper()
Definition: XMLUtils.h:118
XMLSimpleStr(const XMLCh *str)
Definition: XMLUtils.h:73
virtual XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream * makeStream() const
Definition: XMLUtils.h:120
unsigned int buffTotal_
Definition: XMLUtils.h:188
XMLUniStr(const char *str)
Definition: XMLUtils.h:97
std::unique_ptr< Storage > storage
Definition: XMLUtils.h:32
static unsigned int instances
Definition: XMLUtils.h:56
std::vector< uint8_t > buffer_
Definition: XMLUtils.h:189
virtual ~CBInputStream()
Definition: XMLUtils.cc:134
long double T
tuple size
Write out results.
Helper class to handle FWLite file input sources.
virtual unsigned int curPos() const
Definition: XMLUtils.h:158