|
||||
File indexing completed on 2025-01-18 10:04:08
0001 // Created on: 1995-03-08 0002 // Created by: Christian CAILLET 0003 // Copyright (c) 1995-1999 Matra Datavision 0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _Interface_MSG_HeaderFile 0018 #define _Interface_MSG_HeaderFile 0019 0020 #include <Standard.hxx> 0021 #include <Standard_DefineAlloc.hxx> 0022 #include <Standard_Handle.hxx> 0023 0024 #include <Standard_PCharacter.hxx> 0025 #include <Standard_Real.hxx> 0026 #include <Standard_IStream.hxx> 0027 #include <Standard_OStream.hxx> 0028 0029 0030 //! This class gives a set of functions to manage and use a list 0031 //! of translated messages (messagery) 0032 //! 0033 //! Keys are strings, their corresponding (i.e. translated) items 0034 //! are strings, managed by a dictionary (a global one). 0035 //! 0036 //! If the dictionary is not set, or if a key is not recorded, 0037 //! the key is returned as item, and it is possible to : 0038 //! - trace or not this fail, record or not it for further trace 0039 //! 0040 //! It is also possible to suspend the translation (keys are then 0041 //! always returned as items) 0042 //! 0043 //! This class also provides a file format for loading : 0044 //! It is made of couples of lines, the first one begins by '@' 0045 //! the following is the key, the second one is the message 0046 //! Lines which are empty or which begin by '@@' are skipped 0047 class Interface_MSG 0048 { 0049 public: 0050 0051 DEFINE_STANDARD_ALLOC 0052 0053 0054 //! A MSG is created to write a "functional code" in conjunction 0055 //! with operator () attached to Value 0056 //! Then, to have a translated message, write in C++ : 0057 //! 0058 //! Interface_MSG("...mykey...") which returns a CString 0059 //! See also some help which follow 0060 Standard_EXPORT Interface_MSG(const Standard_CString key); 0061 0062 //! Translates a message which contains one integer variable 0063 //! It is just a help which avoid the following : 0064 //! char mess[100]; sprintf(mess,Interface_MSG("code"),ival); 0065 //! then AddFail(mess); 0066 //! replaced by AddFail (Interface_MSG("code",ival)); 0067 //! 0068 //! The basic message is intended to be in C-sprintf format, 0069 //! with one %d form in it 0070 Standard_EXPORT Interface_MSG(const Standard_CString key, const Standard_Integer i1); 0071 0072 //! Translates a message which contains two integer variables 0073 //! As for one integer, it is just a writing help 0074 //! 0075 //! The basic message is intended to be in C-sprintf format 0076 //! with two %d forms in it 0077 Standard_EXPORT Interface_MSG(const Standard_CString key, const Standard_Integer i1, const Standard_Integer i2); 0078 0079 //! Translates a message which contains one real variable 0080 //! <intervals> if set, commands the variable to be rounded to an 0081 //! interval (see below, method Intervals) 0082 //! As for one integer, it is just a writing help 0083 //! 0084 //! The basic message is intended to be in C-sprintf format 0085 //! with one %f form (or equivalent : %e etc) in it 0086 Standard_EXPORT Interface_MSG(const Standard_CString key, const Standard_Real r1, const Standard_Integer intervals = -1); 0087 0088 //! Translates a message which contains one string variable 0089 //! As for one integer, it is just a writing help 0090 //! 0091 //! The basic message is intended to be in C-sprintf format 0092 //! with one %s form in it 0093 Standard_EXPORT Interface_MSG(const Standard_CString key, const Standard_CString str); 0094 0095 //! Translates a message which contains one integer and one 0096 //! string variables 0097 //! As for one integer, it is just a writing help 0098 //! Used for instance to say "Param n0.<ival> i.e. <str> is not.." 0099 //! 0100 //! The basic message is intended to be in C-sprintf format 0101 //! with one %d then one %s forms in it 0102 Standard_EXPORT Interface_MSG(const Standard_CString key, const Standard_Integer ival, const Standard_CString str); 0103 0104 //! Optimised destructor (applies for additional forms of Create) 0105 Standard_EXPORT void Destroy(); 0106 ~Interface_MSG() 0107 { 0108 Destroy(); 0109 } 0110 0111 //! Returns the translated message, in a functional form with 0112 //! operator () 0113 //! was C++ : return const 0114 Standard_EXPORT Standard_CString Value() const; 0115 operator Standard_CString() const; 0116 0117 //! Reads a list of messages from a stream, returns read count 0118 //! 0 means empty file, -1 means error 0119 Standard_EXPORT static Standard_Integer Read (Standard_IStream& S); 0120 0121 //! Reads a list of messages from a file defined by its name 0122 Standard_EXPORT static Standard_Integer Read (const Standard_CString file); 0123 0124 //! Writes the list of messages recorded to be translated, to a 0125 //! stream. Writes all the list (Default) or only keys which begin 0126 //! by <rootkey>. Returns the count of written messages 0127 Standard_EXPORT static Standard_Integer Write (Standard_OStream& S, const Standard_CString rootkey = ""); 0128 0129 //! Returns True if a given message is surely a key 0130 //! (according to the form adopted for keys) 0131 //! (before activating messages, answer is false) 0132 Standard_EXPORT static Standard_Boolean IsKey (const Standard_CString mess); 0133 0134 //! Returns the item recorded for a key. 0135 //! Returns the key itself if : 0136 //! - it is not recorded (then, the trace system is activated) 0137 //! - MSG has been required to be hung on 0138 Standard_EXPORT static Standard_CString Translated (const Standard_CString key); 0139 0140 //! Fills the dictionary with a couple (key-item) 0141 //! If a key is already recorded, it is possible to : 0142 //! - keep the last definition, and activate the trace system 0143 Standard_EXPORT static void Record (const Standard_CString key, const Standard_CString item); 0144 0145 //! Sets the trace system to work when activated, as follow : 0146 //! - if <toprint> is True, print immediately on standard output 0147 //! - if <torecord> is True, record it for further print 0148 Standard_EXPORT static void SetTrace (const Standard_Boolean toprint, const Standard_Boolean torecord); 0149 0150 //! Sets the main modes for MSG : 0151 //! - if <running> is True, translation works normally 0152 //! - if <running> is False, translated item equate keys 0153 //! - if <raising> is True, errors (from Record or Translate) 0154 //! cause MSG to raise an exception 0155 //! - if <raising> is False, MSG runs without exception, then 0156 //! see also Trace Modes above 0157 Standard_EXPORT static void SetMode (const Standard_Boolean running, const Standard_Boolean raising); 0158 0159 //! Prints the recorded errors (without title; can be empty, this 0160 //! is the normally expected case) 0161 Standard_EXPORT static void PrintTrace (Standard_OStream& S); 0162 0163 //! Returns an "intervalled" value from a starting real <val> : 0164 //! i.e. a value which is rounded on an interval limit 0165 //! Interval limits are defined to be in a coarsely "geometric" 0166 //! progression (two successive intervals are inside a limit ratio) 0167 //! 0168 //! <order> gives the count of desired intervals in a range <1-10> 0169 //! <upper> False, returns the first lower interval (D) 0170 //! <upper> True, returns the first upper interval 0171 //! Values of Intervals according <order> : 0172 //! 0,1 : 1 10 100 ... 0173 //! 2 : 1 3 10 30 100 ... 0174 //! 3(D): 1 2 5 10 20 50 100 ... 0175 //! 4 : 1 2 3 6 10 20 30 60 100 ... 0176 //! 6 : 1 1.5 2 3 5 7 10 15 20 ... 0177 //! 10 : 1 1.2 1.5 2 2.5 3 4 5 6 8 10 12 15 20 25 ... 0178 Standard_EXPORT static Standard_Real Intervalled (const Standard_Real val, const Standard_Integer order = 3, const Standard_Boolean upper = Standard_False); 0179 0180 //! Codes a date as a text, from its numeric value (-> seconds) : 0181 //! YYYY-MM-DD:HH-MN-SS fixed format, completed by leading zeros 0182 //! Another format can be provided, as follows : 0183 //! C:%d ... C like format, preceded by C: 0184 //! S:... format to call system (not yet implemented) 0185 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 = ""); 0186 0187 //! Decodes a date to numeric integer values 0188 //! Returns True if OK, False if text does not fit with required 0189 //! format. Incomplete forms are allowed (for instance, for only 0190 //! YYYY-MM-DD, hour is zero) 0191 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); 0192 0193 //! Returns a value about comparison of two dates 0194 //! 0 : equal. <0 text1 anterior. >0 text1 posterior 0195 Standard_EXPORT static Standard_Integer CDate (const Standard_CString text1, const Standard_CString text2); 0196 0197 //! Returns a blank string, of length between 0 and <max>, to fill 0198 //! the printing of a numeric value <val>, i.e. : 0199 //! If val < 10 , max-1 blanks 0200 //! If val between 10 and 99, max-2 blanks ... etc... 0201 Standard_EXPORT static Standard_CString Blanks (const Standard_Integer val, const Standard_Integer max); 0202 0203 //! Returns a blank string, to complete a given string <val> up to 0204 //! <max> characters : 0205 //! If strlen(val) is 0, max blanks 0206 //! If strlen(val) is 5, max-5 blanks etc... 0207 Standard_EXPORT static Standard_CString Blanks (const Standard_CString val, const Standard_Integer max); 0208 0209 //! Returns a blank string of <count> blanks (mini 0, maxi 76) 0210 Standard_EXPORT static Standard_CString Blanks (const Standard_Integer count); 0211 0212 //! Prints a String on an Output Stream, as follows : 0213 //! Accompanied with blanks, to give up to <max> charis at all, 0214 //! justified according just : 0215 //! -1 (D) : left 0 : center 1 : right 0216 //! Maximum 76 characters 0217 Standard_EXPORT static void Print (Standard_OStream& S, const Standard_CString val, const Standard_Integer max, const Standard_Integer just = -1); 0218 0219 0220 0221 0222 protected: 0223 0224 0225 0226 0227 0228 private: 0229 0230 0231 0232 Standard_CString thekey; 0233 Standard_PCharacter theval; 0234 0235 0236 }; 0237 0238 0239 0240 0241 0242 0243 0244 #endif // _Interface_MSG_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |