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.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 /****************************************************************************/
18 // Function type template
19 /****************************************************************************/
20 #ifndef FunctionBinding_h
21 #define FunctionBinding_h
22 
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
31 #include "CastingFunctionBinding.h"
32 
33 
34 // ===========================================================================
35 // class definitions
36 // ===========================================================================
40 template< class T, typename R >
41 class FunctionBinding : public ValueSource<R> {
42 public:
44  typedef R(T::* Operation)() const;
45 
46  FunctionBinding(T* const source, Operation operation, const R scale = 1) :
47  mySource(source),
48  myOperation(operation),
49  myScale(scale) {}
50 
53 
54  R getValue() const {
55  return myScale * (mySource->*myOperation)();
56  }
57 
58  ValueSource<R>* copy() const {
60  }
61 
64  }
65 
66 private:
69 
72 
74  const R myScale;
75 
76 private:
79 
80 };
81 
82 template<class T>
83 class FunctionBindingString : public ValueSource<std::string> {
84 public:
86  typedef std::string(T::* Operation)() const;
87 
88  FunctionBindingString(T* const source, Operation operation) :
89  mySource(source),
90  myOperation(operation)
91  {}
92 
95 
96  std::string getValue() const {
97  return (mySource->*myOperation)();
98  }
99 
102  }
103 
105  return nullptr;
106  }
107 
108 private:
111 
114 
115 private:
118 
119 };
120 
121 #endif
122 
123 /****************************************************************************/
124 
ValueSource< std::string > * copy() const
ValueSource< R > * copy() const
Operation myOperation
The object&#39;s operation to perform.
FunctionBinding(T *const source, Operation operation, const R scale=1)
T * mySource
The object the action is directed to.
ValueSource< double > * makedoubleReturningCopy() const
T * mySource
The object the action is directed to.
~FunctionBindingString()
Destructor.
R(T::* Operation)() const
Type of the function to execute.
FunctionBindingString(T *const source, Operation operation)
const R myScale
The scale to apply.
FunctionBinding< T, R > & operator=(const FunctionBinding< T, R > &)
invalidated assignment operator
ValueSource< double > * makedoubleReturningCopy() const
Operation myOperation
The object&#39;s operation to perform.
~FunctionBinding()
Destructor.
std::string getValue() const
R getValue() const