1 // Created on: 2001-01-18
2 // Created by: OCC Team
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _Message_Msg_HeaderFile
17 #define _Message_Msg_HeaderFile
19 #include <Standard.hxx>
20 #include <Standard_DefineAlloc.hxx>
21 #include <Standard_Handle.hxx>
23 #include <TCollection_HAsciiString.hxx>
24 #include <TCollection_HExtendedString.hxx>
25 #include <TColStd_SequenceOfInteger.hxx>
27 class TCollection_ExtendedString;
28 class TCollection_AsciiString;
29 class TCollection_HAsciiString;
30 class TCollection_HExtendedString;
33 //! This class provides a tool for constructing the parametrized message
34 //! basing on resources loaded by Message_MsgFile tool.
36 //! A Message is created from a keyword: this keyword identifies the
37 //! message in a message file that should be previously loaded by call
38 //! to Message_MsgFile::LoadFile().
40 //! The text of the message can contain placeholders for the parameters
41 //! which are to be filled by the proper values when the message
42 //! is prepared. Most of the format specifiers used in C can be used,
43 //! for instance, %s for string, %d for integer etc. In addition,
44 //! specifier %f is supported for double numbers (for compatibility
45 //! with previous versions).
47 //! User fills the parameter fields in the text of the message by
48 //! calling corresponding methods Arg() or operators "<<".
50 //! The resulting message, filled with all parameters, can be obtained
51 //! by method Get(). If some parameters were not filled, the text
52 //! UNKNOWN is placed instead.
61 Standard_EXPORT Message_Msg();
64 Standard_EXPORT Message_Msg(const Message_Msg& theMsg);
66 //! Create a message using a corresponding entry in Message_MsgFile
67 Standard_EXPORT Message_Msg(const Standard_CString theKey);
69 //! Create a message using a corresponding entry in Message_MsgFile
70 Standard_EXPORT Message_Msg(const TCollection_ExtendedString& theKey);
72 //! Set a message body text -- can be used as alternative to
73 //! using messages from resource file
74 Standard_EXPORT void Set (const Standard_CString theMsg);
76 //! Set a message body text -- can be used as alternative to
77 //! using messages from resource file
78 Standard_EXPORT void Set (const TCollection_ExtendedString& theMsg);
80 //! Set a value for %..s conversion
81 Standard_EXPORT Message_Msg& Arg (const Standard_CString theString);
82 Message_Msg& operator << (const Standard_CString theString)
84 return Arg(theString);
87 //! Set a value for %..s conversion
88 Message_Msg& Arg (const TCollection_AsciiString& theString);
89 Message_Msg& operator << (const TCollection_AsciiString& theString)
91 return Arg(theString);
94 //! Set a value for %..s conversion
95 Message_Msg& Arg (const Handle(TCollection_HAsciiString)& theString);
96 Message_Msg& operator << (const Handle(TCollection_HAsciiString)& theString)
98 return Arg(theString);
101 //! Set a value for %..s conversion
102 Standard_EXPORT Message_Msg& Arg (const TCollection_ExtendedString& theString);
103 Message_Msg& operator << (const TCollection_ExtendedString& theString)
105 return Arg(theString);
108 //! Set a value for %..s conversion
109 Message_Msg& Arg (const Handle(TCollection_HExtendedString)& theString);
110 Message_Msg& operator << (const Handle(TCollection_HExtendedString)& theString)
112 return Arg(theString);
115 //! Set a value for %..d, %..i, %..o, %..u, %..x or %..X conversion
116 Standard_EXPORT Message_Msg& Arg (const Standard_Integer theInt);
117 Message_Msg& operator << (const Standard_Integer theInt)
122 //! Set a value for %..f, %..e, %..E, %..g or %..G conversion
123 Standard_EXPORT Message_Msg& Arg (const Standard_Real theReal);
124 Message_Msg& operator << (const Standard_Real theReal)
129 //! Returns the original message text
130 const TCollection_ExtendedString& Original() const;
132 //! Returns current state of the message text with
133 //! parameters to the moment
134 const TCollection_ExtendedString& Value() const;
136 //! Tells if Value differs from Original
137 Standard_Boolean IsEdited() const;
139 //! Return the resulting message string with all parameters
140 //! filled. If some parameters were not yet filled by calls
141 //! to methods Arg (or <<), these parameters are filled by
143 Standard_EXPORT const TCollection_ExtendedString& Get();
144 operator const TCollection_ExtendedString& () { return Get(); }
158 Standard_EXPORT Standard_Integer getFormat (const Standard_Integer theType, TCollection_AsciiString& theFormat);
160 Standard_EXPORT void replaceText (const Standard_Integer theFirst, const Standard_Integer theNb, const TCollection_ExtendedString& theStr);
163 TCollection_ExtendedString myOriginal;
164 TCollection_ExtendedString myMessageBody;
165 TColStd_SequenceOfInteger mySeqOfFormats;
171 #include <Message_Msg.lxx>
177 #endif // _Message_Msg_HeaderFile