Transformer.h
Go to the documentation of this file.
1 
20 #ifndef TRANSFORMER_H_32113356
21 #define TRANSFORMER_H_32113356
22 
23 #include <map>
24 #include "uscxml/Interpreter.h"
26 
27 namespace uscxml {
28 
29 class USCXML_API TransformerImpl {
30 public:
31  TransformerImpl(const Interpreter& other) {
32  interpreter = other; // we need to keep a reference to retain the document!
33  other.getImpl()->setupDOM();
34  _document = other.getImpl()->_document;
35  _baseURL = other.getImpl()->_baseURL;
36  _scxml = other.getImpl()->_scxml;
37  _name = other.getImpl()->_name;
38  _binding = other.getImpl()->_binding;
39  }
40 
41 
42 
43  virtual void writeTo(std::ostream& stream) = 0;
44  virtual operator Interpreter() {
45  throw std::runtime_error("Transformer cannot be interpreted as an Interpreter again");
46  }
47 
48  virtual XERCESC_NS::DOMDocument* getDocument() const {
49  return _document;
50  }
51 
52 protected:
53  std::multimap<std::string, std::string> _extensions;
54  std::list<std::string> _options;
55 
56  XERCESC_NS::DOMDocument* _document;
57  XERCESC_NS::DOMElement* _scxml;
58 
59  Interpreter interpreter;
60  InterpreterImpl::Binding _binding;
61  URL _baseURL;
62  std::string _name;
63 
64  friend class Transformer;
65 };
66 
67 class USCXML_API Transformer {
68 public:
69 // Transformer(const Interpreter& source) { _impl = new (source) }
70 
71  Transformer() : _impl() {} // the empty, invalid interpreter
72  Transformer(std::shared_ptr<TransformerImpl> const impl) : _impl(impl) { }
73  Transformer(const Transformer& other) : _impl(other._impl) { }
74  virtual ~Transformer() {};
75 
76  operator bool() const {
77  return !!_impl;
78  }
79  bool operator< (const Transformer& other) const {
80  return _impl < other._impl;
81  }
82  bool operator==(const Transformer& other) const {
83  return _impl == other._impl;
84  }
85  bool operator!=(const Transformer& other) const {
86  return _impl != other._impl;
87  }
88  Transformer& operator= (const Transformer& other) {
89  _impl = other._impl;
90  return *this;
91  }
92 
93  virtual void writeTo(std::ostream& stream) {
94  _impl->writeTo(stream);
95  }
96  operator Interpreter() {
97  return _impl->operator Interpreter();
98  }
99 
100  std::shared_ptr<TransformerImpl> getImpl() {
101  return _impl;
102  }
103 
104  void setExtensions(const std::multimap<std::string, std::string>& extensions) {
105  _impl->_extensions = extensions;
106  }
107 
108  void setOptions(const std::list<std::string>& options) {
109  _impl->_options = options;
110  }
111 
112 protected:
113  std::shared_ptr<TransformerImpl> _impl;
114 
115 };
116 
117 }
118 
119 #endif /* end of include guard: TRANSFORMER_H_32113356 */
Definition: Breakpoint.cpp:26
Central class to interpret and process SCXML documents.
Definition: Interpreter.h:79
Definition: URL.h:133
std::shared_ptr< InterpreterImpl > getImpl() const
Return the actual implementation of the Interperter.
Definition: Interpreter.h:222
Definition: Transformer.h:29
Definition: Transformer.h:67