converter.hpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2015 Aldebaran
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  *
00016 */
00017 
00018 #ifndef CONVERTER_HPP
00019 #define CONVERTER_HPP
00020 
00021 #include <string>
00022 
00023 #include <boost/make_shared.hpp>
00024 #include <boost/shared_ptr.hpp>
00025 
00026 #include <ros/ros.h>
00027 #include <naoqi_driver/message_actions.h>
00028 
00029 namespace naoqi
00030 {
00031 namespace converter
00032 {
00033 
00034 
00042 class Converter
00043 {
00044 
00045 public:
00046 
00050   template<typename T>
00051   Converter( T conv ):
00052     convPtr_( boost::make_shared<ConverterModel<T> >(conv) )
00053   {}
00054 
00059   std::string name() const
00060   {
00061     return convPtr_->name();
00062   }
00063 
00068   float frequency() const
00069   {
00070     return convPtr_->frequency();
00071   }
00072 
00073   void reset()
00074   {
00075     convPtr_->reset();
00076   }
00077 
00078   void callAll( const std::vector<message_actions::MessageAction>& actions )
00079   {
00080     if ( actions.size() > 0 )
00081     {
00082       convPtr_->callAll(actions);
00083     }
00084 
00085     ros::Time after = ros::Time::now();
00086     lapse_time = after - before;
00087     before = after;
00088   }
00089 
00090   ros::Duration lapseTime() const
00091   {
00092     return lapse_time;
00093   }
00094 
00095   friend bool operator==( const Converter& lhs, const Converter& rhs )
00096   {
00097     // decision made for OR-comparison since we want to be more restrictive
00098     if ( lhs.name() == rhs.name() )
00099       return true;
00100     return false;
00101   }
00102 
00103 private:
00104 
00105   ros::Time before;
00106   ros::Duration lapse_time;
00107 
00111   struct ConverterConcept
00112   {
00113     virtual ~ConverterConcept(){}
00114     virtual std::string name() const = 0;
00115     virtual float frequency() const = 0;
00116     virtual void reset() = 0;
00117     virtual void callAll( const std::vector<message_actions::MessageAction>& actions ) = 0;
00118   };
00119 
00120 
00124   template<typename T>
00125   struct ConverterModel : public ConverterConcept
00126   {
00127     ConverterModel( const T& other ):
00128       converter_( other )
00129     {}
00130 
00131     std::string name() const
00132     {
00133       return converter_->name();
00134     }
00135 
00136     float frequency() const
00137     {
00138       return converter_->frequency();
00139     }
00140     
00141     void reset()
00142     {
00143       converter_->reset();
00144     }
00145 
00146     void callAll( const std::vector<message_actions::MessageAction>& actions )
00147     {
00148       converter_->callAll( actions );
00149     }
00150 
00151     T converter_;
00152   };
00153 
00154   boost::shared_ptr<ConverterConcept> convPtr_;
00155 
00156 }; // class converter
00157 
00158 } //converter
00159 } //naoqi
00160 
00161 #endif


naoqi_driver
Author(s): Karsten Knese
autogenerated on Tue Jul 9 2019 03:21:56