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