ConditionCheck.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarX::Core
19 * @author Kai Welke (welke _at_ kit _dot_ edu)
20 * @date 2011
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 
25 #pragma once
26 
28 
29 #include <ArmarXCore/interface/observers/VariantBase.h>
30 #include <ArmarXCore/interface/observers/ConditionCheckBase.h>
31 #include <ArmarXCore/interface/observers/ObserverInterface.h>
32 
35 
36 #include <string>
37 #include <memory>
38 #include <map>
39 
40 namespace armarx
41 {
42  using VariantTypeIdList = std::vector<VariantTypeId>;
43 
44  class ConditionCheck;
46 
57  virtual public ConditionCheckBase
58  {
59  public:
64 
68  ~ConditionCheck() override {}
69 
82  //using ChannelRegistry = std::unordered_map<std::string, armarx::ChannelRegistryEntry>;
83  using ChannelRegistry = armarx::ChannelRegistry;
84  virtual ConditionCheckPtr createInstance(const CheckConfiguration& configuration, const ChannelRegistry& channelRegistry);
85 
91  virtual ConditionCheck* clone()
92  {
93  return new ConditionCheck();
94  }
95 
99  void reset();
100 
108  void evaluateCondition(const DataFieldRegistry& dataFields);
109 
115  bool getFulFilled();
116 
117  friend std::ostream& operator<<(std::ostream& stream, const ConditionCheck& rhs)
118  {
119  // stream << ElementaryConditionPtr::dynamicCast(rhs.condition) << " = " << rhs.fulFilled;
120  return stream;
121  }
122 
123  friend std::ostream& operator<<(std::ostream& stream, const ConditionCheckPtr& rhs)
124  {
125  // stream << ElementaryConditionPtr::dynamicCast(rhs->condition) << " = " << rhs->fulFilled;
126  return stream;
127  }
128 
129  protected:
135  void setNumberParameters(int numberParameters);
136 
144  void addSupportedType(VariantTypeId dataFieldType = 0, ParameterTypeList parameterTypes = ParameterTypeList());
145 
153  const Variant& getParameter(int index);
154 
163  virtual bool evaluate(const StringVariantMap& dataFields)
164  {
165  return true;
166  }
167 
168  static ParameterTypeList createParameterTypeList(int numberTypes, ...);
169 
170  private:
171  void assureTypeSupported(const CheckConfiguration& configuration, VariantTypeId dataFieldType);
172 
173  bool firstEval;
174  };
175 }
176 namespace armarx::checks
177 {
178  class CheckBase;
179  using CheckBasePtr = std::shared_ptr<CheckBase>;
180  using CheckBaseConstPtr = std::shared_ptr<const CheckBase>;
181 
182  class CheckBase
183  {
184  public:
185  virtual ~CheckBase()
186  {
187  }
188  virtual const std::string& getCheckStr() const
189  {
190  return _checkStr;
191  }
192 
193  static CheckBasePtr create(const std::string& check)
194  {
195  return CheckBasePtr(new CheckBase(check));
196  }
197  private:
198  const std::string _checkStr;
199  CheckBase() {}
200  CheckBase(std::string check) : _checkStr(check) {}
201  };
202 
203 }
204 
205 #define ARMARX_CREATE_CHECK(OFFERER,NEWCHECK) namespace checks { namespace OFFERER { \
206  const CheckBaseConstPtr NEWCHECK = CheckBase::create(#NEWCHECK);\
207  }}
208 
209 extern template class ::IceInternal::Handle<::armarx::ConditionCheck>;
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::checks::CheckBaseConstPtr
std::shared_ptr< const CheckBase > CheckBaseConstPtr
Definition: ConditionCheck.h:180
armarx::StringVariantMap
std::map< std::string, Variant > StringVariantMap
Definition: Variant.h:748
armarx::checks::CheckBase::getCheckStr
virtual const std::string & getCheckStr() const
Definition: ConditionCheck.h:188
armarx::checks::CheckBase::create
static CheckBasePtr create(const std::string &check)
Definition: ConditionCheck.h:193
DataFieldIdentifier.h
armarx::ConditionCheck::evaluate
virtual bool evaluate(const StringVariantMap &dataFields)
Evaluate the condition based on the current data field values.
Definition: ConditionCheck.h:163
armarx::checks::CheckBasePtr
std::shared_ptr< CheckBase > CheckBasePtr
Definition: ConditionCheck.h:179
armarx::checks
Definition: ConditionCheck.h:176
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::ConditionCheck::clone
virtual ConditionCheck * clone()
Clones the current check.
Definition: ConditionCheck.h:91
armarx::ConditionCheck::operator<<
friend std::ostream & operator<<(std::ostream &stream, const ConditionCheck &rhs)
Definition: ConditionCheck.h:117
armarx::ConditionCheck::~ConditionCheck
~ConditionCheck() override
Destructor.
Definition: ConditionCheck.h:68
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:44
armarx::ConditionCheck::operator<<
friend std::ostream & operator<<(std::ostream &stream, const ConditionCheckPtr &rhs)
Definition: ConditionCheck.h:123
armarx::checks::CheckBase::~CheckBase
virtual ~CheckBase()
Definition: ConditionCheck.h:185
armarx::ConditionCheck
Definition: ConditionCheck.h:56
armarx::ConditionCheck::ChannelRegistry
armarx::ChannelRegistry ChannelRegistry
Creates a new ConditionCheck instance.
Definition: ConditionCheck.h:83
armarx::VariantTypeIdList
std::vector< VariantTypeId > VariantTypeIdList
Definition: ConditionCheck.h:42
ImportExport.h
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
Variant.h
armarx::checks::CheckBase
Definition: ConditionCheck.h:182
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28