SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // »missingDescription« 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 #ifndef CastingFunctionBinding_h 00023 #define CastingFunctionBinding_h 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #include <utils/common/ValueSource.h> 00036 00037 00038 // =========================================================================== 00039 // class definitions 00040 // =========================================================================== 00044 template< class T, typename R, typename O > 00045 class CastingFunctionBinding : public ValueSource<R> { 00046 public: 00048 typedef O(T::* Operation)() const; 00049 00050 CastingFunctionBinding(T* source, Operation operation) : 00051 mySource(source), 00052 myOperation(operation) {} 00053 00055 ~CastingFunctionBinding() {} 00056 00057 R getValue() const { 00058 return (R)(mySource->*myOperation)(); 00059 } 00060 00061 ValueSource<R> *copy() const { 00062 return new CastingFunctionBinding<T, R, O>(mySource, myOperation); 00063 } 00064 00065 ValueSource<SUMOReal> *makeSUMORealReturningCopy() const { 00066 return new CastingFunctionBinding<T, SUMOReal, O>(mySource, myOperation); 00067 } 00068 00069 protected: 00070 00071 private: 00073 T* mySource; 00074 00076 Operation myOperation; 00077 }; 00078 00079 00080 #endif 00081 00082 /****************************************************************************/ 00083