- 3.0.2 rigid body dynamics module.
RBDDataMap.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
11 #ifndef _RBDDATAMAP_H_
12 #define _RBDDATAMAP_H_
13 
14 #include <cstring>
15 
16 namespace ct {
17 namespace rbd {
18 
22 template <typename T, size_t N>
24 {
25 private:
26  T data[N];
27 
28 public:
30  RBDDataMap(const T& defaultValue);
31  RBDDataMap(const RBDDataMap& rhs);
32  RBDDataMap& operator=(const RBDDataMap& rhs);
33  RBDDataMap& operator=(const T& rhs);
34  T& operator[](size_t which);
35  const T& operator[](size_t which) const;
36 
37 private:
38  void copydata(const RBDDataMap& rhs);
39  void assigndata(const T& commonValue);
40 };
41 
42 template <typename T, size_t N>
43 inline RBDDataMap<T, N>::RBDDataMap(const T& value)
44 {
45  assigndata(value);
46 }
47 
48 template <typename T, size_t N>
50 {
51  copydata(rhs);
52 }
53 
54 template <typename T, size_t N>
56 {
57  if (&rhs != this)
58  {
59  copydata(rhs);
60  }
61  return *this;
62 }
63 
64 template <typename T, size_t N>
66 {
67  assigndata(value);
68  return *this;
69 }
70 
71 template <typename T, size_t N>
72 inline T& RBDDataMap<T, N>::operator[](size_t l)
73 {
74  return data[l];
75 }
76 
77 template <typename T, size_t N>
78 inline const T& RBDDataMap<T, N>::operator[](size_t l) const
79 {
80  return data[l];
81 }
82 
83 template <typename T, size_t N>
84 inline void RBDDataMap<T, N>::copydata(const RBDDataMap& rhs)
85 {
86  for (size_t id = 0; id < N; ++id)
87  data[id] = rhs[id];
88 }
89 
90 template <typename T, size_t N>
91 inline void RBDDataMap<T, N>::assigndata(const T& value)
92 {
93  for (size_t id = 0; id < N; ++id)
94  data[id] = value;
95 }
96 
97 template <typename T, size_t N>
98 inline std::ostream& operator<<(std::ostream& out, const RBDDataMap<T, N>& map)
99 {
100  for (size_t id = 0; id < N; ++id)
101  {
102  out << "[" << id << "] = " << map[id] << " ";
103  }
104  return out;
105 }
106 
107 } // namespace rbd
108 } // namespace ct
109 
110 #endif /* _RBDDATAMAP_H_ */
A very simple container to associate N generic data item T.
Definition: RBDDataMap.h:23
T & operator[](size_t which)
Definition: RBDDataMap.h:72
RBDDataMap()
Definition: RBDDataMap.h:29
RBDDataMap & operator=(const RBDDataMap &rhs)
Definition: RBDDataMap.h:55