Commit c4ad123a authored by FBerendsen's avatar FBerendsen
Browse files

COMP: enable c++11 for gcc and other fixes

parent d57de45a
PROJECT(componenthandshake) PROJECT(componenthandshake)
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
cmake_policy(VERSION 2.8) cmake_policy(VERSION 2.8)
ADD_DEFINITIONS(
-std=c++11
)
#set(CMAKE_CXX_STANDARD 11)
file(GLOB componenthandshake_SRC file(GLOB componenthandshake_SRC
"*.h" "*.h"
"*.cxx" "*.cxx"
......
#ifndef ComponentBase_h #ifndef ComponentBase_h
#define ComponentBase_h #define ComponentBase_h
#include <iostream>
#include <cstring>
namespace elx namespace elx
{ {
class ComponentBase { class ComponentBase {
......
...@@ -18,12 +18,12 @@ GDOptimizer4thPartyComponent::~GDOptimizer4thPartyComponent() ...@@ -18,12 +18,12 @@ GDOptimizer4thPartyComponent::~GDOptimizer4thPartyComponent()
int GDOptimizer4thPartyComponent::ConnectFrom(const char * interfacename, ComponentBase* other) int GDOptimizer4thPartyComponent::ConnectFrom(const char * interfacename, ComponentBase* other)
{ {
//TODO write out as templated functionality: //TODO write out as templated functionality:
if (std::strcmp(InterfaceName<InterfaceAcceptor<MetricValueInterface>>::Get(), interfacename) == 0) if (std::strcmp(InterfaceName<InterfaceAcceptor<MetricValueInterface> >::Get(), interfacename) == 0)
{ {
InterfaceAcceptor<MetricValueInterface>* acceptIF = static_cast<InterfaceAcceptor<MetricValueInterface>*> (this); InterfaceAcceptor<MetricValueInterface>* acceptIF = static_cast<InterfaceAcceptor<MetricValueInterface>*> (this);
if (!acceptIF) if (!acceptIF)
{ {
std::cout << InterfaceName<InterfaceAcceptor<MetricValueInterface>>::Get() << " optimizer has no OptimizerValueInterface" << std::endl; std::cout << InterfaceName<InterfaceAcceptor<MetricValueInterface> >::Get() << " optimizer has no OptimizerValueInterface" << std::endl;
} }
// connect value interfaces // connect value interfaces
acceptIF->Connect(other); acceptIF->Connect(other);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define Interfaces_hxx #define Interfaces_hxx
#include "ComponentBase.h" #include "ComponentBase.h"
#include <typeinfo>
namespace elx namespace elx
{ {
...@@ -32,20 +33,6 @@ private: ...@@ -32,20 +33,6 @@ private:
bool isSet; bool isSet;
}; };
template<class InterfaceT>
int InterfaceAcceptor<InterfaceT>::Connect(ComponentBase* providerComponent){
InterfaceT* providerInterface = dynamic_cast<InterfaceT*> (providerComponent);
if (!providerInterface)
{
std::cout << "providerComponent does not have required " << InterfaceName < InterfaceT >::Get() << std::endl;
return 0;
}
// connect value interfaces
this->Set(providerInterface); // due to the input argument being uniquely defined in the multiple inheritance tree, all versions of Set() are accessible
return 1;
}
//template<typename... Interfaces> //template<typename... Interfaces>
//class Accepting : public Interfaces... //class Accepting : public Interfaces...
...@@ -90,8 +77,8 @@ class Providing : public Interfaces... ...@@ -90,8 +77,8 @@ class Providing : public Interfaces...
template<typename AcceptingInterfaces, typename ProvidingInterfaces> template<typename AcceptingInterfaces, typename ProvidingInterfaces>
class Implements : public ComponentBase, public AcceptingInterfaces, public ProvidingInterfaces class Implements : public ComponentBase, public AcceptingInterfaces, public ProvidingInterfaces
{ {
typedef typename AcceptingInterfaces AcceptingInterfacesType; typedef AcceptingInterfaces AcceptingInterfacesType;
typedef typename ProvidingInterfaces ProvidingInterfacesType; typedef ProvidingInterfaces ProvidingInterfacesType;
}; };
/* /*
...@@ -180,5 +167,20 @@ struct AcceptorInterfaceName ...@@ -180,5 +167,20 @@ struct AcceptorInterfaceName
}; };
template<class InterfaceT>
int InterfaceAcceptor<InterfaceT>::Connect(ComponentBase* providerComponent){
InterfaceT* providerInterface = dynamic_cast<InterfaceT*> (providerComponent);
if (!providerInterface)
{
std::cout << "providerComponent does not have required " << InterfaceName < InterfaceT >::Get() << std::endl;
return 0;
}
// connect value interfaces
this->Set(providerInterface); // due to the input argument being uniquely defined in the multiple inheritance tree, all versions of Set() are accessible
return 1;
}
} // end namespace elx } // end namespace elx
#endif // #define Interfaces_hxx #endif // #define Interfaces_hxx
\ No newline at end of file
...@@ -13,14 +13,12 @@ ...@@ -13,14 +13,12 @@
using namespace elx; using namespace elx;
int main() { int main() {
{ {
tuple<double, long long, const char*> t1(12.2, 42, "big");
std::cout << InterfaceName<MetricValueInterface>::Get() << std::endl; std::cout << InterfaceName<MetricValueInterface>::Get() << std::endl;
std::cout << AcceptorInterfaceName<InterfaceAcceptor<MetricValueInterface>>::Get() << std::endl; std::cout << AcceptorInterfaceName<InterfaceAcceptor<MetricValueInterface> >::Get() << std::endl;
std::cout << InterfaceName<InterfaceAcceptor<MetricValueInterface>>::Get() << std::endl; std::cout << InterfaceName<InterfaceAcceptor<MetricValueInterface> >::Get() << std::endl;
std::cout << InterfaceName<InterfaceProvider<MetricValueInterface>>::Get() << std::endl; std::cout << InterfaceName<InterfaceProvider<MetricValueInterface> >::Get() << std::endl;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment