Loading...
Searching...
No Matches
function.h
Go to the documentation of this file.
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2014 John Wellbelove
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#ifndef ETL_FUNCTION_INCLUDED
#define ETL_FUNCTION_INCLUDED
#include "platform.h"
//*****************************************************************************
//*****************************************************************************
namespace etl
{
//***************************************************************************
//***************************************************************************
template <typename TParameter>
class ifunction
{
public:
typedef TParameter parameter_type;
virtual ~ifunction() {}
//*************************************************************************
//*************************************************************************
virtual void operator()(TParameter) const = 0;
};
//***************************************************************************
//***************************************************************************
template <>
class ifunction<void>
{
public:
typedef void parameter_type;
virtual ~ifunction() {}
//*************************************************************************
//*************************************************************************
virtual void operator()() const = 0;
};
//***************************************************************************
//***************************************************************************
template <typename TObject, typename TParameter>
class function : public ifunction<TParameter>
{
public:
typedef TObject object_type;
typedef TParameter parameter_type;
//*************************************************************************
//*************************************************************************
function(TObject& object_, void (TObject::*p_function_)(TParameter))
: p_object(&object_)
, p_function(p_function_)
{
}
//*************************************************************************
//*************************************************************************
virtual void operator()(TParameter data) const ETL_OVERRIDE
{
// Call the object's member function with the data.
(p_object->*p_function)(data);
}
private:
TObject* p_object;
void (TObject::*p_function)(TParameter);
};
//***************************************************************************
//***************************************************************************
template <typename TObject>
class function<TObject, void> : public ifunction<void>
{
public:
//*************************************************************************
//*************************************************************************
function(TObject& object_, void (TObject::*p_function_)(void))
: p_object(&object_)
, p_function(p_function_)
{
}
//*************************************************************************
//*************************************************************************
virtual void operator()() const ETL_OVERRIDE
{
// Call the object's member function.
(p_object->*p_function)();
}
private:
TObject* p_object;
void (TObject::*p_function)();
};
//***************************************************************************
//***************************************************************************
template <typename TParameter>
class function<void, TParameter> : public ifunction<TParameter>
{
public:
//*************************************************************************
//*************************************************************************
explicit function(void (*p_function_)(TParameter))
: p_function(p_function_)
{
}
//*************************************************************************
//*************************************************************************
virtual void operator()(TParameter data) const ETL_OVERRIDE
{
// Call the function with the data.
(*p_function)(data);
}
private:
void (*p_function)(TParameter);
};
//***************************************************************************
//***************************************************************************
template <>
class function<void, void> : public ifunction<void>
{
public:
//*************************************************************************
//*************************************************************************
explicit function(void (*p_function_)(void))
: p_function(p_function_)
{
}
//*************************************************************************
//*************************************************************************
virtual void operator()() const ETL_OVERRIDE
{
// Call the function.
(*p_function)();
}
private:
void (*p_function)();
};
//***************************************************************************
//***************************************************************************
template <typename TObject, typename TParameter, void (TObject::*Function)(TParameter)>
class function_mp : public ifunction<TParameter>
{
public:
typedef TObject object_type;
typedef TParameter parameter_type;
//*************************************************************************
//*************************************************************************
explicit function_mp(TObject& object_)
: p_object(&object_)
{
}
//*************************************************************************
//*************************************************************************
virtual void operator()(TParameter data) const ETL_OVERRIDE
{
// Call the object's member function with the data.
(p_object->*Function)(data);
}
private:
TObject* p_object;
};
//***************************************************************************
//***************************************************************************
template <typename TObject, void (TObject::*Function)(void)>
class function_mv : public ifunction<void>
{
public:
typedef TObject object_type;
typedef void parameter_type;
//*************************************************************************
//*************************************************************************
explicit function_mv(TObject& object_)
: p_object(&object_)
{
}
//*************************************************************************
//*************************************************************************
virtual void operator()() const ETL_OVERRIDE
{
// Call the object's member function.
(p_object->*Function)();
}
private:
TObject* p_object;
};
//***************************************************************************
//***************************************************************************
template <typename TObject, typename TParameter, TObject& Instance, void (TObject::*Function)(TParameter)>
class function_imp : public ifunction<TParameter>
{
public:
typedef TObject object_type;
typedef TParameter parameter_type;
//*************************************************************************
//*************************************************************************
virtual void operator()(TParameter data) const ETL_OVERRIDE
{
// Call the object's member function with the data.
(Instance.*Function)(data);
}
};
//***************************************************************************
//***************************************************************************
template <typename TObject, TObject& Instance, void (TObject::*Function)(void)>
class function_imv : public ifunction<void>
{
public:
typedef TObject object_type;
typedef void parameter_type;
//*************************************************************************
//*************************************************************************
virtual void operator()() const ETL_OVERRIDE
{
// Call the object's member function.
(Instance.*Function)();
}
};
//***************************************************************************
//***************************************************************************
template <typename TParameter, void (*Function)(TParameter)>
class function_fp : public ifunction<TParameter>
{
public:
typedef TParameter parameter_type;
//*************************************************************************
//*************************************************************************
function_fp() {}
//*************************************************************************
//*************************************************************************
virtual void operator()(TParameter data) const ETL_OVERRIDE
{
// Call the object's member function with the data.
(*Function)(data);
}
};
//***************************************************************************
//***************************************************************************
template <void (*Function)(void)>
class function_fv : public ifunction<void>
{
public:
typedef void parameter_type;
//*************************************************************************
//*************************************************************************
function_fv() {}
//*************************************************************************
//*************************************************************************
virtual void operator()() const ETL_OVERRIDE
{
// Call the function.
(*Function)();
}
};
} // namespace etl
#endif
etl::function< void, TParameter >::operator()
virtual void operator()(TParameter data) const ETL_OVERRIDE
Definition function.h:185
etl::function_imp::parameter_type
TParameter parameter_type
The type of parameter sent to the function.
Definition function.h:316
etl::function_mp::object_type
TObject object_type
The type of object.
Definition function.h:239
etl::function< TObject, void >::operator()
virtual void operator()() const ETL_OVERRIDE
The function operator that calls the destination function.
Definition function.h:151
etl::function::object_type
TObject object_type
The type of object.
Definition function.h:97
etl::ifunction::operator()
virtual void operator()(TParameter) const =0
The function operator that will be overridden.
etl::function_imp::object_type
TObject object_type
The type of object.
Definition function.h:315
etl::function_fv::parameter_type
void parameter_type
The type of parameter sent to the function.
Definition function.h:394
etl::function_mv::function_mv
function_mv(TObject &object_)
Definition function.h:284
etl::function_fv::function_fv
function_fv()
Definition function.h:401
etl::function_imv::object_type
TObject object_type
The type of object.
Definition function.h:340
etl::function_mp::function_mp
function_mp(TObject &object_)
Definition function.h:246
etl::function_mp::operator()
virtual void operator()(TParameter data) const ETL_OVERRIDE
Definition function.h:255
etl::function< void, TParameter >::function
function(void(*p_function_)(TParameter))
Definition function.h:176
etl::function_mp::parameter_type
TParameter parameter_type
The type of parameter sent to the function.
Definition function.h:240
etl::function< TObject, void >::function
function(TObject &object_, void(TObject::*p_function_)(void))
Definition function.h:142
etl::function_fv::operator()
virtual void operator()() const ETL_OVERRIDE
Definition function.h:407
etl::function< void, void >::function
function(void(*p_function_)(void))
Definition function.h:209
etl::function_fp::parameter_type
TParameter parameter_type
The type of parameter sent to the function.
Definition function.h:364
etl::function_mv::operator()
virtual void operator()() const ETL_OVERRIDE
Definition function.h:293
etl::function_fp::function_fp
function_fp()
Definition function.h:371
etl::ifunction< void >::operator()
virtual void operator()() const =0
The function operator that will be overridden.
etl::function_imv::parameter_type
void parameter_type
The type of parameter sent to the function.
Definition function.h:341
etl::function_mv::parameter_type
void parameter_type
The type of parameter sent to the function.
Definition function.h:278
etl::function::parameter_type
TParameter parameter_type
The type of parameter sent to the function.
Definition function.h:98
etl::ifunction::parameter_type
TParameter parameter_type
The type of parameter sent to the function.
Definition function.h:57
etl::ifunction< void >::parameter_type
void parameter_type
The type of parameter sent to the function.
Definition function.h:76
etl::function< void, void >::operator()
virtual void operator()() const ETL_OVERRIDE
The function operator that calls the destination function.
Definition function.h:217
etl::function::function
function(TObject &object_, void(TObject::*p_function_)(TParameter))
Definition function.h:105
etl::function_mv::object_type
TObject object_type
The type of object.
Definition function.h:277
etl::function::operator()
virtual void operator()(TParameter data) const ETL_OVERRIDE
Definition function.h:115
etl::function_imp::operator()
virtual void operator()(TParameter data) const ETL_OVERRIDE
Definition function.h:322
etl::function_fp::operator()
virtual void operator()(TParameter data) const ETL_OVERRIDE
Definition function.h:377
etl::function_imv::operator()
virtual void operator()() const ETL_OVERRIDE
Definition function.h:347
etl::function_imp
Definition function.h:312
etl::function_imv
Definition function.h:337
etl::ifunction
Definition function.h:54
etl
Definition absolute.h:40
etl::data
ETL_CONSTEXPR TContainer::pointer data(TContainer &container)
Definition iterator.h:1470
platform.h