Eclipse SUMO - Simulation of Urban MObility
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 
27 #include "CastingFunctionBinding.h"
28 
29 
30 // ===========================================================================
31 // class definitions
32 // ===========================================================================
36 template< class T, typename R >
37 class FunctionBinding : public ValueSource<R> {
38 public:
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 
54  ValueSource<R>* copy() const {
56  }
57 
60  }
61 
62 private:
65 
68 
70  const R myScale;
71 
72 private:
75 
76 };
77 
78 template<class T>
79 class FunctionBindingString : public ValueSource<std::string> {
80 public:
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 
98  }
99 
101  return nullptr;
102  }
103 
104 private:
107 
110 
111 private:
114 
115 };
const R myScale
The scale to apply.
T * mySource
The object the action is directed to.
ValueSource< R > * copy() const
Operation myOperation
The object's operation to perform.
~FunctionBinding()
Destructor.
R(T::* Operation)() const
Type of the function to execute.
FunctionBinding< T, R > & operator=(const FunctionBinding< T, R > &)
invalidated assignment operator
R getValue() const
ValueSource< double > * makedoubleReturningCopy() const
FunctionBinding(T *const source, Operation operation, const R scale=1)
T * mySource
The object the action is directed to.
FunctionBindingString(T *const source, Operation operation)
~FunctionBindingString()
Destructor.
std::string getValue() const
ValueSource< double > * makedoubleReturningCopy() const
FunctionBindingString< T > & operator=(const FunctionBindingString< T > &)
invalidated assignment operator
ValueSource< std::string > * copy() const
std::string(T::* Operation)() const
Type of the function to execute.
Operation myOperation
The object's operation to perform.