1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Events_InfoMessage.hxx
4 // Created: 31 May 2016
5 // Author: Vitaly SMETANNIKOV
7 #ifndef Events_InfoMessage_H_
8 #define Events_InfoMessage_H_
11 #include <Events_Message.h>
12 #include <Events_Loop.h>
17 /**\class Events_InfoMessage
19 * \brief An event message for sending a string message which has to be translated.
21 class Events_InfoMessage: public Events_Message
26 /// \param theSender a pointer on sender object
27 Events_InfoMessage(const void* theSender = 0):Events_Message(Events_Loop::eventByName("InfoMessage"), theSender) {}
30 /// \param theSender a pointer on sender object
31 Events_InfoMessage(const std::string& theContext,
32 const std::string& theMsg, const void* theSender = 0):
33 Events_Message(Events_Loop::eventByName("InfoMessage"), theSender),
34 myContext(theContext), myMessage(theMsg) {}
36 /// default destructor
37 virtual ~Events_InfoMessage() {}
39 /// Identifier of this event (one for all errors)
40 static Events_ID errorID() { return Events_Loop::loop()->eventByName("InfoMessage"); }
42 /// Set a context string
43 /// \param theContext a context string
44 void setContext(const std::string& theContext) { myContext = theContext; }
47 /// Returns context string
48 std::string context() const { return myContext; }
50 /// Set message string for translation
51 /// \param theMsg the string of message
52 void setMessageString(const std::string& theMsg) { myMessage = theMsg; }
55 std::string messageString() const { return myMessage; }
57 /// Add parameter for message string of string type
58 /// \param theParam the parameter
59 void addParameter(const std::string& theParam)
61 myParameters.push_back(theParam);
64 /// Add parameter for message string of double type
65 /// \param theParam the parameter
66 void addParameter(double theParam)
69 int n = sprintf(aBuf, "%g", theParam);
70 std::string aStr(aBuf);
71 myParameters.push_back(aStr);
74 /// Add parameter for message string of integer type
75 /// \param theParam the parameter
76 void addParameter(int theParam)
79 int n = sprintf(aBuf, "%d", theParam);
80 std::string aStr(aBuf);
81 myParameters.push_back(aStr);
84 /// Returns list of parameters
85 std::list<std::string> parameters() const { return myParameters; }
87 /// Add parameter for message string of string type
88 /// \param theParam the parameter
89 Events_InfoMessage& arg(const std::string& theParam) { addParameter(theParam); return *this; }
91 /// Add parameter for message string of integer type
92 /// \param theParam the parameter
93 Events_InfoMessage& arg(int theParam) { addParameter(theParam); return *this; }
95 /// Add parameter for message string of double type
96 /// \param theParam the parameter
97 Events_InfoMessage& arg(double theParam) { addParameter(theParam); return *this; }
100 std::shared_ptr<Events_Message> aMsg(new Events_InfoMessage(*this));
101 Events_Loop::loop()->send(aMsg);
106 /// Context of the messgae
107 std::string myContext;
109 /// String of the message
110 std::string myMessage;
112 /// Parameters of the message
113 std::list<std::string> myParameters;