1 // Created on: 1995-03-08
2 // Created by: Christian CAILLET
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Interface_MSG_HeaderFile
18 #define _Interface_MSG_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Standard_CString.hxx>
25 #include <Standard_PCharacter.hxx>
26 #include <Standard_Integer.hxx>
27 #include <Standard_Real.hxx>
28 #include <Standard_IStream.hxx>
29 #include <Standard_OStream.hxx>
30 #include <Standard_Boolean.hxx>
31 class Standard_DomainError;
34 //! This class gives a set of functions to manage and use a list
35 //! of translated messages (messagery)
37 //! Keys are strings, their corresponding (i.e. translated) items
38 //! are strings, managed by a dictionary (a global one).
40 //! If the dictionary is not set, or if a key is not recorded,
41 //! the key is returned as item, and it is possible to :
42 //! - trace or not this fail, record or not it for further trace
44 //! It is also possible to suspend the translation (keys are then
45 //! always returned as items)
47 //! This class also provides a file format for loading :
48 //! It is made of couples of lines, the first one begins by '@'
49 //! the following is the key, the second one is the message
50 //! Lines which are empty or which begin by '@@' are skipped
58 //! A MSG is created to write a "functional code" in conjunction
59 //! with operator () attached to Value
60 //! Then, to have a translated message, write in C++ :
62 //! Interface_MSG("...mykey...") which returns a CString
63 //! See also some help which follow
64 Standard_EXPORT Interface_MSG(const Standard_CString key);
66 //! Translates a message which contains one integer variable
67 //! It is just a help which avoid the following :
68 //! char mess[100]; sprintf(mess,Interface_MSG("code"),ival);
69 //! then AddFail(mess);
70 //! replaced by AddFail (Interface_MSG("code",ival));
72 //! The basic message is intended to be in C-sprintf format,
73 //! with one %d form in it
74 Standard_EXPORT Interface_MSG(const Standard_CString key, const Standard_Integer i1);
76 //! Translates a message which contains two integer variables
77 //! As for one integer, it is just a writing help
79 //! The basic message is intended to be in C-sprintf format
80 //! with two %d forms in it
81 Standard_EXPORT Interface_MSG(const Standard_CString key, const Standard_Integer i1, const Standard_Integer i2);
83 //! Translates a message which contains one real variable
84 //! <intervals> if set, commands the variable to be rounded to an
85 //! interval (see below, method Intervals)
86 //! As for one integer, it is just a writing help
88 //! The basic message is intended to be in C-sprintf format
89 //! with one %f form (or equivalent : %e etc) in it
90 Standard_EXPORT Interface_MSG(const Standard_CString key, const Standard_Real r1, const Standard_Integer intervals = -1);
92 //! Translates a message which contains one string variable
93 //! As for one integer, it is just a writing help
95 //! The basic message is intended to be in C-sprintf format
96 //! with one %s form in it
97 Standard_EXPORT Interface_MSG(const Standard_CString key, const Standard_CString str);
99 //! Translates a message which contains one integer and one
101 //! As for one integer, it is just a writing help
102 //! Used for instance to say "Param n0.<ival> i.e. <str> is not.."
104 //! The basic message is intended to be in C-sprintf format
105 //! with one %d then one %s forms in it
106 Standard_EXPORT Interface_MSG(const Standard_CString key, const Standard_Integer ival, const Standard_CString str);
108 //! Optimised destructor (applies for additional forms of Create)
109 Standard_EXPORT void Destroy();
115 //! Returns the translated message, in a functional form with
117 //! was C++ : return const
118 Standard_EXPORT Standard_CString Value() const;
119 operator Standard_CString() const;
121 //! Reads a list of messages from a stream, returns read count
122 //! 0 means empty file, -1 means error
123 Standard_EXPORT static Standard_Integer Read (Standard_IStream& S);
125 //! Reads a list of messages from a file defined by its name
126 Standard_EXPORT static Standard_Integer Read (const Standard_CString file);
128 //! Writes the list of messages recorded to be translated, to a
129 //! stream. Writes all the list (Default) or only keys which begin
130 //! by <rootkey>. Returns the count of written messages
131 Standard_EXPORT static Standard_Integer Write (Standard_OStream& S, const Standard_CString rootkey = "");
133 //! Returns True if a given message is surely a key
134 //! (according to the form adopted for keys)
135 //! (before activating messages, answer is false)
136 Standard_EXPORT static Standard_Boolean IsKey (const Standard_CString mess);
138 //! Returns the item recorded for a key.
139 //! Returns the key itself if :
140 //! - it is not recorded (then, the trace system is activated)
141 //! - MSG has been required to be hung on
142 Standard_EXPORT static Standard_CString Translated (const Standard_CString key);
144 //! Fills the dictionary with a couple (key-item)
145 //! If a key is already recorded, it is possible to :
146 //! - keep the last definition, and activate the trace system
147 Standard_EXPORT static void Record (const Standard_CString key, const Standard_CString item);
149 //! Sets the trace system to work when activated, as follow :
150 //! - if <toprint> is True, print immediately on standard output
151 //! - if <torecord> is True, record it for further print
152 Standard_EXPORT static void SetTrace (const Standard_Boolean toprint, const Standard_Boolean torecord);
154 //! Sets the main modes for MSG :
155 //! - if <running> is True, translation works normally
156 //! - if <running> is False, translated item equate keys
157 //! - if <raising> is True, errors (from Record or Translate)
158 //! cause MSG to raise an exception
159 //! - if <raising> is False, MSG runs without exception, then
160 //! see also Trace Modes above
161 Standard_EXPORT static void SetMode (const Standard_Boolean running, const Standard_Boolean raising);
163 //! Prints the recorded errors (without title; can be empty, this
164 //! is the normally expected case)
165 Standard_EXPORT static void PrintTrace (Standard_OStream& S);
167 //! Returns an "intervalled" value from a starting real <val> :
168 //! i.e. a value which is rounded on an interval limit
169 //! Interval limits are defined to be in a coarsely "geometric"
170 //! progression (two successive intervals are inside a limit ratio)
172 //! <order> gives the count of desired intervals in a range <1-10>
173 //! <upper> False, returns the first lower interval (D)
174 //! <upper> True, returns the first upper interval
175 //! Values of Intervals according <order> :
176 //! 0,1 : 1 10 100 ...
177 //! 2 : 1 3 10 30 100 ...
178 //! 3(D): 1 2 5 10 20 50 100 ...
179 //! 4 : 1 2 3 6 10 20 30 60 100 ...
180 //! 6 : 1 1.5 2 3 5 7 10 15 20 ...
181 //! 10 : 1 1.2 1.5 2 2.5 3 4 5 6 8 10 12 15 20 25 ...
182 Standard_EXPORT static Standard_Real Intervalled (const Standard_Real val, const Standard_Integer order = 3, const Standard_Boolean upper = Standard_False);
184 //! Codes a date as a text, from its numeric value (-> seconds) :
185 //! YYYY-MM-DD:HH-MN-SS fixed format, completed by leading zeros
186 //! Another format can be provided, as follows :
187 //! C:%d ... C like format, preceded by C:
188 //! S:... format to call system (not yet implemented)
189 Standard_EXPORT static void TDate (const Standard_CString text, const Standard_Integer yy, const Standard_Integer mm, const Standard_Integer dd, const Standard_Integer hh, const Standard_Integer mn, const Standard_Integer ss, const Standard_CString format = "");
191 //! Decodes a date to numeric integer values
192 //! Returns True if OK, False if text does not fit with required
193 //! format. Incomplete forms are allowed (for instance, for only
194 //! YYYY-MM-DD, hour is zero)
195 Standard_EXPORT static Standard_Boolean NDate (const Standard_CString text, Standard_Integer& yy, Standard_Integer& mm, Standard_Integer& dd, Standard_Integer& hh, Standard_Integer& mn, Standard_Integer& ss);
197 //! Returns a value about comparison of two dates
198 //! 0 : equal. <0 text1 anterior. >0 text1 posterior
199 Standard_EXPORT static Standard_Integer CDate (const Standard_CString text1, const Standard_CString text2);
201 //! Returns a blank string, of length between 0 and <max>, to fill
202 //! the printing of a numeric value <val>, i.e. :
203 //! If val < 10 , max-1 blanks
204 //! If val between 10 and 99, max-2 blanks ... etc...
205 Standard_EXPORT static Standard_CString Blanks (const Standard_Integer val, const Standard_Integer max);
207 //! Returns a blank string, to complete a given string <val> up to
208 //! <max> characters :
209 //! If strlen(val) is 0, max blanks
210 //! If strlen(val) is 5, max-5 blanks etc...
211 Standard_EXPORT static Standard_CString Blanks (const Standard_CString val, const Standard_Integer max);
213 //! Returns a blank string of <count> blanks (mini 0, maxi 76)
214 Standard_EXPORT static Standard_CString Blanks (const Standard_Integer count);
216 //! Prints a String on an Output Stream, as follows :
217 //! Accompanied with blanks, to give up to <max> charis at all,
218 //! justified according just :
219 //! -1 (D) : left 0 : center 1 : right
220 //! Maximum 76 characters
221 Standard_EXPORT static void Print (Standard_OStream& S, const Standard_CString val, const Standard_Integer max, const Standard_Integer just = -1);
236 Standard_CString thekey;
237 Standard_PCharacter theval;
248 #endif // _Interface_MSG_HeaderFile