Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
FunctionBinding.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// Function type template
22/****************************************************************************/
23#pragma once
24#include <config.h>
25
28
29
30// ===========================================================================
31// class definitions
32// ===========================================================================
36template< class T, typename R >
37class FunctionBinding : public ValueSource<R> {
38public:
40 typedef R(T::* Operation)() const;
41
42 FunctionBinding(T* const source, Operation operation, const R scale = 1) :
43 mySource(source),
44 myOperation(operation),
45 myScale(scale) {}
46
49
50 R getValue() const {
51 return myScale * (mySource->*myOperation)();
52 }
53
57
61
62private:
65
68
70 const R myScale;
71
72private:
75
76};
77
78template<class T>
79class FunctionBindingString : public ValueSource<std::string> {
80public:
82 typedef std::string(T::* Operation)() const;
83
84 FunctionBindingString(T* const source, Operation operation) :
85 mySource(source),
86 myOperation(operation)
87 {}
88
91
92 std::string getValue() const {
93 return (mySource->*myOperation)();
94 }
95
99
101 return nullptr;
102 }
103
104private:
107
110
111private:
114
115};
const R myScale
The scale to apply.
T * mySource
The object the action is directed to.
Operation myOperation
The object's operation to perform.
~FunctionBinding()
Destructor.
R(T::* Operation)() const
Type of the function to execute.
ValueSource< double > * makedoubleReturningCopy() const
ValueSource< R > * copy() const
FunctionBinding(T *const source, Operation operation, const R scale=1)
FunctionBinding< T, R > & operator=(const FunctionBinding< T, R > &)
invalidated assignment operator
T * mySource
The object the action is directed to.
FunctionBindingString(T *const source, Operation operation)
~FunctionBindingString()
Destructor.
FunctionBindingString< T > & operator=(const FunctionBindingString< T > &)
invalidated assignment operator
ValueSource< std::string > * copy() const
std::string getValue() const
std::string(T::* Operation)() const
Type of the function to execute.
ValueSource< double > * makedoubleReturningCopy() const
Operation myOperation
The object's operation to perform.