1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    CastingFunctionBinding.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Christian Roessel
13 /// @author  Sascha Krieg
14 /// @date    Fri, 29.04.2005
15 /// @version $Id$
16 ///
17 //  Function type template
18 /****************************************************************************/
19 #ifndef CastingFunctionBinding_h
20 #define CastingFunctionBinding_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <utils/common/ValueSource.h>
29 
30 
31 // ===========================================================================
32 // class definitions
33 // ===========================================================================
34 /**
35  * @class CastingFunctionBinding
36  */
37 template< class T, typename R, typename O  >
38 class CastingFunctionBinding : public ValueSource<R> {
39 public:
40     /// Type of the function to execute.
41     typedef O(T::* Operation)() const;
42 
43     CastingFunctionBinding(T* source, Operation operation, const R scale = 1) :
mySource(source)44         mySource(source),
45         myOperation(operation),
46         myScale(scale) {}
47 
48     /// Destructor.
~CastingFunctionBinding()49     ~CastingFunctionBinding() {}
50 
getValue()51     R getValue() const {
52         return myScale * (R)(mySource->*myOperation)();
53     }
54 
copy()55     ValueSource<R>* copy() const {
56         return new CastingFunctionBinding<T, R, O>(mySource, myOperation, myScale);
57     }
58 
makedoubleReturningCopy()59     ValueSource<double>* makedoubleReturningCopy() const {
60         return new CastingFunctionBinding<T, double, O>(mySource, myOperation, myScale);
61     }
62 
63 private:
64     /// The object the action is directed to.
65     T* mySource;
66 
67     /// The object's operation to perform.
68     Operation myOperation;
69 
70     /// The scale to apply.
71     const R myScale;
72 
73 private:
74     /// @brief invalidated assignment operator
75     CastingFunctionBinding<T, R, O>& operator=(const CastingFunctionBinding<T, R, O>&);
76 
77 };
78 
79 
80 #endif
81 
82 /****************************************************************************/
83 
84