source: rrlib_util/patterns/command/tFunctor.h @ 43:0b04f7b6406e

Last change on this file since 43:0b04f7b6406e was 43:0b04f7b6406e, checked in by Tobias Föhst <foehst@…>, 9 years ago

Reformatted with astyle 2.02.1

File size: 3.8 KB
Line 
1//
2// You received this file as part of RRLib
3// Robotics Research Library
4//
5// Copyright (C) Finroc GbR (finroc.org)
6//
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public License
9// as published by the Free Software Foundation; either version 2
10// of the License, or (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20//
21//----------------------------------------------------------------------
22/*!\file    tFunctor.h
23 *
24 * \author  Tobias Foehst
25 *
26 * \date    2010-10-24
27 *
28 * \brief Contains tFunctor
29 *
30 * \b tFunctor
31 *
32 */
33//----------------------------------------------------------------------
34#ifndef __rrlib__util__patterns__command__tFunctor_h__
35#define __rrlib__util__patterns__command__tFunctor_h__
36
37//----------------------------------------------------------------------
38// External includes (system with <>, local with "")
39//----------------------------------------------------------------------
40#include <memory>
41
42//----------------------------------------------------------------------
43// Internal includes with ""
44//----------------------------------------------------------------------
45#include "rrlib/util/patterns/command/tFunctorHandlerBase.h"
46#include "rrlib/util/patterns/command/tFunctorHandler.h"
47#include "rrlib/util/patterns/command/tMemberFunctionHandler.h"
48
49//----------------------------------------------------------------------
50// Debugging
51//----------------------------------------------------------------------
52
53//----------------------------------------------------------------------
54// Namespace declaration
55//----------------------------------------------------------------------
56namespace rrlib
57{
58namespace util
59{
60
61//----------------------------------------------------------------------
62// Forward declarations / typedefs / enums
63//----------------------------------------------------------------------
64
65//----------------------------------------------------------------------
66// Class declaration
67//----------------------------------------------------------------------
68//!
69/*!
70 *
71 */
72template <typename TReturn, typename ... TParameters>
73class tFunctor
74{
75
76//----------------------------------------------------------------------
77// Public methods and typedefs
78//----------------------------------------------------------------------
79public:
80
81  tFunctor(const tFunctor &other)
82    : handler(other.handler)
83  {}
84
85  explicit tFunctor(std::shared_ptr<tFunctorHandlerBase<TReturn, TParameters...>> handler)
86    : handler(handler)
87  {}
88
89  template <typename TFunctor>
90  tFunctor(const TFunctor &functor)
91    : handler(new tFunctorHandler<TFunctor, TReturn, TParameters...>(functor))
92  {}
93
94  template <typename TObject, typename TFunction>
95  tFunctor(TObject &object, const TFunction &function)
96    : handler(new tMemberFunctionHandler<TObject, TFunction, TReturn, TParameters...>(object, function))
97  {}
98
99  TReturn operator()(TParameters... parameters) const
100  {
101    return (*this->handler)(parameters...);
102  }
103
104//----------------------------------------------------------------------
105// Private fields and methods
106//----------------------------------------------------------------------
107private:
108
109  std::shared_ptr<tFunctorHandlerBase<TReturn, TParameters...>> handler;
110
111//  tFunctor();
112
113};
114
115//----------------------------------------------------------------------
116// End of namespace declaration
117//----------------------------------------------------------------------
118}
119}
120
121#endif
Note: See TracBrowser for help on using the repository browser.