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>
25 IMPLEMENT_STANDARD_RTTIEXT(Standard_OutOfMemory,Standard_ProgramError)
27 //=======================================================================
28 //function : Standard_OutOfMemory
30 //=======================================================================
32 Standard_OutOfMemory::Standard_OutOfMemory(const Standard_CString theMessage)
34 // call explicitly own method (non-virtual call)
35 Standard_OutOfMemory::SetMessageString (theMessage);
38 //=======================================================================
39 //function : GetMessageString
41 //=======================================================================
43 Standard_CString Standard_OutOfMemory::GetMessageString() const
48 //=======================================================================
49 //function : SetMessageString
51 //=======================================================================
53 void Standard_OutOfMemory::SetMessageString (const Standard_CString theMessage)
55 // restrict length of the message by buffer size
56 size_t n = (theMessage ? std::min (strlen (theMessage), sizeof(myBuffer) - 1) : 0);
58 // first set line end symbol to be safe in case of concurrent call
61 memcpy (myBuffer, theMessage, n);
64 //=======================================================================
67 //=======================================================================
69 void Standard_OutOfMemory::Raise(const Standard_CString theMessage)
71 NewInstance(theMessage)->Reraise();
74 //=======================================================================
77 //=======================================================================
79 void Standard_OutOfMemory::Raise(Standard_SStream& theMessage)
81 NewInstance(theMessage.str().c_str())->Reraise();
84 //=======================================================================
85 //function : NewInstance
87 //=======================================================================
89 // global instance must be allocated at load-time
90 static Handle(Standard_OutOfMemory) anOutOfMemInstance = new Standard_OutOfMemory;
92 Handle(Standard_OutOfMemory) Standard_OutOfMemory::NewInstance(const Standard_CString theMessage)
94 anOutOfMemInstance->SetMessageString (theMessage);
95 return anOutOfMemInstance;
98 //=======================================================================
101 //=======================================================================
103 void Standard_OutOfMemory::Throw () const