MsgRetrievingFunction.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Encapsulates an object's method for using it as a message retriever
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 #ifndef MsgRetrievingFunction_h
00020 #define MsgRetrievingFunction_h
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <string>
00033 #include <sstream>
00034 #include <utils/iodevices/OutputDevice.h>
00035 #include "MsgHandler.h"
00036 
00037 
00038 // ===========================================================================
00039 // class definitions
00040 // ===========================================================================
00047 template< class T >
00048 class MsgRetrievingFunction : public OutputDevice {
00049 public:
00051     typedef void(T::* Operation)(const MsgHandler::MsgType, const std::string &);
00052 
00053 
00059     MsgRetrievingFunction(T* object, Operation operation, MsgHandler::MsgType type) :
00060             myObject(object),
00061             myOperation(operation),
00062             myMsgType(type) {}
00063 
00064 
00066     ~MsgRetrievingFunction() throw() {}
00067 
00068 
00069 protected:
00072 
00081     std::ostream &getOStream() throw() {
00082         return myMessage;
00083     }
00084 
00085 
00088     virtual void postWriteHook() throw() {
00089         (myObject->*myOperation)(myMsgType, myMessage.str());
00090         myMessage.str("");
00091     }
00093 
00094 
00095 private:
00097     T* myObject;
00098 
00100     Operation myOperation;
00101 
00103     MsgHandler::MsgType myMsgType;
00104 
00106     std::ostringstream myMessage;
00107 
00108 };
00109 
00110 
00111 #endif
00112 
00113 /****************************************************************************/
00114 

Generated on Wed May 5 00:06:31 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6