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 /****************************************************************************/
15 // Encapsulates an object's method for using it as a message retriever
16 /****************************************************************************/
17 #ifndef MsgRetrievingFunction_h
18 #define MsgRetrievingFunction_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 
25 #include <string>
26 #include <sstream>
28 #include "MsgHandler.h"
29 
30 
31 // ===========================================================================
32 // class definitions
33 // ===========================================================================
40 template< class T >
42 public:
44  typedef void(T::* Operation)(const MsgHandler::MsgType, const std::string&);
45 
46 
52  MsgRetrievingFunction(T* object, Operation operation, MsgHandler::MsgType type) :
53  myObject(object),
54  myOperation(operation),
55  myMsgType(type) {}
56 
57 
60 
61 
62 protected:
65 
74  std::ostream& getOStream() {
75  return myMessage;
76  }
77 
78 
81  virtual void postWriteHook() {
83  myMessage.str("");
84  }
86 
87 
88 private:
91 
94 
97 
99  std::ostringstream myMessage;
100 
101 };
102 
103 
104 #endif
105 
106 /****************************************************************************/
107 
MsgRetrievingFunction::MsgRetrievingFunction
MsgRetrievingFunction(T *object, Operation operation, MsgHandler::MsgType type)
Constructor.
Definition: MsgRetrievingFunction.h:52
MsgHandler::MsgType
MsgType
Definition: MsgHandler.h:45
MsgRetrievingFunction::getOStream
std::ostream & getOStream()
Returns the associated ostream.
Definition: MsgRetrievingFunction.h:74
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
MsgHandler.h
MsgRetrievingFunction
Encapsulates an object's method for using it as a message retriever.
Definition: MsgRetrievingFunction.h:41
MsgRetrievingFunction::myMessage
std::ostringstream myMessage
message buffer
Definition: MsgRetrievingFunction.h:99
MsgRetrievingFunction::Operation
void(T::* Operation)(const MsgHandler::MsgType, const std::string &)
Type of the function to execute.
Definition: MsgRetrievingFunction.h:44
OutputDevice.h
MsgRetrievingFunction::myMsgType
MsgHandler::MsgType myMsgType
The type of message to retrieve.
Definition: MsgRetrievingFunction.h:96
MsgRetrievingFunction::myObject
T * myObject
The object the action is directed to.
Definition: MsgRetrievingFunction.h:90
MsgRetrievingFunction::postWriteHook
virtual void postWriteHook()
Sends the data which was written to the string stream via the retrieving function.
Definition: MsgRetrievingFunction.h:81
MsgRetrievingFunction::myOperation
Operation myOperation
The object's operation to perform.
Definition: MsgRetrievingFunction.h:93
MsgRetrievingFunction::~MsgRetrievingFunction
~MsgRetrievingFunction()
Destructor.
Definition: MsgRetrievingFunction.h:59