FRX SDK Documentation 2025 SP0
Loading...
Searching...
No Matches
dbobjptr.h
Go to the documentation of this file.
1#pragma once
2
3//
4// (C) Copyright 2005-2024 by Graebert GmbH.
5//
6// Permission to use, copy, modify, and distribute this software in
7// object code form for any purpose and without fee is hereby granted,
8// provided that the above copyright notice appears in all copies and
9// that both that copyright notice and the limited warranty and
10// restricted rights notice below appear in all supporting
11// documentation.
12//
13// GRAEBERT PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
14// GRAEBERT SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
15// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. GRAEBERT GMBH
16// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
17// UNINTERRUPTED OR ERROR FREE.
18
20template <class T>
22{
23
24public:
25 AcDbObjectPointerBase( ):m_ptr(0),m_status( Acad::eNullObjectPointer)
26 {
27 }
29 {
30
31 }
32
33 const T* object( ) const
34 {
35 return m_ptr;
36 }
38 {
39 return m_ptr;
40 }
41 const T * operator->( ) const
42 {
43 return m_ptr;
44 }
46 {
47 return m_ptr;
48 }
49 operator const T*( ) const
50 {
51 return m_ptr;
52 }
53 operator T*( )
54 {
55 return m_ptr;
56 }
57
58 Acad::ErrorStatus openStatus( ) const
59 {
60 return m_status;
61 }
62
63 Acad::ErrorStatus open( AcDbObjectId objId ,
65 bool openErased = false )
66 {
68 return m_status;
69 }
70
71 Acad::ErrorStatus acquire( T*& pObj )
72 {
73 if ( pObj == 0 )
74 return Acad::eNullObjectPointer;
75 if ( m_ptr != NULL )
76 {
77 Acad::ErrorStatus status = closeIt( );
78 if ( status != Acad::eOk )
79 return status;
80 }
81 m_ptr = pObj;
82 m_status = Acad::eOk;
83 pObj = 0;
84 return Acad::eOk;
85 }
86 Acad::ErrorStatus release( T*& pObj )
87 {
88 if ( m_ptr == 0 )
89 return Acad::eNullObjectPointer;
90 m_status = Acad::eNullObjectPointer;
91 pObj = m_ptr;
92 m_ptr = 0;
93 return Acad::eOk;
94 }
95
96 Acad::ErrorStatus close( )
97 {
98 return closeIt( );
99 }
100
101 Acad::ErrorStatus create( )
102 {
103 T* pObj = new T();
104
105 if ( m_ptr != 0 )
106 {
107 Acad::ErrorStatus status = closeIt( );
108 if ( status != Acad::eOk )
109 {
110 delete pObj;
111 return status;
112 }
113 }
114 m_ptr = pObj;
115 m_status = Acad::eOk;
116 return m_status;
117 }
118
119protected:
126
128 Acad::ErrorStatus m_status;
129
130
131private:
133 AcDbObjectPointerBase& operator=( const AcDbObjectPointerBase & ) = delete;
134
135 Acad::ErrorStatus closeIt( )
136 {
137 if ( m_ptr == 0 )
138 return Acad::eOk;
139 Acad::ErrorStatus status = Acad::eOk;
140 if ( m_ptr->objectId( ).isNull( ) )
141 {
142 delete m_ptr;
143 status = Acad::eOk;
144 }
145 else
146 {
147 status = m_ptr->close( );
148 }
149 m_ptr = 0;
150 m_status = Acad::eNullObjectPointer;
151 return this->es;
152 }
153
154};
Acad::ErrorStatus acdbOpenObject(T *&pObj, AcDbObjectId id, AcDb::OpenMode mode, bool openErased=false)
Definition AddGlobals.h:36
Acad::ErrorStatus acquire(T *&pObj)
Definition dbobjptr.h:71
Acad::ErrorStatus release(T *&pObj)
Definition dbobjptr.h:86
const T * object() const
Definition dbobjptr.h:33
Acad::ErrorStatus open(AcDbObjectId objId, AcDb::OpenMode mode=AcDb::kForRead, bool openErased=false)
Definition dbobjptr.h:63
Acad::ErrorStatus create()
Definition dbobjptr.h:101
const T * operator->() const
Definition dbobjptr.h:41
AcDbObjectPointerBase(AcDbObjectId objId, AcDb::OpenMode mode, bool openErased)
Definition dbobjptr.h:120
Acad::ErrorStatus m_status
Definition dbobjptr.h:128
Acad::ErrorStatus openStatus() const
Definition dbobjptr.h:58
Acad::ErrorStatus close()
Definition dbobjptr.h:96