0024023: Revamp the OCCT Handle - gcc and clang
[occt.git] / src / Message / Message_Msg.hxx
1 // Created on: 2001-01-18
2 // Created by: OCC Team
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _Message_Msg_HeaderFile
17 #define _Message_Msg_HeaderFile
18
19 #include <Standard.hxx>
20 #include <Standard_DefineAlloc.hxx>
21 #include <Standard_Handle.hxx>
22
23 #include <TCollection_HAsciiString.hxx>
24 #include <TCollection_HExtendedString.hxx>
25 #include <TColStd_SequenceOfInteger.hxx>
26
27 class TCollection_ExtendedString;
28 class TCollection_AsciiString;
29 class TCollection_HAsciiString;
30 class TCollection_HExtendedString;
31
32
33 //! This class provides a tool for constructing the parametrized message
34 //! basing on resources loaded by Message_MsgFile tool.
35 //!
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().
39 //!
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).
46 //!
47 //! User fills the parameter fields in the text of the message by
48 //! calling corresponding methods Arg() or operators "<<".
49 //!
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.
53 class Message_Msg 
54 {
55 public:
56
57   DEFINE_STANDARD_ALLOC
58
59   
60   //! Empty constructor
61   Standard_EXPORT Message_Msg();
62   
63   //! Copy constructor
64   Standard_EXPORT Message_Msg(const Message_Msg& theMsg);
65   
66   //! Create a message using a corresponding entry in Message_MsgFile
67   Standard_EXPORT Message_Msg(const Standard_CString theKey);
68   
69   //! Create a message using a corresponding entry in Message_MsgFile
70   Standard_EXPORT Message_Msg(const TCollection_ExtendedString& theKey);
71   
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);
75   
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);
79   
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)
83 {
84   return Arg(theString);
85 }
86   
87   //! Set a value for %..s conversion
88     Message_Msg& Arg (const TCollection_AsciiString& theString);
89   Message_Msg& operator << (const TCollection_AsciiString& theString)
90 {
91   return Arg(theString);
92 }
93   
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)
97 {
98   return Arg(theString);
99 }
100   
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)
104 {
105   return Arg(theString);
106 }
107   
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)
111 {
112   return Arg(theString);
113 }
114   
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)
118 {
119   return Arg(theInt);
120 }
121   
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)
125 {
126   return Arg(theReal);
127 }
128   
129   //! Returns the original message text
130     const TCollection_ExtendedString& Original() const;
131   
132   //! Returns current state of the message text with
133   //! parameters to the moment
134     const TCollection_ExtendedString& Value() const;
135   
136   //! Tells if Value differs from Original
137     Standard_Boolean IsEdited() const;
138   
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
142   //! the word UNKNOWN
143   Standard_EXPORT const TCollection_ExtendedString& Get();
144 operator const TCollection_ExtendedString& () { return Get(); }
145
146
147
148
149 protected:
150
151
152
153
154
155 private:
156
157   
158   Standard_EXPORT Standard_Integer getFormat (const Standard_Integer theType, TCollection_AsciiString& theFormat);
159   
160   Standard_EXPORT void replaceText (const Standard_Integer theFirst, const Standard_Integer theNb, const TCollection_ExtendedString& theStr);
161
162
163   TCollection_ExtendedString myOriginal;
164   TCollection_ExtendedString myMessageBody;
165   TColStd_SequenceOfInteger mySeqOfFormats;
166
167
168 };
169
170
171 #include <Message_Msg.lxx>
172
173
174
175
176
177 #endif // _Message_Msg_HeaderFile