Wolframe, 0.0.3

subroutineFrame.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_SUBROUTINE_FRAME_HPP_INCLUDED
36 #define _DATABASE_VIRTUAL_MACHINE_SUBROUTINE_FRAME_HPP_INCLUDED
38 #include "types/variant.hpp"
39 #include <string>
40 #include <vector>
41 #include <cstdlib>
42 #include <boost/shared_ptr.hpp>
43 
44 namespace _Wolframe {
45 namespace db {
46 namespace vm {
47 
51 {
52 public:
56  explicit SubroutineFrame( const std::vector<std::string>& paramnames_)
57  :m_paramnames(paramnames_){}
62 
64  void clear()
65  {
66  m_paramnames.clear();
67  m_paramvalues.clear();
68  }
69 
71  void init( const std::vector<std::string>& paramnames_)
72  {
73  clear();
74  m_paramnames = paramnames_;
75  }
76 
78  void push( const types::Variant& p)
79  {
80  if (m_paramvalues.size() >= m_paramnames.size())
81  {
82  throw std::runtime_error("too many parameters passed to subroutine");
83  }
84  m_paramvalues.push_back( p);
85  }
89  {
90  if (m_paramvalues.size() < m_paramnames.size())
91  {
92  throw std::runtime_error("too few parameters passed to subroutine");
93  }
95  rt->push( m_paramvalues);
96  return rt;
97  }
98 
99 private:
100  std::vector<std::string> m_paramnames;
101  std::vector<types::Variant> m_paramvalues;
102 };
103 
104 }}}//namespace
105 #endif
106 
Defines the structure holding a set of tuples (database results, transaction input, suroutine parameters) and providing an iterator on it.
void clear()
Clear current subroutine frame (start initialization)
Definition: subroutineFrame.hpp:64
ValueTupleSetR getParameters() const
Get the parameters of a called subroutine as value tuple set.
Definition: subroutineFrame.hpp:88
Structure for addressing the parameters passed to a subroutine by name.
Definition: subroutineFrame.hpp:50
boost::shared_ptr< ValueTupleSet > ValueTupleSetR
Definition: valueTupleSet.hpp:218
void init(const std::vector< std::string > &paramnames_)
Initialize parameter names by the parameters defined for a subroutine.
Definition: subroutineFrame.hpp:71
Forward declaration.
Definition: variant.hpp:65
Set of tuples (database results, transaction input, etc.)
Definition: valueTupleSet.hpp:50
SubroutineFrame(const std::vector< std::string > &paramnames_)
Constructor.
Definition: subroutineFrame.hpp:56
Variant value type.
std::vector< std::string > m_paramnames
parameter names
Definition: subroutineFrame.hpp:100
SubroutineFrame(const SubroutineFrame &o)
Copy constructor.
Definition: subroutineFrame.hpp:59
SubroutineFrame()
Default constructor.
Definition: subroutineFrame.hpp:54
void push(const types::Variant &p)
Push a parameter value (in the order of the parameter names)
Definition: subroutineFrame.hpp:78
std::vector< types::Variant > m_paramvalues
parameter values (parallel array to m_paramnames)
Definition: subroutineFrame.hpp:101