ocra-recipes
Doxygen documentation for the ocra-recipes repository
AbilitySet.h
Go to the documentation of this file.
1 #ifndef _OCRA_OPTIM_ABILITY_SET_H_
2 #define _OCRA_OPTIM_ABILITY_SET_H_
3 
4 #ifdef WIN32
5 # pragma once
6 #endif
7 
8 #include "ocra/optim/IFunction.h"
9 
10 #include <vector>
11 
12 namespace ocra
13 {
19  class AbilitySet
20  {
21  protected:
23  AbilitySet(const std::vector<bool>& usageSet)
24  :_usageSet(usageSet)
25  {
26  ocra_assert(usageSet.size() == PROP_NUMBER && "given usage vector has not the proper size");
27  _usageSet[FUN_VALUE] = true;
28  }
29 
30 
40  )
41  : _usageSet(PROP_NUMBER, false)
42  {
43  _usageSet[FUN_VALUE] = true;
44  _usageSet[prop0] = true;
45  _usageSet[prop1] = true;
46  }
47 
48 
50  eFunctionAbility prop0,
51  eFunctionAbility prop1,
52  eFunctionAbility prop2,
55  )
56  : _usageSet(PROP_NUMBER, false)
57  {
58  _usageSet[FUN_VALUE] = true;
59 
60  const eFunctionAbility props[] = { prop0, prop1, prop2, prop3, prop4 };
61  for (int i=0; i<5; ++i)
62  _usageSet[props[i]] = true;
63  }
64 
66  eFunctionAbility prop0,
67  eFunctionAbility prop1,
68  eFunctionAbility prop2,
69  eFunctionAbility prop3,
70  eFunctionAbility prop4,
71  eFunctionAbility prop5,
76  )
77  : _usageSet(PROP_NUMBER, false)
78  {
79  _usageSet[FUN_VALUE] = true;
80 
81  const eFunctionAbility props[] = { prop0, prop1, prop2, prop3, prop4, prop5, prop6, prop7, prop8, prop9 };
82  for (int i=0; i<10; ++i)
83  _usageSet[props[i]] = true;
84  }
86 
87 
89  const std::vector<bool>& getUsageSet() const
90  {
91  return _usageSet;
92  }
93 
94  public:
97  {
98  _usageSet[prop] = true;
99  return *this;
100  }
101 
104  {
105  _usageSet[prop] = false;
106  return *this;
107  }
108 
109  private:
110  std::vector<bool> _usageSet;
111 
114  friend AbilitySet operator& (const AbilitySet a1, const AbilitySet a2);
115  friend AbilitySet operator| (const AbilitySet a1, const AbilitySet a2);
117  };
118 
119  inline AbilitySet operator& (const AbilitySet a1, const AbilitySet a2)
120  {
121  size_t n = a1.getUsageSet().size();
122  ocra_assert(n == a2.getUsageSet().size() && "the sets must have the same size");
123  std::vector<bool> props;
124  props.reserve(n);
125  for (size_t i=0; i<n; ++i)
126  props.push_back(a1.getUsageSet()[i] && a2.getUsageSet()[i]);
127  return AbilitySet(props);
128  }
129 
130  inline AbilitySet operator| (const AbilitySet a1, const AbilitySet a2)
131  {
132  size_t n = a1.getUsageSet().size();
133  ocra_assert(n == a2.getUsageSet().size() && "the sets must have the same size");
134  std::vector<bool> props;
135  props.reserve(n);
136  for (size_t i=0; i<n; ++i)
137  props.push_back(a1.getUsageSet()[i] || a2.getUsageSet()[i]);
138  return AbilitySet(props);
139  }
140 }
141 
142 
143 
144 #endif //_OCRA_OPTIM_ABILITY_SET_H_
145 
146 // cmake:sourcegroup=Function
friend AbilitySet operator|(const AbilitySet a1, const AbilitySet a2)
Definition: AbilitySet.h:130
eFunctionAbility
Enumeration of the computation abilities of a ocra function.
Definition: IFunction.h:64
AbilitySet(eFunctionAbility prop0, eFunctionAbility prop1, eFunctionAbility prop2, eFunctionAbility prop3, eFunctionAbility prop4, eFunctionAbility prop5, eFunctionAbility prop6=FUN_VALUE, eFunctionAbility prop7=FUN_VALUE, eFunctionAbility prop8=FUN_VALUE, eFunctionAbility prop9=FUN_VALUE)
Definition: AbilitySet.h:65
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
AbilitySet(eFunctionAbility prop0=FUN_VALUE, eFunctionAbility prop1=FUN_VALUE)
Definition: AbilitySet.h:37
AbilitySet & add(eFunctionAbility prop)
Definition: AbilitySet.h:96
friend AbilitySet operator&(const AbilitySet a1, const AbilitySet a2)
Definition: AbilitySet.h:119
const std::vector< bool > & getUsageSet() const
Definition: AbilitySet.h:89
AbilitySet(eFunctionAbility prop0, eFunctionAbility prop1, eFunctionAbility prop2, eFunctionAbility prop3=FUN_VALUE, eFunctionAbility prop4=FUN_VALUE)
Definition: AbilitySet.h:49
#define ocra_assert(ocra_expression)
Definition: ocra_assert.h:45
Declaration file of the IFunction interface.
AbilitySet(const std::vector< bool > &usageSet)
Definition: AbilitySet.h:23