converter.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Aldebaran
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef CONVERTER_HPP
19 #define CONVERTER_HPP
20 
21 #include <string>
22 
23 #include <boost/make_shared.hpp>
24 #include <boost/shared_ptr.hpp>
25 
26 #include <ros/ros.h>
28 
29 namespace naoqi
30 {
31 namespace converter
32 {
33 
34 
42 class Converter
43 {
44 
45 public:
46 
50  template<typename T>
51  Converter( T conv ):
52  convPtr_( boost::make_shared<ConverterModel<T> >(conv) )
53  {}
54 
59  std::string name() const
60  {
61  return convPtr_->name();
62  }
63 
68  float frequency() const
69  {
70  return convPtr_->frequency();
71  }
72 
73  void reset()
74  {
75  convPtr_->reset();
76  }
77 
78  void callAll( const std::vector<message_actions::MessageAction>& actions )
79  {
80  if ( actions.size() > 0 )
81  {
82  convPtr_->callAll(actions);
83  }
84 
85  ros::Time after = ros::Time::now();
86  lapse_time = after - before;
87  before = after;
88  }
89 
91  {
92  return lapse_time;
93  }
94 
95  friend bool operator==( const Converter& lhs, const Converter& rhs )
96  {
97  // decision made for OR-comparison since we want to be more restrictive
98  if ( lhs.name() == rhs.name() )
99  return true;
100  return false;
101  }
102 
103 private:
104 
107 
112  {
113  virtual ~ConverterConcept(){}
114  virtual std::string name() const = 0;
115  virtual float frequency() const = 0;
116  virtual void reset() = 0;
117  virtual void callAll( const std::vector<message_actions::MessageAction>& actions ) = 0;
118  };
119 
120 
124  template<typename T>
126  {
127  ConverterModel( const T& other ):
128  converter_( other )
129  {}
130 
131  std::string name() const
132  {
133  return converter_->name();
134  }
135 
136  float frequency() const
137  {
138  return converter_->frequency();
139  }
140 
141  void reset()
142  {
143  converter_->reset();
144  }
145 
146  void callAll( const std::vector<message_actions::MessageAction>& actions )
147  {
148  converter_->callAll( actions );
149  }
150 
152  };
153 
155 
156 }; // class converter
157 
158 } //converter
159 } //naoqi
160 
161 #endif
Converter concept interface.
Definition: converter.hpp:42
void callAll(const std::vector< message_actions::MessageAction > &actions)
Definition: converter.hpp:146
std::string name() const
getting the descriptive name for this converter instance
Definition: converter.hpp:59
ros::Duration lapseTime() const
Definition: converter.hpp:90
virtual std::string name() const =0
Converter(T conv)
Constructor for converter interface.
Definition: converter.hpp:51
float frequency() const
getting the assigned frequency of this converter instance
Definition: converter.hpp:68
void callAll(const std::vector< message_actions::MessageAction > &actions)
Definition: converter.hpp:78
virtual void callAll(const std::vector< message_actions::MessageAction > &actions)=0
static Time now()
boost::shared_ptr< ConverterConcept > convPtr_
Definition: converter.hpp:154
friend bool operator==(const Converter &lhs, const Converter &rhs)
Definition: converter.hpp:95


naoqi_driver
Author(s): Karsten Knese
autogenerated on Sat Feb 15 2020 03:24:26