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>
14 /**\class Events_InfoMessage
16 * \brief An event message for sending a string message which has to be translated.
18 class Events_InfoMessage: public Events_Message
23 /// \param theSender a pointer on sender object
24 Events_InfoMessage(const void* theSender = 0):Events_Message(Events_Loop::eventByName("InfoMessage"), theSender) {}
27 /// \param theSender a pointer on sender object
28 Events_InfoMessage(const std::string& theContext,
29 const std::string& theMsg, const void* theSender = 0):
30 Events_Message(Events_Loop::eventByName("InfoMessage"), theSender),
31 myContext(theContext), myMessage(theMsg) {}
33 /// default destructor
34 virtual ~Events_InfoMessage() {}
36 /// Identifier of this event (one for all errors)
37 static Events_ID errorID() { return Events_Loop::loop()->eventByName("InfoMessage"); }
39 /// Set a context string
40 /// \param theContext a context string
41 void setContext(const std::string& theContext) { myContext = theContext; }
44 /// Returns context string
45 std::string context() const { return myContext; }
47 /// Set message string for translation
48 /// \param theMsg the string of message
49 void setMessageString(const std::string& theMsg) { myMessage = theMsg; }
52 std::string messageString() const { return myMessage; }
54 /// Add parameter for message string of string type
55 /// \param theParam the parameter
56 void addParameter(const std::string& theParam)
58 myParameters.push_back(theParam);
61 /// Add parameter for message string of double type
62 /// \param theParam the parameter
63 void addParameter(double theParam)
66 int n = sprintf(aBuf, "%g", theParam);
67 std::string aStr(aBuf);
68 myParameters.push_back(aStr);
71 /// Add parameter for message string of integer type
72 /// \param theParam the parameter
73 void addParameter(int theParam)
76 int n = sprintf(aBuf, "%d", theParam);
77 std::string aStr(aBuf);
78 myParameters.push_back(aStr);
81 /// Returns list of parameters
82 std::list<std::string> parameters() const { return myParameters; }
84 /// Add parameter for message string of string type
85 /// \param theParam the parameter
86 Events_InfoMessage& arg(const std::string& theParam) { addParameter(theParam); return *this; }
88 /// Add parameter for message string of integer type
89 /// \param theParam the parameter
90 Events_InfoMessage& arg(int theParam) { addParameter(theParam); return *this; }
92 /// Add parameter for message string of double type
93 /// \param theParam the parameter
94 Events_InfoMessage& arg(double theParam) { addParameter(theParam); return *this; }
97 std::shared_ptr<Events_Message> aMsg(new Events_InfoMessage(*this));
98 Events_Loop::loop()->send(aMsg);
103 /// Context of the messgae
104 std::string myContext;
106 /// String of the message
107 std::string myMessage;
109 /// Parameters of the message
110 std::list<std::string> myParameters;