Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-14 09:15:16

0001 // Created on: 2001-01-18
0002 // Created by: OCC Team
0003 // Copyright (c) 2001-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _Message_Msg_HeaderFile
0017 #define _Message_Msg_HeaderFile
0018 
0019 #include <Standard.hxx>
0020 #include <Standard_DefineAlloc.hxx>
0021 #include <Standard_Handle.hxx>
0022 
0023 #include <TCollection_HAsciiString.hxx>
0024 #include <TCollection_HExtendedString.hxx>
0025 #include <Standard_Integer.hxx>
0026 #include <NCollection_Sequence.hxx>
0027 
0028 class TCollection_AsciiString;
0029 class TCollection_HAsciiString;
0030 class TCollection_HExtendedString;
0031 
0032 //! This class provides a tool for constructing the parametrized message
0033 //! basing on resources loaded by Message_MsgFile tool.
0034 //!
0035 //! A Message is created from a keyword: this keyword identifies the
0036 //! message in a message file that should be previously loaded by call
0037 //! to Message_MsgFile::LoadFile().
0038 //!
0039 //! The text of the message can contain placeholders for the parameters
0040 //! which are to be filled by the proper values when the message
0041 //! is prepared. Most of the format specifiers used in C can be used,
0042 //! for instance, %s for string, %d for integer etc. In addition,
0043 //! specifier %f is supported for double numbers (for compatibility
0044 //! with previous versions).
0045 //!
0046 //! User fills the parameter fields in the text of the message by
0047 //! calling corresponding methods Arg() or operators .
0048 //!
0049 //! The resulting message, filled with all parameters, can be obtained
0050 //! by method Get(). If some parameters were not filled, the text
0051 //! UNKNOWN is placed instead.
0052 class Message_Msg
0053 {
0054 public:
0055   DEFINE_STANDARD_ALLOC
0056 
0057   //! Empty constructor
0058   Standard_EXPORT Message_Msg();
0059 
0060   //! Copy constructor
0061   Standard_EXPORT Message_Msg(const Message_Msg& theMsg);
0062 
0063   //! Create a message using a corresponding entry in Message_MsgFile
0064   Standard_EXPORT Message_Msg(const char* const theKey);
0065 
0066   //! Create a message using a corresponding entry in Message_MsgFile
0067   Standard_EXPORT Message_Msg(const TCollection_ExtendedString& theKey);
0068 
0069   //! Set a message body text -- can be used as alternative to
0070   //! using messages from resource file
0071   Standard_EXPORT void Set(const char* const theMsg);
0072 
0073   //! Set a message body text -- can be used as alternative to
0074   //! using messages from resource file
0075   Standard_EXPORT void Set(const TCollection_ExtendedString& theMsg);
0076 
0077   //! Set a value for %..s conversion
0078   Standard_EXPORT Message_Msg& Arg(const char* const theString);
0079 
0080   Message_Msg& operator<<(const char* const theString) { return Arg(theString); }
0081 
0082   //! Set a value for %..s conversion
0083   Message_Msg& Arg(const TCollection_AsciiString& theString);
0084 
0085   Message_Msg& operator<<(const TCollection_AsciiString& theString) { return Arg(theString); }
0086 
0087   //! Set a value for %..s conversion
0088   Message_Msg& Arg(const occ::handle<TCollection_HAsciiString>& theString);
0089 
0090   Message_Msg& operator<<(const occ::handle<TCollection_HAsciiString>& theString)
0091   {
0092     return Arg(theString);
0093   }
0094 
0095   //! Set a value for %..s conversion
0096   Standard_EXPORT Message_Msg& Arg(const TCollection_ExtendedString& theString);
0097 
0098   Message_Msg& operator<<(const TCollection_ExtendedString& theString) { return Arg(theString); }
0099 
0100   //! Set a value for %..s conversion
0101   Message_Msg& Arg(const occ::handle<TCollection_HExtendedString>& theString);
0102 
0103   Message_Msg& operator<<(const occ::handle<TCollection_HExtendedString>& theString)
0104   {
0105     return Arg(theString);
0106   }
0107 
0108   //! Set a value for %..d, %..i, %..o, %..u, %..x or %..X conversion
0109   Standard_EXPORT Message_Msg& Arg(const int theInt);
0110 
0111   Message_Msg& operator<<(const int theInt) { return Arg(theInt); }
0112 
0113   //! Set a value for %..f, %..e, %..E, %..g or %..G conversion
0114   Standard_EXPORT Message_Msg& Arg(const double theReal);
0115 
0116   Message_Msg& operator<<(const double theReal) { return Arg(theReal); }
0117 
0118   //! Returns the original message text
0119   const TCollection_ExtendedString& Original() const;
0120 
0121   //! Returns current state of the message text with
0122   //! parameters to the moment
0123   const TCollection_ExtendedString& Value() const;
0124 
0125   //! Tells if Value differs from Original
0126   bool IsEdited() const;
0127 
0128   //! Return the resulting message string with all parameters
0129   //! filled. If some parameters were not yet filled by calls
0130   //! to methods Arg (or <<), these parameters are filled by
0131   //! the word UNKNOWN
0132   Standard_EXPORT const TCollection_ExtendedString& Get();
0133 
0134   operator const TCollection_ExtendedString&() { return Get(); }
0135 
0136 private:
0137   Standard_EXPORT int getFormat(const int theType, TCollection_AsciiString& theFormat);
0138 
0139   Standard_EXPORT void replaceText(const int                         theFirst,
0140                                    const int                         theNb,
0141                                    const TCollection_ExtendedString& theStr);
0142 
0143   TCollection_ExtendedString myOriginal;
0144   TCollection_ExtendedString myMessageBody;
0145   NCollection_Sequence<int>  mySeqOfFormats;
0146 };
0147 
0148 #include <Message_Msg.lxx>
0149 
0150 #endif // _Message_Msg_HeaderFile