diff --git a/src/liboncilla/Oncilla.cpp b/src/liboncilla/Oncilla.cpp index ac491dc..0e3e75a 100644 --- a/src/liboncilla/Oncilla.cpp +++ b/src/liboncilla/Oncilla.cpp @@ -1,100 +1,100 @@ /* * Oncilla.cpp * * Created on: 15 dec. 2011 * Author: Alexandre Tuleu, Arne Nordmann */ #include "Oncilla.h" #include namespace rci { namespace oncilla { ::rci::oncilla::Synchronizer::Ptr Oncilla::s_synchronizer; std::string Oncilla::nameOfLeg(Leg l){ static const char * legNames[NUM_LEGS + 1] = { "Left Fore", //LEFT_FORE "Right Fore", //RIGHT_FORE "Left Hind", //LEFT_HIND "Right Hind," //RIGHT_HIND "Undefined" }; //oncly consider index in range [0 NUM_LEGS], defaulting to NUM_LEGS if out of bound. int index((l < 0 ) ? NUM_LEGS : (l > NUM_LEGS ? NUM_LEGS : l)); return legNames[index]; } Oncilla::Oncilla(){ if(!s_synchronizer){ if(!d_backend){ BackendLoader bl; //we have to keep alive the pointer or dlclose() will be called once //We free him. Or we could add BackendLoader as a member of Oncilla // I prefer only to have the Object creator interface. d_backend = bl.SuitableBackend(); } s_synchronizer = d_backend->CreateSynchronizer(); init(); } } Oncilla::~Oncilla() { } void Oncilla::init() { d_L0s.reserve(4); d_L1s.reserve(4); d_L2s.reserve(4); d_L3s.reserve(4); - for(rci::oncilla::Leg l = LEFT_FORE; l < NUM_LEGS; ++l){ + LIBONCILLA_FOREACH_LEG(l){ d_L0s.push_back(d_backend->CreateL0(l,Oncilla::nameOfLeg(l) + " Oncilla L0")); d_L1s.push_back(d_backend->CreateL1(l,Oncilla::nameOfLeg(l) + " Oncilla L1")); d_L2s.push_back(d_backend->CreateL2(l,Oncilla::nameOfLeg(l) + " Oncilla L2")); d_L3s.push_back(d_backend->CreateL3(l,Oncilla::nameOfLeg(l) + " Oncilla L3")); } d_trunk = d_backend->CreateTrunk(); } const L0::Ptr & Oncilla::getL0(Leg l) const { return this->d_L0s[l]; } const L1::Ptr & Oncilla::getL1(Leg l) const { return this->d_L1s[l]; } const L2::Ptr & Oncilla::getL2(Leg l) const { return this->d_L2s[l]; } const L3::Ptr & Oncilla::getL3(Leg l) const { return this->d_L3s[l]; } const Trunk::Ptr & Oncilla::getTrunk() const { return this->d_trunk; } const rci::oncilla::Synchronizer::Ptr & Oncilla::getSynchronizer() const { if(!s_synchronizer){ throw std::logic_error("Internal error : synchronizer seems unitialized" ", but it should never happen. Please report this bug."); } return this->s_synchronizer; } } } diff --git a/src/liboncilla/Supervisor.cpp b/src/liboncilla/Supervisor.cpp index b49a363..8105e57 100644 --- a/src/liboncilla/Supervisor.cpp +++ b/src/liboncilla/Supervisor.cpp @@ -1,28 +1,27 @@ /* * Supervisor.cpp * * Created on: Jan 21, 2013 * Author: tuleu */ #include "Supervisor.h" #include #include "Oncilla.h" namespace rci { namespace oncilla { Supervisor::Supervisor(OncillaBackend & backend) : d_l4s(4,SupervisorL4::Ptr()) , d_trunk(backend.CreateSupervisorTrunk()){ - for(rci::oncilla::Leg l = LEFT_FORE; - l < rci::oncilla::NUM_LEGS ; ++l){ + LIBONCILLA_FOREACH_LEG(l){ d_l4s[l] = backend.CreateSupervisorL4(l,Oncilla::nameOfLeg(l) + " Oncilla Supervised L4"); } } Supervisor::~Supervisor(){ // TODO Auto-generated destructor stub } } /* namespace oncilla */ } /* namespace rci */ diff --git a/src/liboncilla/common.h b/src/liboncilla/common.h index d4f8afd..dbaa974 100644 --- a/src/liboncilla/common.h +++ b/src/liboncilla/common.h @@ -1,27 +1,32 @@ /** * \file common.h * * \date Jun 28, 2012 * \author Alexandre Tuleu */ #ifndef LIBONCILLA_COMMON_H_ #define LIBONCILLA_COMMON_H_ namespace rci{ namespace oncilla{ enum Leg { LEFT_FORE = 0, RIGHT_FORE = 1, LEFT_HIND = 2, RIGHT_HIND = 3, NUM_LEGS = 4 }; } } +#define LIBONCILLA_FOREACH_LEG(var) \ + for(::rci::oncilla::Leg var = ::rci::oncilla::LEFT_FORE;\ + var < ::rci::oncilla::NUM_LEGS;\ + var = (::rci::oncilla::Leg)(var + 1)) + #endif // LIBONCILLA_COMMON_H_ diff --git a/src/liboncilla/exceptions/UnavailableInterfaceError.cpp b/src/liboncilla/exceptions/UnavailableInterfaceError.cpp index cb8312e..aa88015 100644 --- a/src/liboncilla/exceptions/UnavailableInterfaceError.cpp +++ b/src/liboncilla/exceptions/UnavailableInterfaceError.cpp @@ -1,73 +1,73 @@ /* * UnavailableInterfaceError.cpp * * Created on: Jan 21, 2013 * Author: tuleu */ #include "UnavailableInterfaceError.h" namespace rci { namespace oncilla { UnavailableInterfaceError::UnavailableInterfaceError( const std::string& reason , const std::string& component , const std::string& methodName , const std::string& className , const std::string& notice) : std::runtime_error(FormatStringFromArgs(reason,component,methodName,className,notice)) , d_component(component) ,d_reason(reason) ,d_class(className) ,d_method(methodName) ,d_notice(notice){ } -UnavailableInterfaceError::~UnavailableInterfaceError(){ +UnavailableInterfaceError::~UnavailableInterfaceError() throw (){ } const std::string& UnavailableInterfaceError::Reason() const{ return d_reason; } const std::string& UnavailableInterfaceError::Component() const{ return d_component; } const std::string& UnavailableInterfaceError::Class() const{ return d_class; } const std::string& UnavailableInterfaceError::Method() const{ return d_method; } std::string UnavailableInterfaceError::FullMethodName() const{ return (d_class.empty() ? (d_method + "()") : (d_class + "::" + d_method + "()")); } const std::string& UnavailableInterfaceError::Notice() const{ return d_notice; } std::string UnavailableInterfaceError::FormatStringFromArgs( const std::string& reason , const std::string& component , const std::string& methodName , const std::string& className , const std::string& notice){ std::string res("Interface '"); if(className.empty()){ res += methodName + "()'"; } else { res += className + "::" + methodName + "()'"; } res += " is not available in " + component + " reason :\n" + reason; if(!notice.empty()){ res += "\n" + notice; } return res; } } /* namespace oncilla */ } /* namespace rci */