Wolframe, 0.0.3

output.hpp
Go to the documentation of this file.
1 /************************************************************************
2 
3  Copyright (C) 2011 - 2014 Project Wolframe.
4  All rights reserved.
5 
6  This file is part of Project Wolframe.
7 
8  Commercial Usage
9  Licensees holding valid Project Wolframe Commercial licenses may
10  use this file in accordance with the Project Wolframe
11  Commercial License Agreement provided with the Software or,
12  alternatively, in accordance with the terms contained
13  in a written agreement between the licensee and Project Wolframe.
14 
15  GNU General Public License Usage
16  Alternatively, you can redistribute this file and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  Wolframe is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  GNU General Public License for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
28 
29  If you have questions regarding the use of this file, please contact
30  Project Wolframe.
31 
32 ************************************************************************/
35 #ifndef _DATABASE_VIRTUAL_MACHINE_OUTPUT_HPP_INCLUDED
36 #define _DATABASE_VIRTUAL_MACHINE_OUTPUT_HPP_INCLUDED
37 #include "types/variant.hpp"
38 #include <vector>
39 #include <boost/shared_ptr.hpp>
40 
41 namespace _Wolframe {
42 namespace db {
43 namespace vm {
44 
47 class Output
48 {
49 public:
52  {
53  addOutputSink();
54  }
56  Output( const Output& o)
57  :m_ar(o.m_ar){}
58 
61  class Element
62  {
63  public:
65  enum Operation
66  {
67  Open, //< open of a single element
68  OpenArray, //< open of an array
69  OpenArrayElement, //< open of an array element
70  Close, //< close of a single element
71  CloseArray, //< close of an array
72  CloseArrayElement, //< close of an array element
73  Value //< content value
74  };
77  :m_op(Value){}
79  Element( const Element& o)
80  :m_op(o.m_op),m_arg(o.m_arg){}
82  Element( const Operation& op_, const types::Variant& arg_)
83  :m_op(op_),m_arg(arg_){}
85  explicit Element( const Operation& op_)
86  :m_op(op_){}
87 
89  Operation op() const {return m_op;}
91  const types::Variant& arg() const {return m_arg;}
92 
93  private:
96  };
97 
100  void add( const Element& elem)
101  {
102  m_ar.back().push_back( elem);
103  }
106  void addValue( const types::Variant& value)
107  {
108  m_ar.back().push_back( Element( Element::Value, value));
109  }
110 
113  {
114  m_ar.push_back( ElementArray());
115  }
116 
117  typedef std::vector<Element>::const_iterator const_iterator;
119  const_iterator begin( std::size_t i=0) const {if (i>=m_ar.size()) throw std::runtime_error("array bound access"); return m_ar[i].begin();}
121  const_iterator end( std::size_t i=0) const {if (i>=m_ar.size()) throw std::runtime_error("array bound access"); return m_ar[i].end();}
122 
124  const std::vector<Element>& elements( std::size_t i=0) const {if (i>=m_ar.size()) throw std::runtime_error("array bound access"); return m_ar[i];}
125 
126 private:
127  typedef std::vector<Element> ElementArray;
128  std::vector<ElementArray> m_ar; //< array of output element vectors (first element is the transaction output and the following are the auditing function inputs)
129 };
130 
131 typedef boost::shared_ptr<Output> OutputR;
132 
133 }}}//namespace
134 #endif
135 
Operation op() const
Get the operation of output.
Definition: output.hpp:89
void addValue(const types::Variant &value)
Add a value element to output.
Definition: output.hpp:106
const std::vector< Element > & elements(std::size_t i=0) const
Get the array of output elements.
Definition: output.hpp:124
Output structure of the VM for transactions.
Definition: output.hpp:47
types::Variant m_arg
argument of output
Definition: output.hpp:95
Output()
Default constructor.
Definition: output.hpp:51
Element(const Operation &op_)
Constructor.
Definition: output.hpp:85
const_iterator end(std::size_t i=0) const
Get the end iterator on this output.
Definition: output.hpp:121
std::vector< ElementArray > m_ar
Definition: output.hpp:128
Forward declaration.
Definition: variant.hpp:65
const_iterator begin(std::size_t i=0) const
Get the start iterator on this output.
Definition: output.hpp:119
Variant value type.
boost::shared_ptr< Output > OutputR
Definition: output.hpp:131
Element()
Default constructor.
Definition: output.hpp:76
void addOutputSink()
Add a new output sink and declare it as the current output.
Definition: output.hpp:112
void add(const Element &elem)
Add element to output.
Definition: output.hpp:100
Output(const Output &o)
Copy constructor.
Definition: output.hpp:56
Operation m_op
operation of output
Definition: output.hpp:94
Element of output.
Definition: output.hpp:61
std::vector< Element >::const_iterator const_iterator
Definition: output.hpp:117
Element(const Element &o)
Copy constructor.
Definition: output.hpp:79
const types::Variant & arg() const
Get the argument of output.
Definition: output.hpp:91
std::vector< Element > ElementArray
Definition: output.hpp:127
Element(const Operation &op_, const types::Variant &arg_)
Constructor.
Definition: output.hpp:82
Operation
Operation of output.
Definition: output.hpp:65