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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // Encapsulates an object's method for using it as a message retriever
17 /****************************************************************************/
18 #ifndef MsgRetrievingFunction_h
19 #define MsgRetrievingFunction_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <string>
28 #include <sstream>
30 #include "MsgHandler.h"
31 
32 
33 // ===========================================================================
34 // class definitions
35 // ===========================================================================
42 template< class T >
44 public:
46  typedef void(T::* Operation)(const MsgHandler::MsgType, const std::string&);
47 
48 
54  MsgRetrievingFunction(T* object, Operation operation, MsgHandler::MsgType type) :
55  myObject(object),
56  myOperation(operation),
57  myMsgType(type) {}
58 
59 
62 
63 
64 protected:
67 
76  std::ostream& getOStream() {
77  return myMessage;
78  }
79 
80 
83  virtual void postWriteHook() {
85  myMessage.str("");
86  }
88 
89 
90 private:
93 
96 
98  MsgHandler::MsgType myMsgType;
99 
101  std::ostringstream myMessage;
102 
103 };
104 
105 
106 #endif
107 
108 /****************************************************************************/
109 
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:64
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.