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 
98 
100  std::ostringstream myMessage;
101 
102 };
103 
104 
105 #endif
106 
107 /****************************************************************************/
108 
MsgRetrievingFunction::MsgRetrievingFunction
MsgRetrievingFunction(T *object, Operation operation, MsgHandler::MsgType type)
Constructor.
Definition: MsgRetrievingFunction.h:53
MsgHandler::MsgType
MsgType
Definition: MsgHandler.h:51
MsgRetrievingFunction::getOStream
std::ostream & getOStream()
Returns the associated ostream.
Definition: MsgRetrievingFunction.h:75
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
MsgHandler.h
MsgRetrievingFunction
Encapsulates an object's method for using it as a message retriever.
Definition: MsgRetrievingFunction.h:42
MsgRetrievingFunction::myMessage
std::ostringstream myMessage
message buffer
Definition: MsgRetrievingFunction.h:100
MsgRetrievingFunction::Operation
void(T::* Operation)(const MsgHandler::MsgType, const std::string &)
Type of the function to execute.
Definition: MsgRetrievingFunction.h:45
OutputDevice.h
MsgRetrievingFunction::myMsgType
MsgHandler::MsgType myMsgType
The type of message to retrieve.
Definition: MsgRetrievingFunction.h:97
MsgRetrievingFunction::myObject
T * myObject
The object the action is directed to.
Definition: MsgRetrievingFunction.h:91
MsgRetrievingFunction::postWriteHook
virtual void postWriteHook()
Sends the data which was written to the string stream via the retrieving function.
Definition: MsgRetrievingFunction.h:82
MsgRetrievingFunction::myOperation
Operation myOperation
The object's operation to perform.
Definition: MsgRetrievingFunction.h:94
MsgRetrievingFunction::~MsgRetrievingFunction
~MsgRetrievingFunction()
Destructor.
Definition: MsgRetrievingFunction.h:60