Wolframe, 0.0.3

programInstance.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_VM_PROGRAM_INSTANCE_HPP_INCLUDED
36 #define _DATABASE_VM_PROGRAM_INSTANCE_HPP_INCLUDED
40 #include "database/vm/output.hpp"
44 #include "types/variant.hpp"
45 #include <string>
46 #include <vector>
47 #include <map>
48 
49 namespace _Wolframe {
50 namespace db {
51 namespace vm {
53 class Program;
54 
58  :public InstructionSet
59 {
60 public:
63  struct LogTraceContext;
64  typedef void (*LogTraceCallBack)( const LogTraceContext* prgcontext, unsigned int ip_);
65 
66 public:
69  :m_db_stm(0)
70  ,m_ip(0)
71  ,m_cond(false)
74  {}
78  ,m_db_stm(o.m_db_stm)
79  ,m_ip(o.m_ip)
80  ,m_cond(o.m_cond)
81  ,m_stack(o.m_stack)
82  ,m_output(o.m_output)
85  {}
86 
88  ProgramInstance( const ProgramImage& program_, TransactionExecStatemachine* db_stm_, LogTraceCallBack logTraceCallBack_=0, const LogTraceContext* logTraceContext_=0);
89 
91  bool execute();
93  const OutputR& output() const {return m_output;}
95  const DatabaseError* lastError() const {return &m_lastError;}
97  unsigned int ip() const {return m_ip;}
98 
99 private:
102  struct ResultFlags
103  {
104  bool is_first;
105  bool unique;
106  bool nonempty;
107 
112  ResultFlags( bool unique_=false, bool nonempty_=false)
113  :is_first(true),unique(unique_),nonempty(nonempty_){}
115  void clear()
116  {
117  is_first = true;
118  unique = false;
119  nonempty = false;
120  }
122  void init( bool unique_, bool nonempty_)
123  {
124  is_first = true;
125  unique = unique_;
126  nonempty = nonempty_;
127  }
129  bool touched()
130  {
131  bool rt = !is_first;
132  is_first = false;
133  return rt;
134  }
135  };
136 
140  {
143  :m_return_ip(0)
144  ,m_bindidx(0)
145  ,m_hintidx(0)
146  {}
148  StackElement( Address return_ip_, const ValueTupleSetR& parameter_)
149  :m_return_ip(return_ip_)
150  ,m_bindidx(0)
151  ,m_hintidx(0)
152  ,m_parameter(parameter_)
153  {}
157  ,m_bindidx(o.m_bindidx)
158  ,m_hintidx(o.m_hintidx)
167  {}
168 
170  std::size_t m_bindidx;
175  std::map<ArgumentIndex,ValueTupleSetR> m_resultMap;
180  };
181 
182 private:
185  const types::Variant& constArgument( ArgumentIndex idx) const;
186  const std::string& statementArgument( ArgumentIndex argidx) const;
187  const std::string& tagnameArgument( ArgumentIndex argidx) const;
189  ArgumentIndex columnIndex( const ValueTupleSet* valueset, ArgumentIndex nameidx) const;
190  const types::Variant& selectedArgument( ArgumentIndex idx) const;
191  const types::Variant& iteratorArgument( ArgumentIndex idx) const;
192  void initValueIteraror( const ValueTupleSetR& valueset);
193  void initResult( const ValueTupleSetR& resultset);
194  void printIteratorColumn();
195  ValueTupleSetR fetchDatabaseResult( std::size_t nofColumns);
196  void setDatabaseError();
197 
198 private:
203  bool m_cond;
204  std::vector<StackElement> m_stack;
209 };
210 
211 }}}//namespace
212 #endif
213 
Interface for program executing database transactions.
void initValueIteraror(const ValueTupleSetR &valueset)
bool nonempty
NONEMPTY flag.
Definition: programInstance.hpp:106
State stack element of the virtual machine executing a transaction.
Definition: programInstance.hpp:139
const LogTraceContext * m_logTraceContext
Context for 'm_logTraceCallBack'.
Definition: programInstance.hpp:208
std::vector< StackElement > m_stack
execution stack
Definition: programInstance.hpp:204
ValueTupleSetR keptResult(ArgumentIndex idx) const
Class for describing database errors.
Definition: databaseError.hpp:46
std::size_t m_bindidx
current bind index
Definition: programInstance.hpp:170
std::map< ArgumentIndex, ValueTupleSetR > m_resultMap
KEEP result map.
Definition: programInstance.hpp:175
ArgumentIndex columnIndex(const ValueTupleSet *valueset, ArgumentIndex nameidx) const
StackElement(Address return_ip_, const ValueTupleSetR &parameter_)
Constructor.
Definition: programInstance.hpp:148
Defines the structure holding a set of tuples (database results, transaction input, suroutine parameters) and providing an iterator on it.
Address m_return_ip
IP to set o RETURN.
Definition: programInstance.hpp:169
Defines the instruction set of the virtual machine defining database transactions.
const std::string & statementArgument(ArgumentIndex argidx) const
Structure for addressing the parameters passed to a subroutine by name.
Definition: subroutineFrame.hpp:50
bool touched()
Get and set of the first result flag.
Definition: programInstance.hpp:129
bool execute()
Execute the program.
ValueTupleSetR m_valueSet
currently iterated value set
Definition: programInstance.hpp:177
Defines the output of a virtual machine for database transactions.
Defines a structure for addressing the parameters passed to a subroutine by name. ...
Error class for databases.
Iterator on this set of value tuples.
Definition: valueTupleSet.hpp:66
boost::shared_ptr< ValueTupleSet > ValueTupleSetR
Definition: valueTupleSet.hpp:218
Callback context structure for logging VM instructions in transaction execution.
ValueTupleSetR m_selectedSet
selected value set
Definition: programInstance.hpp:176
boost::uint32_t Address
Address in program code.
Definition: instructionSet.hpp:326
Address m_ip
instruction pointer
Definition: programInstance.hpp:201
ValueTupleSet::const_iterator m_valueEnd
end of value set
Definition: programInstance.hpp:179
ResultFlags(const ResultFlags &o)
Copy constructor.
Definition: programInstance.hpp:109
OutputR m_output
output
Definition: programInstance.hpp:205
void clear()
Reset flags.
Definition: programInstance.hpp:115
ProgramImage m_program
image of program to execute
Definition: programInstance.hpp:199
boost::uint32_t ArgumentIndex
Index of an argument.
Definition: instructionSet.hpp:324
ValueTupleSetR fetchDatabaseResult(std::size_t nofColumns)
Forward declaration.
Definition: variant.hpp:65
ArgumentIndex m_hintidx
current database statement hint index
Definition: programInstance.hpp:171
TransactionExecStatemachine * m_db_stm
engine to process database instructions
Definition: programInstance.hpp:200
const types::Variant & iteratorArgument(ArgumentIndex idx) const
Set of tuples (database results, transaction input, etc.)
Definition: valueTupleSet.hpp:50
LogTraceCallBack m_logTraceCallBack
NULL or callback procedure for logging execution that is be called after every instruction executed...
Definition: programInstance.hpp:207
Variant value type.
ResultFlags(bool unique_=false, bool nonempty_=false)
Constructor.
Definition: programInstance.hpp:112
void(* LogTraceCallBack)(const LogTraceContext *prgcontext, unsigned int ip_)
Definition: programInstance.hpp:64
DatabaseError m_lastError
last database error reported
Definition: programInstance.hpp:206
boost::shared_ptr< Output > OutputR
Definition: output.hpp:131
StackElement(const StackElement &o)
Copy constructor.
Definition: programInstance.hpp:155
SubroutineFrame m_subroutine_frame
prepared subroutine call parameter structure
Definition: programInstance.hpp:202
ResultFlags m_resultFlags
conditions to be meet for each element of the next result
Definition: programInstance.hpp:174
types::Variant loopcntArgument() const
bool unique
UNIQUE flag.
Definition: programInstance.hpp:105
const types::Variant & selectedArgument(ArgumentIndex idx) const
const OutputR & output() const
Get the output of the executed program.
Definition: programInstance.hpp:93
Flags defined in the database command between DO and the statement (NONEMPTY,UNIQUE) ...
Definition: programInstance.hpp:102
void init(bool unique_, bool nonempty_)
Initialize flags.
Definition: programInstance.hpp:122
Interface to the database transaction execution statemechine.
Definition: transactionExecStatemachine.hpp:49
ValueTupleSetR m_lastResult
last call result
Definition: programInstance.hpp:173
ValueTupleSetR m_parameter
parameter structure
Definition: programInstance.hpp:172
Enumeration of instructions for the transaction VM with some static functions on them.
Definition: instructionSet.hpp:50
StackElement()
Default constructor.
Definition: programInstance.hpp:142
bool is_first
true, if there has been no result set added to the set (result is created)
Definition: programInstance.hpp:104
unsigned int ip() const
Get the current IP of program execution (instruction pointer)
Definition: programInstance.hpp:97
void initResult(const ValueTupleSetR &resultset)
Instance of a program with statevariables.
Definition: programInstance.hpp:57
const types::Variant & constArgument(ArgumentIndex idx) const
Interface to the standard database transaction execution statemechine.
ValueTupleSet::const_iterator m_valueIter
iterator on value set
Definition: programInstance.hpp:178
Program addressing only flat data structures and with symbolic information stripped out...
Definition: programImage.hpp:54
ProgramInstance()
Default constructor.
Definition: programInstance.hpp:68
bool m_cond
current condition flag for conditional execution ('InstructionSet::CondCode')
Definition: programInstance.hpp:203
ProgramInstance(const ProgramInstance &o)
Copy constructor.
Definition: programInstance.hpp:76
const std::string & tagnameArgument(ArgumentIndex argidx) const
ValueTupleSetR tupleSet(ArgumentIndex idx) const
const DatabaseError * lastError() const
Get the last error of the executed program.
Definition: programInstance.hpp:95