0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / Standard / Standard_Transient.hxx
1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _Standard_Transient_HeaderFile
16 #define _Standard_Transient_HeaderFile
17
18 #include <Standard.hxx>
19 #include <Standard_DefineAlloc.hxx>
20 #include <Standard_PrimitiveTypes.hxx>
21
22 class Standard_Type;
23
24 namespace opencascade {
25   template <class T> class handle;
26 }
27
28 //! Abstract class which forms the root of the entire 
29 //! Transient class hierarchy.
30
31 class Standard_Transient
32 {
33 public:
34   // Standard OCCT memory allocation stuff
35   DEFINE_STANDARD_ALLOC
36
37 public:
38
39   //! Empty constructor
40   Standard_Transient() : myRefCount_(0) {}
41
42   //! Copy constructor -- does nothing
43   Standard_Transient (const Standard_Transient&) : myRefCount_(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
54 public: 
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
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.
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
89 public:
90   //!@name Reference counting, for use by handle<>
91
92   //! Get the reference counter of this object
93   Standard_Integer GetRefCount() const { return myRefCount_; }
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
102 private:
103
104   //! Reference counter.
105   //! Note use of underscore, aimed to reduce probability 
106   //! of conflict with names of members of derived classes.
107   mutable volatile Standard_Integer myRefCount_;
108 };
109
110
111 //! Computes a hash code for the given transient object, in the range [1, theUpperBound]
112 //! @param theTransientObject the transient object which hash code is to be computed
113 //! @param theUpperBound the upper bound of the range a computing hash code must be within
114 //! @return a computed hash code, in the range [1, theUpperBound]
115 inline Standard_Integer HashCode (const Standard_Transient* const theTransientObject,
116                                   const Standard_Integer          theUpperBound)
117 {
118   return ::HashCode (static_cast<const void*> (theTransientObject), theUpperBound);
119 }
120
121 //! Definition of Handle_Standard_Transient as typedef for compatibility
122 typedef opencascade::handle<Standard_Transient> Handle_Standard_Transient;
123
124 #endif