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