SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00008 // Encapsulates an object's method for using it as a message retriever 00009 /****************************************************************************/ 00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00012 /****************************************************************************/ 00013 // 00014 // This file is part of SUMO. 00015 // SUMO is free software: you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation, either version 3 of the License, or 00018 // (at your option) any later version. 00019 // 00020 /****************************************************************************/ 00021 #ifndef MsgRetrievingFunction_h 00022 #define MsgRetrievingFunction_h 00023 00024 00025 // =========================================================================== 00026 // included modules 00027 // =========================================================================== 00028 #ifdef _MSC_VER 00029 #include <windows_config.h> 00030 #else 00031 #include <config.h> 00032 #endif 00033 00034 #include <string> 00035 #include <sstream> 00036 #include <utils/iodevices/OutputDevice.h> 00037 #include "MsgHandler.h" 00038 00039 00040 // =========================================================================== 00041 // class definitions 00042 // =========================================================================== 00049 template< class T > 00050 class MsgRetrievingFunction : public OutputDevice { 00051 public: 00053 typedef void(T::* Operation)(const MsgHandler::MsgType, const std::string&); 00054 00055 00061 MsgRetrievingFunction(T* object, Operation operation, MsgHandler::MsgType type) : 00062 myObject(object), 00063 myOperation(operation), 00064 myMsgType(type) {} 00065 00066 00068 ~MsgRetrievingFunction() {} 00069 00070 00071 protected: 00074 00083 std::ostream& getOStream() { 00084 return myMessage; 00085 } 00086 00087 00090 virtual void postWriteHook() { 00091 (myObject->*myOperation)(myMsgType, myMessage.str()); 00092 myMessage.str(""); 00093 } 00095 00096 00097 private: 00099 T* myObject; 00100 00102 Operation myOperation; 00103 00105 MsgHandler::MsgType myMsgType; 00106 00108 std::ostringstream myMessage; 00109 00110 }; 00111 00112 00113 #endif 00114 00115 /****************************************************************************/ 00116