Stefan Scholz / ETL
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers callback.h Source File

callback.h

Go to the documentation of this file.
00001 ///\file
00002 
00003 /******************************************************************************
00004 The MIT License(MIT)
00005 
00006 Embedded Template Library.
00007 https://github.com/ETLCPP/etl
00008 http://www.etlcpp.com
00009 
00010 Copyright(c) 2015 jwellbelove
00011 
00012 Permission is hereby granted, free of charge, to any person obtaining a copy
00013 of this software and associated documentation files(the "Software"), to deal
00014 in the Software without restriction, including without limitation the rights
00015 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
00016 copies of the Software, and to permit persons to whom the Software is
00017 furnished to do so, subject to the following conditions :
00018 
00019 The above copyright notice and this permission notice shall be included in all
00020 copies or substantial portions of the Software.
00021 
00022 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00023 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00024 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
00025 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00026 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00027 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00028 SOFTWARE.
00029 ******************************************************************************/
00030 
00031 #ifndef __ETL_CALLBACK__
00032 #define __ETL_CALLBACK__
00033 
00034 namespace etl
00035 {
00036   //***************************************************************************
00037   /// A callback class designed to be multiply inherited by other client classes.
00038   /// The class is parametrised with a callback parameter type and a unique id.
00039   /// The unique id allows multiple callbacks with the same parameter type.
00040   ///\tparam TParameter The callback parameter type.
00041   ///\tparam ID The unique id for this callback.
00042   //***************************************************************************
00043   template <typename TParameter, const int ID>
00044   class callback
00045   {
00046   private:
00047 
00048     // Creates a parameter type unique to this ID.
00049     template <typename T, const int I>
00050     struct parameter
00051     {
00052         parameter(T value)
00053             : value(value)
00054         {
00055         }
00056 
00057         typedef T value_type;
00058 
00059         T value;
00060 
00061     private:
00062 
00063         parameter();
00064     };
00065 
00066     // Specialisation for void.
00067     template <const int I>
00068     struct parameter<void, I>
00069     {
00070         typedef void value_type;
00071     };
00072 
00073   public:
00074 
00075     typedef parameter<TParameter, ID> type;
00076 
00077     virtual void etl_callback(type p = type()) = 0;
00078   };
00079 }
00080 
00081 #endif