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.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
19 // Encapsulates an object's method for using it as a message retriever
20 /****************************************************************************/
21 #pragma once
22 #include <config.h>
23 #include <string>
24 #include <sstream>
26 #include "MsgHandler.h"
27 
28 
29 // ===========================================================================
30 // class definitions
31 // ===========================================================================
38 template< class T >
40 public:
42  typedef void(T::* Operation)(const MsgHandler::MsgType, const std::string&);
43 
44 
50  MsgRetrievingFunction(T* object, Operation operation, MsgHandler::MsgType type) :
51  myObject(object),
52  myOperation(operation),
53  myMsgType(type) {}
54 
55 
58 
59 
60 protected:
63 
72  std::ostream& getOStream() {
73  return myMessage;
74  }
75 
76 
79  virtual void postWriteHook() {
81  myMessage.str("");
82  }
84 
85 
86 private:
89 
92 
95 
97  std::ostringstream myMessage;
98 
99 };
Encapsulates an object's method for using it as a message retriever.
void(T::* Operation)(const MsgHandler::MsgType, const std::string &)
Type of the function to execute.
virtual void postWriteHook()
Sends the data which was written to the string stream via the retrieving function.
MsgHandler::MsgType myMsgType
The type of message to retrieve.
std::ostream & getOStream()
Returns the associated ostream.
std::ostringstream myMessage
message buffer
Operation myOperation
The object's operation to perform.
MsgRetrievingFunction(T *object, Operation operation, MsgHandler::MsgType type)
Constructor.
T * myObject
The object the action is directed to.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61