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()->init();
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  virtual void writeTo(std::ostream& stream) = 0;
43  virtual operator Interpreter() {
44  throw std::runtime_error("Transformer cannot be interpreted as an Interpreter again");
45  }
46 
47 protected:
48  std::multimap<std::string, std::string> _extensions;
49  std::list<std::string> _options;
50 
51  XERCESC_NS::DOMDocument* _document;
52  XERCESC_NS::DOMElement* _scxml;
53 
54  Interpreter interpreter;
55  InterpreterImpl::Binding _binding;
56  URL _baseURL;
57  std::string _name;
58 
59  friend class Transformer;
60 };
61 
62 class USCXML_API Transformer {
63 public:
64 // Transformer(const Interpreter& source) { _impl = new (source) }
65 
66  Transformer() : _impl() {} // the empty, invalid interpreter
67  Transformer(std::shared_ptr<TransformerImpl> const impl) : _impl(impl) { }
68  Transformer(const Transformer& other) : _impl(other._impl) { }
69  virtual ~Transformer() {};
70 
71  operator bool() const {
72  return !!_impl;
73  }
74  bool operator< (const Transformer& other) const {
75  return _impl < other._impl;
76  }
77  bool operator==(const Transformer& other) const {
78  return _impl == other._impl;
79  }
80  bool operator!=(const Transformer& other) const {
81  return _impl != other._impl;
82  }
83  Transformer& operator= (const Transformer& other) {
84  _impl = other._impl;
85  return *this;
86  }
87 
88  virtual void writeTo(std::ostream& stream) {
89  _impl->writeTo(stream);
90  }
91  operator Interpreter() {
92  return _impl->operator Interpreter();
93  }
94 
95  std::shared_ptr<TransformerImpl> getImpl() {
96  return _impl;
97  }
98 
99  void setExtensions(const std::multimap<std::string, std::string>& extensions) {
100  _impl->_extensions = extensions;
101  }
102 
103  void setOptions(const std::list<std::string>& options) {
104  _impl->_options = options;
105  }
106 
107 protected:
108  std::shared_ptr<TransformerImpl> _impl;
109 
110 };
111 
112 }
113 
114 #endif /* end of include guard: TRANSFORMER_H_32113356 */
Definition: InterpreterIssue.cpp:33
Central class to interpret and process SCXML documents.
Definition: Interpreter.h:112
Definition: URL.h:191
std::shared_ptr< InterpreterImpl > getImpl() const
Return the actual implementation of the Interperter.
Definition: Interpreter.h:219
Definition: Transformer.h:30
Definition: Transformer.h:62