1 // Created on: 2016-01-06
2 // Created by: Andrey Betenev
3 // Copyright (c) 2016 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Standard_OutOfMemory.hxx>
21 IMPLEMENT_STANDARD_RTTIEXT(Standard_OutOfMemory,Standard_ProgramError)
23 //=======================================================================
24 //function : Standard_OutOfMemory
26 //=======================================================================
28 Standard_OutOfMemory::Standard_OutOfMemory(const Standard_CString theMessage)
30 // call explicitly own method (non-virtual call)
31 Standard_OutOfMemory::SetMessageString (theMessage);
34 //=======================================================================
35 //function : GetMessageString
37 //=======================================================================
39 Standard_CString Standard_OutOfMemory::GetMessageString() const
44 //=======================================================================
45 //function : SetMessageString
47 //=======================================================================
49 void Standard_OutOfMemory::SetMessageString (const Standard_CString theMessage)
51 // restrict length of the message by buffer size
52 size_t n = (theMessage ? std::min (strlen (theMessage), sizeof(myBuffer) - 1) : 0);
54 // first set line end symbol to be safe in case of concurrent call
57 memcpy (myBuffer, theMessage, n);
60 //=======================================================================
63 //=======================================================================
65 void Standard_OutOfMemory::Raise(const Standard_CString theMessage)
67 NewInstance(theMessage)->Reraise();
70 //=======================================================================
73 //=======================================================================
75 void Standard_OutOfMemory::Raise(Standard_SStream& theMessage)
77 NewInstance(theMessage.str().c_str())->Reraise();
80 //=======================================================================
81 //function : NewInstance
83 //=======================================================================
85 // global instance must be allocated at load-time
86 static Handle(Standard_OutOfMemory) anOutOfMemInstance = new Standard_OutOfMemory;
88 Handle(Standard_OutOfMemory) Standard_OutOfMemory::NewInstance(const Standard_CString theMessage)
90 anOutOfMemInstance->SetMessageString (theMessage);
91 return anOutOfMemInstance;
94 //=======================================================================
97 //=======================================================================
99 void Standard_OutOfMemory::Throw () const