Skip to content
Snippets Groups Projects
Commit a25a0aef authored by Jan Trávníček's avatar Jan Trávníček
Browse files

move tuple extensions to ext namespace

parent 412e2836
No related branches found
No related tags found
No related merge requests found
...@@ -59,12 +59,12 @@ protected: ...@@ -59,12 +59,12 @@ protected:
return false; return false;
} }
}; };
return std::call_on_nth < bool > ( inputs, index, attachCallback ); return ext::call_on_nth < bool > ( inputs, index, attachCallback );
} }
   
virtual bool detachInput ( const std::shared_ptr < OperationAbstraction > & input ) override { virtual bool detachInput ( const std::shared_ptr < OperationAbstraction > & input ) override {
bool res = false; bool res = false;
std::foreach ( inputs, [ & ] ( auto & param ) { ext::foreach ( inputs, [ & ] ( auto & param ) {
if ( param == input ) { if ( param == input ) {
param = nullptr; param = nullptr;
res = true; res = true;
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
return ( bool ) param && param->isReady ( ); return ( bool ) param && param->isReady ( );
}; };
   
return all_of ( inputs, readyCallback ); return ext::all_of ( inputs, readyCallback );
} }
   
virtual bool inputsAttached ( ) const override { virtual bool inputsAttached ( ) const override {
...@@ -87,7 +87,7 @@ public: ...@@ -87,7 +87,7 @@ public:
return ( bool ) param; return ( bool ) param;
}; };
   
return all_of ( inputs, attachedCallback ); return ext::all_of ( inputs, attachedCallback );
} }
   
virtual bool eval ( ) override { virtual bool eval ( ) override {
...@@ -101,7 +101,7 @@ public: ...@@ -101,7 +101,7 @@ public:
return param->eval ( ); return param->eval ( );
}; };
   
if ( ! all_of ( inputs, evalCallback ) ) if ( ! ext::all_of ( inputs, evalCallback ) )
return false; return false;
   
return this->run ( ); return this->run ( );
...@@ -116,7 +116,7 @@ public: ...@@ -116,7 +116,7 @@ public:
std::string paramType = ext::to_string < typename std::decay < decltype ( param ) >::type::element_type::return_type > ( ); std::string paramType = ext::to_string < typename std::decay < decltype ( param ) >::type::element_type::return_type > ( );
return Registry::getImmediateAbstraction ( std::move ( paramType ), value ); return Registry::getImmediateAbstraction ( std::move ( paramType ), value );
}; };
return std::call_on_nth < std::shared_ptr < OperationAbstraction > > ( inputs, index, callback ); return ext::call_on_nth < std::shared_ptr < OperationAbstraction > > ( inputs, index, callback );
} }
   
virtual std::shared_ptr < OperationAbstraction > getXmlParserFromParam ( unsigned index, std::deque < sax::Token > tokens ) const override { virtual std::shared_ptr < OperationAbstraction > getXmlParserFromParam ( unsigned index, std::deque < sax::Token > tokens ) const override {
...@@ -124,7 +124,7 @@ public: ...@@ -124,7 +124,7 @@ public:
std::string paramType = ext::to_string < typename std::decay < decltype ( param ) >::type::element_type::return_type > ( ); std::string paramType = ext::to_string < typename std::decay < decltype ( param ) >::type::element_type::return_type > ( );
return Registry::getXmlParserAbstraction ( std::move ( paramType ), std::move ( tokens ) ); return Registry::getXmlParserAbstraction ( std::move ( paramType ), std::move ( tokens ) );
}; };
return std::call_on_nth < std::shared_ptr < OperationAbstraction > > ( inputs, index, callback ); return ext::call_on_nth < std::shared_ptr < OperationAbstraction > > ( inputs, index, callback );
} }
}; };
   
......
...@@ -59,7 +59,7 @@ private: ...@@ -59,7 +59,7 @@ private:
   
}; };
   
std::map < typename std::TupleBuilder < std::type_index, sizeof ... ( DispatchedParameterTypes ) >::type, std::unique_ptr < RegistratorWrapperBase > > registeredFunctions; std::map < typename ext::TupleBuilder < std::type_index, sizeof ... ( DispatchedParameterTypes ) >::type, std::unique_ptr < RegistratorWrapperBase > > registeredFunctions;
   
static MultipleDispatch < Algorithm, ReturnType, std::tuple < FrontStaticParamTypes ... >, std::tuple < DispatchedParameterTypes ... >, std::tuple < BackStaticParamTypes ... > > & getInstance ( ) { static MultipleDispatch < Algorithm, ReturnType, std::tuple < FrontStaticParamTypes ... >, std::tuple < DispatchedParameterTypes ... >, std::tuple < BackStaticParamTypes ... > > & getInstance ( ) {
static MultipleDispatch < Algorithm, ReturnType, std::tuple < FrontStaticParamTypes ... >, std::tuple < DispatchedParameterTypes ... >, std::tuple < BackStaticParamTypes ... > > res; static MultipleDispatch < Algorithm, ReturnType, std::tuple < FrontStaticParamTypes ... >, std::tuple < DispatchedParameterTypes ... >, std::tuple < BackStaticParamTypes ... > > res;
......
...@@ -72,8 +72,8 @@ public: ...@@ -72,8 +72,8 @@ public:
   
template < class Data, int arity, class ConstData = Data, class Cast = Data > template < class Data, int arity, class ConstData = Data, class Cast = Data >
class AnyaryNode { class AnyaryNode {
typedef typename std::TupleBuilder < Data, arity >::type ChildrenType; typedef typename ext::TupleBuilder < Data, arity >::type ChildrenType;
typedef typename std::TupleBuilder < ConstData, arity >::type ConstChildrenType; typedef typename ext::TupleBuilder < ConstData, arity >::type ConstChildrenType;
   
union ChildrenUnion { union ChildrenUnion {
ChildrenType children; ChildrenType children;
...@@ -95,7 +95,7 @@ class AnyaryNode { ...@@ -95,7 +95,7 @@ class AnyaryNode {
} }
   
public: public:
AnyaryNode ( typename std::TupleBuilder < Data, arity >::type c ) : children_union ( std::move ( c ) ) { AnyaryNode ( typename ext::TupleBuilder < Data, arity >::type c ) : children_union ( std::move ( c ) ) {
setParent ( std::make_index_sequence < arity > ( ) ); setParent ( std::make_index_sequence < arity > ( ) );
} }
   
...@@ -122,11 +122,11 @@ public: ...@@ -122,11 +122,11 @@ public:
return * this; return * this;
} }
   
const typename std::TupleBuilder < Data, arity >::type & getElements ( ) { const typename ext::TupleBuilder < Data, arity >::type & getElements ( ) {
return children_union.children; return children_union.children;
} }
   
const typename std::TupleBuilder < ConstData, arity >::type & getElements ( ) const { const typename ext::TupleBuilder < ConstData, arity >::type & getElements ( ) const {
return children_union.const_children; return children_union.const_children;
} }
   
...@@ -140,7 +140,7 @@ public: ...@@ -140,7 +140,7 @@ public:
return std::get < N > ( children_union.children ); return std::get < N > ( children_union.children );
} }
   
void setElements ( typename std::TupleBuilder < Data, arity >::type c ) { void setElements ( typename ext::TupleBuilder < Data, arity >::type c ) {
children_union.children = std::move ( c ); children_union.children = std::move ( c );
setParent ( std::make_index_sequence < arity > ( ) ); setParent ( std::make_index_sequence < arity > ( ) );
} }
...@@ -479,7 +479,7 @@ public: ...@@ -479,7 +479,7 @@ public:
} }
   
template < int arity > template < int arity >
static void setChildren ( const AnyaryNode < Data, arity, ConstData, Cast > & node, typename std::TupleBuilder < Data, arity >::type children ) { static void setChildren ( const AnyaryNode < Data, arity, ConstData, Cast > & node, typename ext::TupleBuilder < Data, arity >::type children ) {
const_cast < AnyaryNode < Data, arity, ConstData, Cast > & > ( node ).setChildren ( std::move ( children ) ); const_cast < AnyaryNode < Data, arity, ConstData, Cast > & > ( node ).setChildren ( std::move ( children ) );
} }
   
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
   
#include "compare.hpp" #include "compare.hpp"
   
namespace std { namespace ext {
   
template < class Result, unsigned I, class Tuple, class Callable > template < class Result, unsigned I, class Tuple, class Callable >
struct call_on_nth_helper; struct call_on_nth_helper;
...@@ -76,11 +76,13 @@ bool all_of ( const Tuple & t, Callable callback ) { ...@@ -76,11 +76,13 @@ bool all_of ( const Tuple & t, Callable callback ) {
res &= callback ( arg0 ); res &= callback ( arg0 );
}; };
   
std::foreach ( t, aggregateCallback ); ext::foreach ( t, aggregateCallback );
return res; return res;
} }
   
} /* namespace ext */
   
namespace std {
   
template<int I, class Tuple> template<int I, class Tuple>
struct operator_shift_left_impl; struct operator_shift_left_impl;
...@@ -152,10 +154,6 @@ std::string to_string ( const std::tuple < Ts ... > & value ) { ...@@ -152,10 +154,6 @@ std::string to_string ( const std::tuple < Ts ... > & value ) {
return ss.str(); return ss.str();
} }
   
} /* namespace ext */
namespace std {
template < class Type, int size, class ... Types > template < class Type, int size, class ... Types >
struct TupleBuilder; struct TupleBuilder;
   
...@@ -168,6 +166,6 @@ template < class Type, int n, class ... Types > ...@@ -168,6 +166,6 @@ template < class Type, int n, class ... Types >
struct TupleBuilder : public TupleBuilder < Type, n - 1, Type, Types ... > { struct TupleBuilder : public TupleBuilder < Type, n - 1, Type, Types ... > {
}; };
   
} /* namespace std */ } /* namespace ext */
   
#endif /* __TUPLE_HPP_ */ #endif /* __TUPLE_HPP_ */
...@@ -13,6 +13,6 @@ void TupleTest::tearDown() { ...@@ -13,6 +13,6 @@ void TupleTest::tearDown() {
void TupleTest::testCallOnNth() { void TupleTest::testCallOnNth() {
std::tuple < int, int, int, int, int > t = std::make_tuple ( 1, 2, 3, 4, 5 ); std::tuple < int, int, int, int, int > t = std::make_tuple ( 1, 2, 3, 4, 5 );
   
CPPUNIT_ASSERT ( std::call_on_nth < int > ( t, 1, [] ( int i ) { return i; } ) == 2 ); CPPUNIT_ASSERT ( ext::call_on_nth < int > ( t, 1, [] ( int i ) { return i; } ) == 2 );
} }
   
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment