Eclipse 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-2019 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 
26 #include <string>
27 #include <sstream>
29 #include "MsgHandler.h"
30 
31 
32 // ===========================================================================
33 // class definitions
34 // ===========================================================================
41 template< class T >
43 public:
45  typedef void(T::* Operation)(const MsgHandler::MsgType, const std::string&);
46 
47 
53  MsgRetrievingFunction(T* object, Operation operation, MsgHandler::MsgType type) :
54  myObject(object),
55  myOperation(operation),
56  myMsgType(type) {}
57 
58 
61 
62 
63 protected:
66 
75  std::ostream& getOStream() {
76  return myMessage;
77  }
78 
79 
82  virtual void postWriteHook() {
84  myMessage.str("");
85  }
87 
88 
89 private:
92 
95 
97  MsgHandler::MsgType myMsgType;
98 
100  std::ostringstream myMessage;
101 
102 };
103 
104 
105 #endif
106 
107 /****************************************************************************/
108 
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.