humoto
leftright.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4  @copyright 2014-2017 INRIA. Licensed under the Apache License, Version 2.0.
5  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
6 
7  @brief
8 */
9 
10 #pragma once
11 
12 namespace humoto
13 {
14  /**
15  * @brief This enum is used to handle symmetric objects (left / right foot etc).
16  */
18  {
19  public:
20  enum Type
21  {
22  UNDEFINED = 0,
23  LEFT = 1,
24  RIGHT = 2,
25  COUNT = 2
26  };
27 
28 
29  public:
30  /**
31  * @brief Exchange left and right
32  *
33  * @param[in] left_or_right LEFT or RIGHT
34  *
35  * @return RIGHT or LEFT
36  */
37  static Type invert(const Type left_or_right)
38  {
39  switch(left_or_right)
40  {
41  case LEFT:
42  return(RIGHT);
43  case RIGHT:
44  return(LEFT);
45  default:
46  HUMOTO_THROW_MSG("Non-invertible type.");
47  }
48  }
49  };
50 
51 
52  /**
53  * @brief Container for two symmetric objects
54  *
55  * @tparam t_Data type of the objects
56  */
57  template<typename t_Data>
59  {
60  private:
61  t_Data data[LeftOrRight::COUNT];
62 
63  public:
64  /**
65  * @brief Access the element
66  *
67  * @param[in] left_or_right
68  *
69  * @return data object
70  */
71  t_Data & operator[](const LeftOrRight::Type left_or_right)
72  {
73  HUMOTO_ASSERT((left_or_right == LeftOrRight::LEFT) || (left_or_right == LeftOrRight::RIGHT), "Must be left or right.");
74  return(data[left_or_right - 1]);
75  }
76 
77 
78  /**
79  * @copydoc operator[]
80  */
81  const t_Data & operator[](const LeftOrRight::Type left_or_right) const
82  {
83  HUMOTO_ASSERT((left_or_right == LeftOrRight::LEFT) || (left_or_right == LeftOrRight::RIGHT), "Must be left or right.");
84  return(data[left_or_right - 1]);
85  }
86 
87 
88  /**
89  * @brief Get/set/copy left or right object
90  *
91  * @return data object
92  */
93  t_Data & getLeft() { return(operator[](LeftOrRight::LEFT)); }
94 
95  /// @copydoc getLeft
96  const t_Data & getLeft() const { return(operator[](LeftOrRight::LEFT)); }
97 
98  /// @copydoc getLeft
99  t_Data & getRight() { return(operator[](LeftOrRight::RIGHT)); }
100 
101  /// @copydoc getLeft
102  const t_Data & getRight() const { return(operator[](LeftOrRight::RIGHT)); }
103 
104  /// @copydoc getLeft
105  void setLeft(const t_Data &data) { operator[](LeftOrRight::LEFT) = data; }
106 
107  /// @copydoc getLeft
108  void setRight(const t_Data &data) { operator[](LeftOrRight::RIGHT) = data; }
109 
110  /// @copydoc getLeft
111  void copyLeft(const LeftRightContainer<t_Data> &copy_from) { operator[](LeftOrRight::LEFT) = copy_from[LeftOrRight::LEFT]; }
112 
113  /// @copydoc getLeft
114  void copyRight(const LeftRightContainer<t_Data> &copy_from) { operator[](LeftOrRight::RIGHT) = copy_from[LeftOrRight::RIGHT]; }
115  };
116 }
#define HUMOTO_LOCAL
Definition: export_import.h:26
void copyRight(const LeftRightContainer< t_Data > &copy_from)
Get/set/copy left or right object.
Definition: leftright.h:114
#define HUMOTO_ASSERT(condition, message)
Container for two symmetric objects.
Definition: leftright.h:58
#define HUMOTO_THROW_MSG(s)
HUMOTO_THROW_MSG throws an error message concatenated with the name of the function (if supported)...
void setRight(const t_Data &data)
Get/set/copy left or right object.
Definition: leftright.h:108
t_Data & operator[](const LeftOrRight::Type left_or_right)
Access the element.
Definition: leftright.h:71
This enum is used to handle symmetric objects (left / right foot etc).
Definition: leftright.h:17
void setLeft(const t_Data &data)
Get/set/copy left or right object.
Definition: leftright.h:105
void copyLeft(const LeftRightContainer< t_Data > &copy_from)
Get/set/copy left or right object.
Definition: leftright.h:111
The root namespace of HuMoTo.
Definition: config.h:12
const t_Data & getRight() const
Get/set/copy left or right object.
Definition: leftright.h:102
t_Data & getRight()
Get/set/copy left or right object.
Definition: leftright.h:99
const t_Data & getLeft() const
Get/set/copy left or right object.
Definition: leftright.h:96
t_Data & getLeft()
Get/set/copy left or right object.
Definition: leftright.h:93
const t_Data & operator[](const LeftOrRight::Type left_or_right) const
Access the element.
Definition: leftright.h:81
static Type invert(const Type left_or_right)
Exchange left and right.
Definition: leftright.h:37