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 class Storage;
19 
20 namespace lhef {
21 
22 class StorageWrap {
23  public:
25  ~StorageWrap();
26 
27  Storage *operator -> () { return storage.get(); }
28  const Storage *operator -> () const { return storage.get(); }
29 
30  private:
31  std::auto_ptr<Storage> storage;
32 };
33 
34 class XMLDocument {
35  public:
36  class Handler : public XERCES_CPP_NAMESPACE_QUALIFIER DefaultHandler {};
37 
38  XMLDocument(std::auto_ptr<std::istream> &in, Handler &handler);
39  XMLDocument(std::auto_ptr<StorageWrap> &in, Handler &handler);
40  virtual ~XMLDocument();
41 
42  bool parse();
43 
44  private:
46  public:
49 
50  private:
51  // do not make any kind of copies
52  XercesPlatform(const XercesPlatform &orig);
54 
55  static unsigned int instances;
56  };
57 
58  void init(Handler &handler);
59 
60  std::auto_ptr<XercesPlatform> platform;
61 
62  std::auto_ptr<XERCES_CPP_NAMESPACE_QUALIFIER InputSource> source;
63  std::auto_ptr<XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader> parser;
64 
66 
67  bool done;
68 };
69 
70 class XMLSimpleStr {
71  public:
72  XMLSimpleStr(const XMLCh *str) :
73  string(XERCES_CPP_NAMESPACE_QUALIFIER XMLString::transcode(str))
74  {}
75 
78 
79  inline operator const char *() const
80  { return string; }
81 
82  inline static bool isAllSpaces(const XMLCh *str, unsigned int length)
84  XMLChar1_0::isAllSpaces(str, length); }
85 
86  inline static bool isSpace(XMLCh ch)
88  XMLChar1_0::isWhitespace(ch); }
89 
90  private:
91  char *string;
92 };
93 
94 class XMLUniStr {
95  public:
96  XMLUniStr(const char *str) :
97  unicode(XERCES_CPP_NAMESPACE_QUALIFIER XMLString::transcode(str))
98  {}
99 
102 
103  operator const XMLCh *() const
104  { return unicode; }
105 
106  private:
107  XMLCh *unicode;
108 };
109 
110 template<typename T>
113  public:
114  typedef typename T::Stream_t Stream_t;
115 
116  XMLInputSourceWrapper(std::auto_ptr<Stream_t> &obj) : obj(obj) {}
118 
119  virtual XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream* makeStream() const
120  { return new T(*obj); }
121 
122  private:
123  std::auto_ptr<Stream_t> obj;
124 };
125 
126 class CBInputStream : public XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream {
127  public:
128  class Reader {
129  public:
130  virtual ~Reader();
131  virtual const std::string &data()= 0;
132  };
133 
134  typedef Reader Stream_t;
135 
137  virtual ~CBInputStream();
138 
139  virtual unsigned int curPos() const { return pos; }
140 
141  virtual unsigned int readBytes(XMLByte *const buf,
142  const unsigned int size);
143 
144  private:
146  std::string buffer;
147  unsigned int pos;
148 };
149 
150 class STLInputStream : public XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream {
151  public:
152  typedef std::istream Stream_t;
153 
154  STLInputStream(std::istream &in);
155  virtual ~STLInputStream();
156 
157  virtual unsigned int curPos() const { return pos; }
158 
159  virtual unsigned int readBytes(XMLByte *const buf,
160  const unsigned int size);
161 
162  private:
163  std::istream &in;
164  unsigned int pos;
165 };
166 
168  public XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream {
169  public:
171 
173  virtual ~StorageInputStream();
174 
175  virtual unsigned int curPos() const { return pos; }
176 
177  virtual unsigned int readBytes(XMLByte *const buf,
178  const unsigned int size);
179 
180  private:
182  unsigned int pos;
183  lzma_stream lstr;
185  unsigned int lasttotal_;
186 };
187 
191 
192 } // namespace lhef
193 
194 #endif // GeneratorInterface_LHEInterface_XMLUtils_h
std::auto_ptr< Storage > storage
Definition: XMLUtils.h:31
std::auto_ptr< XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader > parser
Definition: XMLUtils.h:63
unsigned int pos
Definition: XMLUtils.h:164
XMLInputSourceWrapper< StorageInputStream > StorageInputSource
Definition: XMLUtils.h:190
XMLInputSourceWrapper< STLInputStream > STLInputSource
Definition: XMLUtils.h:189
XMLInputSourceWrapper(std::auto_ptr< Stream_t > &obj)
Definition: XMLUtils.h:116
std::istream Stream_t
Definition: XMLUtils.h:152
void init(Handler &handler)
Definition: XMLUtils.cc:74
std::auto_ptr< XERCES_CPP_NAMESPACE_QUALIFIER InputSource > source
Definition: XMLUtils.h:62
StorageInputStream(StorageWrap &in)
Definition: XMLUtils.cc:206
std::string buffer
Definition: XMLUtils.h:146
XMLInputSourceWrapper< CBInputStream > CBInputSource
Definition: XMLUtils.h:188
virtual ~XMLDocument()
Definition: XMLUtils.cc:100
std::auto_ptr< XercesPlatform > platform
Definition: XMLUtils.h:60
virtual const std::string & data()=0
CBInputStream(Reader &in)
Definition: XMLUtils.cc:128
virtual unsigned int readBytes(XMLByte *const buf, const unsigned int size)
Definition: XMLUtils.cc:184
static bool isSpace(XMLCh ch)
Definition: XMLUtils.h:86
Definition: Storage.h:8
virtual ~StorageInputStream()
Definition: XMLUtils.cc:241
XMLDocument(std::auto_ptr< std::istream > &in, Handler &handler)
Definition: XMLUtils.cc:56
virtual ~STLInputStream()
Definition: XMLUtils.cc:180
#define XERCES_CPP_NAMESPACE_QUALIFIER
Definition: LHERunInfo.h:16
virtual unsigned int curPos() const
Definition: XMLUtils.h:175
STLInputStream(std::istream &in)
Definition: XMLUtils.cc:171
unsigned int lasttotal_
Definition: XMLUtils.h:185
virtual unsigned int readBytes(XMLByte *const buf, const unsigned int size)
Definition: XMLUtils.cc:246
std::istream & in
Definition: XMLUtils.h:163
XERCES_CPP_NAMESPACE_QUALIFIER XMLPScanToken token
Definition: XMLUtils.h:65
virtual unsigned int curPos() const
Definition: XMLUtils.h:139
XercesPlatform & operator=(const XercesPlatform &orig)
Storage * operator->()
Definition: XMLUtils.h:27
static bool isAllSpaces(const XMLCh *str, unsigned int length)
Definition: XMLUtils.h:82
std::auto_ptr< Stream_t > obj
Definition: XMLUtils.h:123
unsigned int pos
Definition: XMLUtils.h:147
XMLCh * unicode
Definition: XMLUtils.h:107
StorageWrap & in
Definition: XMLUtils.h:181
StorageWrap Stream_t
Definition: XMLUtils.h:170
virtual unsigned int readBytes(XMLByte *const buf, const unsigned int size)
Definition: XMLUtils.cc:137
virtual ~XMLInputSourceWrapper()
Definition: XMLUtils.h:117
XMLSimpleStr(const XMLCh *str)
Definition: XMLUtils.h:72
virtual XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream * makeStream() const
Definition: XMLUtils.h:119
XMLUniStr(const char *str)
Definition: XMLUtils.h:96
StorageWrap(Storage *storage)
Definition: XMLUtils.cc:24
static unsigned int instances
Definition: XMLUtils.h:55
virtual ~CBInputStream()
Definition: XMLUtils.cc:133
long double T
tuple size
Write out results.
Helper class to handle FWLite file input sources.
virtual unsigned int curPos() const
Definition: XMLUtils.h:157