charon-core  0.3.1
ForStatement.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2012 Gerald Mwangi
2  Copyright (C) 2012 Michael Baron
3 
4  This file is part of Charon.
5 
6  Charon is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Charon is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with Charon. If not, see <http://www.gnu.org/licenses/>.
18 */
29 #include "../include/charon-core/ForStatement.h"
30 
31 #define INVALID_VALUE -1000
32 
33 ForStatement::ForStatement(const std::string& name) :
35  "ForStatement", name,
36  "<h2>Statement module to be used in counting loops</h2><br>"
37  "Statement module to be used in loops. This plugin is intended "
38  "for loops (e.g. WhileGroup). It interfaces the loop depending "
39  "on its counter value."
40  )
41 {
42  ParameteredObject::_setTags("charon-core") ;
43 
45  initialValue, "initialValue", "initial value", "double" );
47  incrementValue, "incrementValue", "increment value", "double" );
49  finalValue, "finalValue", "final value", "double" );
51  currentValue, "currentValue",
52  "ForStatement to interface to the external loop",
53  "int");
54 
55  _currentValue = int(INVALID_VALUE);
56 }
57 
59  _initialValue = initialValue();
60  _incrementValue = incrementValue();
61  _finalValue = finalValue();
62 
63  if (_currentValue == INVALID_VALUE) _currentValue = _initialValue;
64  else _currentValue += _incrementValue;
65  currentValue() = _currentValue;
66 }
67 
68 void ForStatement::reset()
69 {
70  _currentValue = int(INVALID_VALUE);
71 }
72 
74 extern "C" forstatement_DECLDIR ParameteredObject*
75  create(const std::string& name, ParameteredObject::template_type) {
76  return new ForStatement(name);
77 }
78 
80 extern "C" forstatement_DECLDIR void destroy(ParameteredObject* b) {
81  delete b;
82 }
83 
85 extern "C" forstatement_DECLDIR ParameteredObject::build_type getBuildType() {
86 #ifdef _DEBUG
88 #else
90 #endif
91 }
92 
93 bool ForStatement::operator ()() const
94 {
95  return (_currentValue < _finalValue);
96 }
97 
forstatement_DECLDIR ParameteredObject::build_type getBuildType()
Report build configuration to prevent linking of incompatibel runtime libs.
forstatement_DECLDIR void destroy(ParameteredObject *b)
Deletes an instance of the plugin.
build_type
defined build type
template_type
Integer which represents a template type.
Base class for serializable objects.
Convenience file to iclude all ParameteredObject dependencies and Template functions.
InputSlot< double > initialValue
input slot for initial value
Definition: ForStatement.h:57
virtual void execute()
Update object.
void _setTags(const std::string &tags)
Register additional tag names for grouping ParameteredObjects.
the object was compiled in release mode
forstatement_DECLDIR ParameteredObject * create(const std::string &name, ParameteredObject::template_type)
Creates an instance of the plugin.
void _addInputSlot(Slot &slot, const std::string &name, const std::string &doc, const std::string &type="")
These functions needs to be called by the derived class in order to register all objects which can be...
OutputSlot< int > currentValue
output slot for current value
Definition: ForStatement.h:64
ForStatement module to be used in counting loops.
Definition: ForStatement.h:50
InputSlot< double > incrementValue
input slot for increment value
Definition: ForStatement.h:59
ForStatement(const std::string &name="")
default constructor
the object was compiled in debug mode
void _addOutputSlot(Slot &slot, const std::string &name, const std::string &doc, const std::string &type="")
Register output slot.
InputSlot< double > finalValue
input slot for final value
Definition: ForStatement.h:61