Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-02 09:13:08

0001 // Created on: 1999-07-29
0002 // Created by: Roman LYGIN
0003 // Copyright (c) 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 _Message_HeaderFile
0018 #define _Message_HeaderFile
0019 
0020 #include <Message_Messenger.hxx>
0021 #include <Message_Gravity.hxx>
0022 #include <Message_MetricType.hxx>
0023 #include <NCollection_DynamicArray.hxx>
0024 #include <OSD_MemInfo.hxx>
0025 
0026 #include <TCollection_AsciiString.hxx>
0027 
0028 class Message_Report;
0029 
0030 //! Defines
0031 //! - tools to work with messages
0032 //! - basic tools intended for progress indication
0033 class Message
0034 {
0035 public:
0036   DEFINE_STANDARD_ALLOC
0037 
0038   //! Defines default messenger for OCCT applications.
0039   //! This is global static instance of the messenger.
0040   //! By default, it contains single printer directed to std::cout.
0041   //! It can be customized according to the application needs.
0042   //!
0043   //! The following syntax can be used to print messages:
0044   //! @code
0045   //!   Message::DefaultMessenger()->Send ("My Warning", Message_Warning);
0046   //!   Message::SendWarning ("My Warning"); // short-cut for Message_Warning
0047   //!   Message::SendWarning() << "My Warning with " << theCounter << " arguments";
0048   //!   Message::SendFail ("My Failure"); // short-cut for Message_Fail
0049   //! @endcode
0050   Standard_EXPORT static const occ::handle<Message_Messenger>& DefaultMessenger();
0051 
0052 public:
0053   //!@name Short-cuts to DefaultMessenger
0054 
0055   static Message_Messenger::StreamBuffer Send(Message_Gravity theGravity)
0056   {
0057     return DefaultMessenger()->Send(theGravity);
0058   }
0059 
0060   static void Send(const TCollection_AsciiString& theMessage, Message_Gravity theGravity)
0061   {
0062     DefaultMessenger()->Send(theMessage, theGravity);
0063   }
0064 
0065   static Message_Messenger::StreamBuffer SendFail() { return DefaultMessenger()->SendFail(); }
0066 
0067   static Message_Messenger::StreamBuffer SendAlarm() { return DefaultMessenger()->SendAlarm(); }
0068 
0069   static Message_Messenger::StreamBuffer SendWarning() { return DefaultMessenger()->SendWarning(); }
0070 
0071   static Message_Messenger::StreamBuffer SendInfo() { return DefaultMessenger()->SendInfo(); }
0072 
0073   static Message_Messenger::StreamBuffer SendTrace() { return DefaultMessenger()->SendTrace(); }
0074 
0075   static void SendFail(const TCollection_AsciiString& theMessage)
0076   {
0077     return DefaultMessenger()->SendFail(theMessage);
0078   }
0079 
0080   static void SendAlarm(const TCollection_AsciiString& theMessage)
0081   {
0082     return DefaultMessenger()->SendAlarm(theMessage);
0083   }
0084 
0085   static void SendWarning(const TCollection_AsciiString& theMessage)
0086   {
0087     return DefaultMessenger()->SendWarning(theMessage);
0088   }
0089 
0090   static void SendInfo(const TCollection_AsciiString& theMessage)
0091   {
0092     return DefaultMessenger()->SendInfo(theMessage);
0093   }
0094 
0095   static void SendTrace(const TCollection_AsciiString& theMessage)
0096   {
0097     return DefaultMessenger()->SendTrace(theMessage);
0098   }
0099 
0100 public:
0101   //! Returns the string filled with values of hours, minutes and seconds.
0102   //! Example:
0103   //! 1. (5, 12, 26.3345) returns "05h:12m:26.33s",
0104   //! 2. (0,  6, 34.496 ) returns "06m:34.50s",
0105   //! 3. (0,  0,  4.5   ) returns "4.50s"
0106   Standard_EXPORT static TCollection_AsciiString FillTime(const int    Hour,
0107                                                           const int    Minute,
0108                                                           const double Second);
0109 
0110 public:
0111   //! returns the only one instance of Report
0112   //! When theToCreate is true - automatically creates message report when not exist.
0113   Standard_EXPORT static const occ::handle<Message_Report>& DefaultReport(
0114     const bool theToCreate = false);
0115 
0116   //! Determines the metric from the given string identifier.
0117   //! @param theString string identifier
0118   //! @param theType detected type of metric
0119   //! @return TRUE if string identifier is known
0120   Standard_EXPORT static bool MetricFromString(const char* const   theString,
0121                                                Message_MetricType& theType);
0122 
0123   //! Returns the string name for a given metric type.
0124   //! @param theType metric type
0125   //! @return string identifier from the list of Message_MetricType
0126   Standard_EXPORT static const char* MetricToString(const Message_MetricType theType);
0127 
0128   //! Returns the metric type from the given string identifier.
0129   //! @param theString string identifier
0130   //! @return metric type or Message_MetricType_None if string identifier is invalid
0131   static Message_MetricType MetricFromString(const char* const theString)
0132   {
0133     Message_MetricType aMetric = Message_MetricType_None;
0134     MetricFromString(theString, aMetric);
0135     return aMetric;
0136   }
0137 
0138   //! Converts message metric to OSD memory info type.
0139   //! @param[in] theMetric  message metric
0140   //! @param[out] theMemInfo  filled memory info type
0141   //! @return true if converted
0142   static Standard_EXPORT bool ToOSDMetric(const Message_MetricType theMetric,
0143                                           OSD_MemInfo::Counter&    theMemInfo);
0144 
0145   //! Converts OSD memory info type to message metric.
0146   //! @param theMemInfo [int] memory info type
0147   //! @param[out] theMetric  filled message metric
0148   //! @return true if converted
0149   static Standard_EXPORT bool ToMessageMetric(const OSD_MemInfo::Counter theMemInfo,
0150                                               Message_MetricType&        theMetric);
0151 };
0152 
0153 #endif // _Message_HeaderFile