Use (Message_SequenceOfPrinters::Iterator instead of accessing sequence elements by index.
Message_ListOfMsg.hxx
Message_Messenger.cxx
Message_Messenger.hxx
-Message_Messenger.lxx
Message_Msg.cxx
Message_Msg.hxx
Message_Msg.lxx
Message_MsgFile.hxx
Message_Printer.cxx
Message_Printer.hxx
-Message_Printer.lxx
Message_PrinterOStream.cxx
Message_PrinterOStream.hxx
-Message_PrinterOStream.lxx
Message_ProgressIndicator.cxx
Message_ProgressIndicator.hxx
Message_ProgressIndicator.lxx
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
-
#include <Message_Messenger.hxx>
+
#include <Message_Printer.hxx>
#include <Message_PrinterOStream.hxx>
-#include <Standard_Type.hxx>
-#include <TCollection_AsciiString.hxx>
-#include <TCollection_ExtendedString.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Message_Messenger,Standard_Transient)
Standard_Boolean Message_Messenger::AddPrinter (const Handle(Message_Printer)& thePrinter)
{
// check whether printer is already in the list
- for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
- if ( myPrinters(i) == thePrinter )
+ for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
+ {
+ const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
+ if (aPrinter == thePrinter)
+ {
return Standard_False;
- // add to the list
+ }
+ }
+
myPrinters.Append (thePrinter);
return Standard_True;
}
Standard_Boolean Message_Messenger::RemovePrinter (const Handle(Message_Printer)& thePrinter)
{
// find printer in the list
- for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
- if ( myPrinters(i) == thePrinter )
+ for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
+ {
+ const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
+ if (aPrinter == thePrinter)
{
- myPrinters.Remove (i);
+ myPrinters.Remove (aPrinterIter);
return Standard_True;
}
+ }
return Standard_False;
}
{
// remove printers from the list
Standard_Integer nb = 0;
- for (Standard_Integer i=1; i <= myPrinters.Length(); i++)
- if ( myPrinters(i)->IsKind(theType) )
+ for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More();)
+ {
+ const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
+ if (!aPrinter.IsNull() && aPrinter->IsKind (theType))
{
- myPrinters.Remove (i--);
+ myPrinters.Remove (aPrinterIter);
nb++;
}
+ else
+ {
+ aPrinterIter.Next();
+ }
+ }
return nb;
}
const Message_Gravity theGravity,
const Standard_Boolean putEndl) const
{
- Standard_Integer nb = myPrinters.Length();
- for (Standard_Integer i = 1; i <= nb; i++)
+ for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
{
- Handle(Message_Printer) aPrinter = myPrinters(i);
- if ( ! aPrinter.IsNull() )
- aPrinter->Send ( theString, theGravity, putEndl );
+ const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
+ if (!aPrinter.IsNull())
+ {
+ aPrinter->Send (theString, theGravity, putEndl);
+ }
}
}
const Message_Gravity theGravity,
const Standard_Boolean putEndl) const
{
- Standard_Integer nb = myPrinters.Length();
- for (Standard_Integer i = 1; i <= nb; i++)
+ for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
{
- Handle(Message_Printer) aPrinter = myPrinters(i);
- if ( ! aPrinter.IsNull() )
- aPrinter->Send ( theString, theGravity, putEndl );
+ const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
+ if (!aPrinter.IsNull())
+ {
+ aPrinter->Send (theString, theGravity, putEndl);
+ }
}
}
const Message_Gravity theGravity,
const Standard_Boolean putEndl) const
{
- Standard_Integer nb = myPrinters.Length();
- for (Standard_Integer i = 1; i <= nb; i++)
+ for (Message_SequenceOfPrinters::Iterator aPrinterIter (myPrinters); aPrinterIter.More(); aPrinterIter.Next())
{
- Handle(Message_Printer) aPrinter = myPrinters(i);
- if ( ! aPrinter.IsNull() )
- aPrinter->Send ( theString, theGravity, putEndl );
+ const Handle(Message_Printer)& aPrinter = aPrinterIter.Value();
+ if (!aPrinter.IsNull())
+ {
+ aPrinter->Send (theString, theGravity, putEndl);
+ }
}
}
#ifndef _Message_Messenger_HeaderFile
#define _Message_Messenger_HeaderFile
-#include <Standard.hxx>
-#include <Standard_Type.hxx>
-
+#include <Message_Gravity.hxx>
#include <Message_SequenceOfPrinters.hxx>
#include <Standard_Transient.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_Integer.hxx>
#include <Standard_Type.hxx>
#include <Standard_CString.hxx>
-#include <Message_Gravity.hxx>
+#include <TCollection_HAsciiString.hxx>
+#include <TCollection_HExtendedString.hxx>
+
class Message_Printer;
-class TCollection_AsciiString;
-class TCollection_ExtendedString;
// resolve name collisions with WinAPI headers
#ifdef AddPrinter
//! Note that all these operators use trace level Warning.
class Message_Messenger : public Standard_Transient
{
-
+ DEFINE_STANDARD_RTTIEXT(Message_Messenger, Standard_Transient)
public:
-
//! Empty constructor; initializes by single printer directed to cout.
//! Note: the default messenger is not empty but directed to cout
//! in order to protect against possibility to forget defining printers.
Standard_EXPORT Standard_Integer RemovePrinters (const Handle(Standard_Type)& theType);
//! Returns current sequence of printers
- const Message_SequenceOfPrinters& Printers() const;
-
+ const Message_SequenceOfPrinters& Printers() const { return myPrinters; }
+
//! Returns sequence of printers
//! The sequence can be modified.
- Message_SequenceOfPrinters& ChangePrinters();
-
+ Message_SequenceOfPrinters& ChangePrinters() { return myPrinters; }
+
//! Dispatch a message to all the printers in the list.
//! Three versions of string representations are accepted for
//! convenience, by default all are converted to ExtendedString.
//! See above
Standard_EXPORT void Send (const TCollection_ExtendedString& theString, const Message_Gravity theGravity = Message_Warning, const Standard_Boolean putEndl = Standard_True) const;
-
-
-
- DEFINE_STANDARD_RTTIEXT(Message_Messenger,Standard_Transient)
-
-protected:
-
-
-
-
private:
-
Message_SequenceOfPrinters myPrinters;
-
};
+// CString
+inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger,
+ const Standard_CString theStr)
+{
+ theMessenger->Send (theStr, Message_Info, Standard_False);
+ return theMessenger;
+}
+
+// AsciiString
+inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger,
+ const TCollection_AsciiString& theStr)
+{
+ theMessenger->Send (theStr, Message_Info, Standard_False);
+ return theMessenger;
+}
-#include <Message_Messenger.lxx>
+// HAsciiString
+inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger,
+ const Handle(TCollection_HAsciiString)& theStr)
+{
+ theMessenger->Send (theStr->String(), Message_Info, Standard_False);
+ return theMessenger;
+}
+// ExtendedString
+inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger,
+ const TCollection_ExtendedString& theStr)
+{
+ theMessenger->Send (theStr, Message_Info, Standard_False);
+ return theMessenger;
+}
+// HExtendedString
+inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger,
+ const Handle(TCollection_HExtendedString)& theStr)
+{
+ theMessenger->Send (theStr->String(), Message_Info, Standard_False);
+ return theMessenger;
+}
+// Integer
+inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger,
+ const Standard_Integer theVal)
+{
+ TCollection_AsciiString aStr (theVal);
+ theMessenger->Send (aStr, Message_Info, Standard_False);
+ return theMessenger;
+}
+
+// Real
+inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger,
+ const Standard_Real theVal)
+{
+ TCollection_AsciiString aStr (theVal);
+ theMessenger->Send (aStr, Message_Info, Standard_False);
+ return theMessenger;
+}
+
+// Stream
+inline const Handle(Message_Messenger)& operator<< (const Handle(Message_Messenger)& theMessenger,
+ const Standard_SStream& theStream)
+{
+ theMessenger->Send (theStream.str().c_str(), Message_Info, Standard_False);
+ return theMessenger;
+}
+
+// manipulators
+inline const Handle(Message_Messenger)&
+ operator << (const Handle(Message_Messenger)& theMessenger,
+ const Handle(Message_Messenger)& (*pman) (const Handle(Message_Messenger)&))
+{
+ return pman (theMessenger);
+}
+// endl
+inline const Handle(Message_Messenger)& endl (const Handle(Message_Messenger)& theMessenger)
+{
+ theMessenger->Send ("", Message_Info, Standard_True);
+ return theMessenger;
+}
#endif // _Message_Messenger_HeaderFile
+++ /dev/null
-// Created on: 2007-06-29
-// Created by: OCC Team
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <Message_Messenger.hxx>
-
-//=======================================================================
-//function : GetPrinters
-//purpose :
-//=======================================================================
-
-inline const Message_SequenceOfPrinters& Message_Messenger::Printers() const
-{
- return myPrinters;
-}
-
-//=======================================================================
-//function : GetPrinters
-//purpose :
-//=======================================================================
-
-inline Message_SequenceOfPrinters& Message_Messenger::ChangePrinters()
-{
- return myPrinters;
-}
-
-//=======================================================================
-//function : operator <<
-//purpose :
-//=======================================================================
-
-#include <TCollection_HAsciiString.hxx>
-#include <TCollection_HExtendedString.hxx>
-
-// CString
-inline const Handle(Message_Messenger)&
- operator << (const Handle(Message_Messenger)& theMessenger,
- const Standard_CString theStr)
-{
- theMessenger->Send (theStr, Message_Info, Standard_False);
- return theMessenger;
-}
-
-// const char* (not the same as const CString which is char const*)
-/*
-inline const Handle(Message_Messenger)&
- operator << (const Handle(Message_Messenger)& theMessenger,
- const char* theStr)
-{
- theMessenger->Send ((Standard_CString)theStr, Message_Info, Standard_False);
- return theMessenger;
-}
-*/
-// AsciiString
-inline const Handle(Message_Messenger)&
- operator << (const Handle(Message_Messenger)& theMessenger,
- const TCollection_AsciiString& theStr)
-{
- theMessenger->Send (theStr, Message_Info, Standard_False);
- return theMessenger;
-}
-
-// HAsciiString
-inline const Handle(Message_Messenger)&
- operator << (const Handle(Message_Messenger)& theMessenger,
- const Handle(TCollection_HAsciiString)& theStr)
-{
- theMessenger->Send (theStr->String(), Message_Info, Standard_False);
- return theMessenger;
-}
-
-// ExtendedString
-inline const Handle(Message_Messenger)&
- operator << (const Handle(Message_Messenger)& theMessenger,
- const TCollection_ExtendedString& theStr)
-{
- theMessenger->Send (theStr, Message_Info, Standard_False);
- return theMessenger;
-}
-
-// HExtendedString
-inline const Handle(Message_Messenger)&
- operator << (const Handle(Message_Messenger)& theMessenger,
- const Handle(TCollection_HExtendedString)& theStr)
-{
- theMessenger->Send (theStr->String(), Message_Info, Standard_False);
- return theMessenger;
-}
-
-// Integer
-inline const Handle(Message_Messenger)&
- operator << (const Handle(Message_Messenger)& theMessenger,
- const Standard_Integer theVal)
-{
- TCollection_AsciiString aStr (theVal);
- theMessenger->Send (aStr, Message_Info, Standard_False);
- return theMessenger;
-}
-
-// Real
-inline const Handle(Message_Messenger)&
- operator << (const Handle(Message_Messenger)& theMessenger,
- const Standard_Real theVal)
-{
- TCollection_AsciiString aStr (theVal);
- theMessenger->Send (aStr, Message_Info, Standard_False);
- return theMessenger;
-}
-
-// Stream
-inline const Handle(Message_Messenger)&
- operator << (const Handle(Message_Messenger)& theMessenger,
- const Standard_SStream& theStream)
-{
- theMessenger->Send (theStream.str().c_str(), Message_Info, Standard_False);
- return theMessenger;
-}
-
-// manipulators
-inline const Handle(Message_Messenger)&
- operator << (const Handle(Message_Messenger)& theMessenger,
- const Handle(Message_Messenger)& (*pman) (const Handle(Message_Messenger)&))
-{
- return pman (theMessenger);
-}
-
-// endl
-inline const Handle(Message_Messenger)& endl (const Handle(Message_Messenger)& theMessenger)
-{
- theMessenger->Send ("", Message_Info, Standard_True);
- return theMessenger;
-}
#include <Message_Printer.hxx>
-#include <Standard_Type.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
//! level, which can be used by printer to decide either to process a message or ignore it.
class Message_Printer : public Standard_Transient
{
-
+ DEFINE_STANDARD_RTTIEXT(Message_Printer, Standard_Transient)
public:
-
//! Return trace level used for filtering messages;
//! messages with lover gravity will be ignored.
- Message_Gravity GetTraceLevel() const;
-
+ Message_Gravity GetTraceLevel() const { return myTraceLevel; }
+
//! Set trace level used for filtering messages.
//! By default, trace level is Message_Info, so that all messages are output
- void SetTraceLevel (const Message_Gravity theTraceLevel);
-
+ void SetTraceLevel (const Message_Gravity theTraceLevel) { myTraceLevel = theTraceLevel; }
+
//! Send a string message with specified trace level.
//! The parameter theToPutEol specified whether end-of-line should be added to the end of the message.
//! This method must be redefined in descentant.
//! Default implementation calls first method Send().
Standard_EXPORT virtual void Send (const TCollection_AsciiString& theString, const Message_Gravity theGravity, const Standard_Boolean theToPutEol) const;
-
-
-
- DEFINE_STANDARD_RTTIEXT(Message_Printer,Standard_Transient)
-
protected:
-
//! Empty constructor with Message_Info trace level
Standard_EXPORT Message_Printer();
- Message_Gravity myTraceLevel;
-
-
-private:
-
-
+protected:
+ Message_Gravity myTraceLevel;
};
-
-#include <Message_Printer.lxx>
-
-
-
-
-
#endif // _Message_Printer_HeaderFile
+++ /dev/null
-// Created on: 2007-06-28
-// Created by: Pavel TELKOV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <Message_Printer.hxx>
-
-//=======================================================================
-//function : GetTraceLevel
-//purpose :
-//=======================================================================
-
-inline Message_Gravity Message_Printer::GetTraceLevel() const
-{
- return myTraceLevel;
-}
-
-//=======================================================================
-//function : SetTraceLevel
-//purpose :
-//=======================================================================
-
-inline void Message_Printer::SetTraceLevel (const Message_Gravity theTraceLevel)
-{
- myTraceLevel = theTraceLevel;
-}
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
-
-#include <Message_Gravity.hxx>
#include <Message_PrinterOStream.hxx>
-#include <Standard_Mutex.hxx>
-#include <Standard_Stream.hxx>
-#include <Standard_Type.hxx>
+
+#include <OSD_OpenFile.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
aFileName.ChangeAll ('/', '\\');
#endif
- std::ofstream* aFile = new std::ofstream (aFileName.ToCString(),
- (theToAppend ? (std::ios_base::app | std::ios_base::out) : std::ios_base::out));
+ std::ofstream* aFile = new std::ofstream();
+ OSD_OpenStream (*aFile, aFileName.ToCString(), (theToAppend ? (std::ios_base::app | std::ios_base::out) : std::ios_base::out));
if (aFile->is_open())
{
myStream = (Standard_OStream* )aFile;
const Message_Gravity theGravity,
const Standard_Boolean putEndl) const
{
- // Note: the string might need to be converted to Ascii
- if ( myUseUtf8 ) {
- char* astr = new char[theString.LengthOfCString()+1];
- theString.ToUTF8CString (astr);
- Send ( astr, theGravity, putEndl );
- delete [] astr;
- astr = 0;
- }
- else {
- TCollection_AsciiString aStr ( theString, '?' );
- Send ( aStr.ToCString(), theGravity, putEndl );
- }
+ TCollection_AsciiString aStr (theString, myUseUtf8 ? Standard_Character(0) : '?');
+ Send (aStr.ToCString(), theGravity, putEndl);
}
#ifndef _Message_PrinterOStream_HeaderFile
#define _Message_PrinterOStream_HeaderFile
-#include <Standard.hxx>
-#include <Standard_Type.hxx>
-
-#include <Standard_Address.hxx>
-#include <Standard_Boolean.hxx>
#include <Message_Printer.hxx>
-#include <Message_Gravity.hxx>
-#include <Standard_CString.hxx>
+#include <Standard_Address.hxx>
#include <Standard_OStream.hxx>
-class TCollection_AsciiString;
-class TCollection_ExtendedString;
-
class Message_PrinterOStream;
DEFINE_STANDARD_HANDLE(Message_PrinterOStream, Message_Printer)
//! or file stream maintained internally (depending on constructor).
class Message_PrinterOStream : public Message_Printer
{
-
+ DEFINE_STANDARD_RTTIEXT(Message_PrinterOStream, Message_Printer)
public:
-
//! Empty constructor, defaulting to cout
Standard_EXPORT Message_PrinterOStream(const Message_Gravity theTraceLevel = Message_Info);
{
Close();
}
-
+
//! Returns option to convert non-Ascii symbols to UTF8 encoding
- Standard_Boolean GetUseUtf8() const;
+ Standard_Boolean GetUseUtf8() const { return myUseUtf8; }
//! Sets option to convert non-Ascii symbols to UTF8 encoding
- void SetUseUtf8 (const Standard_Boolean useUtf8);
-
+ void SetUseUtf8 (const Standard_Boolean useUtf8) { myUseUtf8 = useUtf8; }
+
//! Returns reference to the output stream
- Standard_OStream& GetStream() const;
+ Standard_OStream& GetStream() const { return *(Standard_OStream*)myStream; }
//! Puts a message to the current stream
//! if its gravity is equal or greater
//! option is set, else replaced by symbols '?'
Standard_EXPORT virtual void Send (const TCollection_ExtendedString& theString, const Message_Gravity theGravity, const Standard_Boolean putEndl = Standard_True) const Standard_OVERRIDE;
-
-
- DEFINE_STANDARD_RTTIEXT(Message_PrinterOStream,Message_Printer)
-
-protected:
-
-
-
-
private:
-
Standard_Address myStream;
Standard_Boolean myIsFile;
Standard_Boolean myUseUtf8;
-
};
-
-#include <Message_PrinterOStream.lxx>
-
-
-
-
-
#endif // _Message_PrinterOStream_HeaderFile
+++ /dev/null
-// Created on: 2007-06-28
-// Created by: Pavel TELKOV
-// Copyright (c) 2007-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <Message_PrinterOStream.hxx>
-
-//=======================================================================
-//function : GetUseUtf8
-//purpose :
-//=======================================================================
-
-inline Standard_Boolean Message_PrinterOStream::GetUseUtf8() const
-{
- return myUseUtf8;
-}
-
-//=======================================================================
-//function : SetUseUtf8
-//purpose :
-//=======================================================================
-
-inline void Message_PrinterOStream::SetUseUtf8 (const Standard_Boolean useUtf8)
-{
- myUseUtf8 = useUtf8;
-}
-
-//=======================================================================
-//function : GetStream
-//purpose :
-//=======================================================================
-
-inline Standard_OStream& Message_PrinterOStream::GetStream () const
-{
- return *(Standard_OStream*)myStream;
-}