Warnings on vc14 were eliminated
[occt.git] / src / Standard / Standard_Transient.hxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15#ifndef _Standard_Transient_HeaderFile
16#define _Standard_Transient_HeaderFile
17
e7195ab4 18#include <Standard.hxx>
19#include <Standard_DefineAlloc.hxx>
7fd59977 20#include <Standard_PrimitiveTypes.hxx>
e7195ab4 21
22class Standard_Type;
23
24namespace opencascade {
25 template <class T> class handle;
26}
27
28//! Abstract class which forms the root of the entire
29//! Transient class hierarchy.
30
31class Standard_Transient
32{
33public:
34 // Standard OCCT memory allocation stuff
35 DEFINE_STANDARD_ALLOC
36
37public:
38
39 //! Empty constructor
40 Standard_Transient() : count(0) {}
41
42 //! Copy constructor -- does nothing
43 Standard_Transient (const Standard_Transient&) : count(0) {}
44
45 //! Assignment operator, needed to avoid copying reference counter
46 Standard_Transient& operator= (const Standard_Transient&) { return *this; }
47
48 //! Destructor must be virtual
49 virtual ~Standard_Transient() {}
50
51 //! Memory deallocator for transient classes
52 Standard_EXPORT virtual void Delete() const;
53
54public:
55 //!@name Support of run-time type information (RTTI)
56
57 typedef void base_type;
58
59 static const char* get_type_name () { return "Standard_Transient"; }
60
f5f4ebd0 61 //! Returns type descriptor of Standard_Transient class
62 Standard_EXPORT static const opencascade::handle<Standard_Type>& get_type_descriptor ();
63
64 //! Returns a type descriptor about this object.
e7195ab4 65 Standard_EXPORT virtual const opencascade::handle<Standard_Type>& DynamicType() const;
66
67 //! Returns a true value if this is an instance of Type.
68 Standard_EXPORT Standard_Boolean IsInstance(const opencascade::handle<Standard_Type>& theType) const;
69
70 //! Returns a true value if this is an instance of TypeName.
71 Standard_EXPORT Standard_Boolean IsInstance(const Standard_CString theTypeName) const;
72
73 //! Returns true if this is an instance of Type or an
74 //! instance of any class that inherits from Type.
75 //! Note that multiple inheritance is not supported by OCCT RTTI mechanism.
76 Standard_EXPORT Standard_Boolean IsKind(const opencascade::handle<Standard_Type>& theType) const;
77
78 //! Returns true if this is an instance of TypeName or an
79 //! instance of any class that inherits from TypeName.
80 //! Note that multiple inheritance is not supported by OCCT RTTI mechanism.
81 Standard_EXPORT Standard_Boolean IsKind(const Standard_CString theTypeName) const;
82
83 //! Returns non-const pointer to this object (like const_cast).
84 //! For protection against creating handle to objects allocated in stack
85 //! or call from constructor, it will raise exception Standard_ProgramError
86 //! if reference counter is zero.
87 Standard_EXPORT Standard_Transient* This() const;
88
89public:
90 //!@name Reference counting, for use by handle<>
91
92 //! Get the reference counter of this object
be5c3602 93 Standard_Integer GetRefCount() const { return count; }
e7195ab4 94
95 //! Increments the reference counter of this object
96 Standard_EXPORT void IncrementRefCounter() const;
97
98 //! Decrements the reference counter of this object;
99 //! returns the decremented value
100 Standard_EXPORT Standard_Integer DecrementRefCounter() const;
101
102private:
103
104 //! Reference counter
105 mutable volatile Standard_Integer count;
106};
107
108//! Global method HashCode(), for use in hash maps
109inline Standard_Integer HashCode (const Standard_Transient* theObject, const Standard_Integer theUpper)
110{
111 return ::HashCode ((Standard_Address*)theObject, theUpper);
112}
113
114//! Definition of Handle_Standard_Transient as typedef for compatibility
115typedef opencascade::handle<Standard_Transient> Handle_Standard_Transient;
7fd59977 116
117#endif