Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-04 09:15:04

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