SUMO - Simulation of Urban MObility
MsgRetrievingFunction.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // Encapsulates an object's method for using it as a message retriever
19 /****************************************************************************/
20 #ifndef MsgRetrievingFunction_h
21 #define MsgRetrievingFunction_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <sstream>
36 #include "MsgHandler.h"
37 
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
48 template< class T >
50 public:
52  typedef void(T::* Operation)(const MsgHandler::MsgType, const std::string&);
53 
54 
60  MsgRetrievingFunction(T* object, Operation operation, MsgHandler::MsgType type) :
61  myObject(object),
62  myOperation(operation),
63  myMsgType(type) {}
64 
65 
68 
69 
70 protected:
73 
82  std::ostream& getOStream() {
83  return myMessage;
84  }
85 
86 
89  virtual void postWriteHook() {
91  myMessage.str("");
92  }
94 
95 
96 private:
99 
102 
104  MsgHandler::MsgType myMsgType;
105 
107  std::ostringstream myMessage;
108 
109 };
110 
111 
112 #endif
113 
114 /****************************************************************************/
115 
std::ostream & getOStream()
Returns the associated ostream.
virtual void postWriteHook()
Sends the data which was written to the string stream via the retrieving function.
MsgRetrievingFunction(T *object, Operation operation, MsgHandler::MsgType type)
Constructor.
MsgHandler::MsgType myMsgType
The type of message to retrieve.
Encapsulates an object&#39;s method for using it as a message retriever.
~MsgRetrievingFunction()
Destructor.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
std::ostringstream myMessage
message buffer
Operation myOperation
The object&#39;s operation to perform.
void(T::* Operation)(const MsgHandler::MsgType, const std::string &)
Type of the function to execute.
T * myObject
The object the action is directed to.