dbobjptr.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. //
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright 2015 Autodesk, Inc. All rights reserved.
  5. //
  6. // Use of this software is subject to the terms of the Autodesk license
  7. // agreement provided at the time of installation or download, or which
  8. // otherwise accompanies this software in either electronic or hard copy form.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //
  12. //
  13. // DESCRIPTION
  14. //
  15. // The template classes defined in this header file provide
  16. // simplified "management" (i.e., opening, closing, creating,
  17. // deleting) of AcDbObject's upon construction and destruction.
  18. // The constructor provides the necessary arguments to open the
  19. // object and the destructor closes the object. During the
  20. // lifetime of the object, clients use operator->() to
  21. // manipulate the opened object. These classes also simplify
  22. // creating and deletion of objects.
  23. //
  24. // One base class, AcDbObjectPointerBase provides the basic
  25. // services of opening and closing objects. Derived classes
  26. // provide the real interface to open objects of various types
  27. // derived from AcDbObject. They usually provide additional
  28. // constructors that know about the particular ways of opening
  29. // an object. The following template classes are defined in
  30. // this header file.
  31. //
  32. // AcDbObjectPointerBase<T_OBJECT>
  33. //
  34. // This class provides the basic services and defines the
  35. // basic contracts for using the smart pointers derived
  36. // from it. You normally don't use this class directly,
  37. // but may use it to define a derived class to add
  38. // constructors that know how to open an object derived
  39. // from AcDbObject in alternate forms.
  40. //
  41. // AcDbObjectPointer<T_OBJECT>
  42. //
  43. // This class allows you to access any AcDbObject-based
  44. // object given its object ID. The following pre-defined
  45. // typedefs are available.
  46. //
  47. // AcDbDictionaryPointer
  48. // AcDbEntityPointer
  49. //
  50. // AcDbSymbolTablePointer<T_OBJECT>
  51. //
  52. // This class allows you to access the symbol tables
  53. // associated with every AcDbDatabase. You can specify
  54. // an object ID or a particular database. The following
  55. // pre-defined typedefs are available for individual
  56. // symbol-table types.
  57. //
  58. // AcDbBlockTablePointer
  59. // AcDbDimStyleTablePointer
  60. // AcDbLayerTablePointer
  61. // AcDbLinetypeTablePointer
  62. // AcDbRegAppTablePointer
  63. // AcDbTextStyleTablePointer
  64. // AcDbUCSTablePointer
  65. // AcDbViewTablePointer
  66. // AcDbViewportTablePointer
  67. //
  68. // Note that to open a "plain" symbol table, you may use
  69. // AcDbObjectPointer<AcDbSymbolTable>.
  70. //
  71. // AcDbSymbolTableRecordPointer<T_OBJECT>
  72. //
  73. // This class allow you to access symbol-table records by
  74. // object ID or by name. The following pre-defined
  75. // typedefs are available for individual symbol-table
  76. // record types.
  77. //
  78. // AcDbBlockTableRecordPointer
  79. // AcDbDimStyleTableRecordPointer
  80. // AcDbLayerTableRecordPointer
  81. // AcDbLinetypeTableRecordPointer
  82. // AcDbRegAppTableRecordPointer
  83. // AcDbTextStyleTableRecordPointer
  84. // AcDbUCSTableRecordPointer
  85. // AcDbViewTableRecordPointer
  86. // AcDbViewportTableRecordPointer
  87. //
  88. // Note that to open a "plain" symbol record, you may use
  89. // AcDbObjectPointer<AcDbSymbolTableRecord>.
  90. //
  91. // These classes are designed to be type-safe replacements for
  92. // explicitly using acdbOpenObject(), acdbOpenAcDbObject(), and
  93. // acdbOpenAcDbEntity(). Using these classes incur opening and
  94. // close objects, which, under certain circumstances, may be
  95. // better managed using transactions.
  96. #ifndef AD_DBOBJPTR_H
  97. #define AD_DBOBJPTR_H
  98. #include <assert.h>
  99. #include "dbsymtb.h"
  100. #ifdef ASSERT
  101. #define DbObjPtr_Assert ASSERT
  102. #elif defined assert
  103. #define DbObjPtr_Assert assert
  104. #elif defined _ASSERTE
  105. #define DbObjPtr_Assert _ASSERTE
  106. #else
  107. #define DbObjPtr_Assert(T)
  108. #endif
  109. #pragma pack (push, 8)
  110. // --------- AcDbObjectPointerBase<T_OBJECT> ---------
  111. //
  112. // This class provides the basic services for opening and
  113. // closing objects given its object ID. It is meant to be a
  114. // base class from which derived classes may specialize on how
  115. // objects may be opened. Template argument T_OBJECT should
  116. // be AcDbObject or a class derived from AcDbObject that you
  117. // can open via acdbOpenObject().
  118. //
  119. // Contracts:
  120. //
  121. // All derived classes must abide by and enforce the following contracts.
  122. //
  123. // 1. Copying and assignment are prohibited. Derived classes
  124. // must also prohibit copying and assigment by declaring those
  125. // functions private. These classes contain a pointer to
  126. // the real object, so the default constructors provided by
  127. // the compiler must not be used. Copying and assigment do
  128. // not have obvious semantics of whether you own the object
  129. // or just the pointer. You can pass AcDbObjectId's and
  130. // use these classes to simplify opening the objects by
  131. // their ID.
  132. //
  133. // 2. Clients must not close the objects themselves by using
  134. // the close() member function. The destructor will close
  135. // the object. These pointer classes are meant to keep the
  136. // object open for the lifetime of the pointer object.
  137. // Note that an upgradeOpen() may fail, but is compatible
  138. // with the semantics of the pointer classes. A failure to
  139. // upgrade will leave the object opened in it's original
  140. // mode.
  141. //
  142. // A consequence of this contract means that passing the
  143. // pointers returned by operator->() or object() to other
  144. // functions may lead to unexpected problems if the other
  145. // functions close the object through the pointer.
  146. //
  147. // 3. Derived classes should provide the following constructors.
  148. //
  149. // A. A constructor that opens the object by its ID. This
  150. // consistency promotes the use of object IDs and
  151. // ensures the "basic" service of opening objects by ID
  152. // when using these object-pointer classes.
  153. //
  154. // B. A default constructor, which is mainly needed when
  155. // clients wish to use the acquire() member function.
  156. //
  157. // 4. All clients will call the openStatus() member function
  158. // to determine if the object was successfully opened before
  159. // using operator->().
  160. //
  161. // The default constructor provided by AcDbObjectPointerBase<T_OBJECT>
  162. // sets the open status to Acad::eNullObjectPointer.
  163. //
  164. // Enable DBOBJPTR_EXPOSE_PTR_REF in order to allow direct access to the
  165. // pointer member. This lets you pass the smart pointer to functions
  166. // like getAt(), deepClone() and acdbOpenAcDbObject(), which need a
  167. // reference to an AcDbObject pointer, so they can modify it.
  168. //
  169. // Note that this allows the pointer member to be updated externally, so
  170. // that previously open objects may be left open, creating a "leak".
  171. //
  172. // Also, the openStatus() method may not reflect the correct status
  173. // after an external operation modified the pointer member.
  174. //
  175. // This also enables constructors and assignment operators which allow
  176. // you to directly assign conventional pointers to the smart pointer.
  177. //
  178. // Use at your own risk!
  179. //
  180. // #define DBOBJPTR_EXPOSE_PTR_REF 1
  181. template<class T_OBJECT>
  182. class AcDbObjectPointerBase
  183. {
  184. public:
  185. AcDbObjectPointerBase();
  186. virtual ~AcDbObjectPointerBase();
  187. const T_OBJECT * object() const;
  188. T_OBJECT * object();
  189. const T_OBJECT * operator->() const;
  190. T_OBJECT * operator->();
  191. operator const T_OBJECT*() const;
  192. #if DBOBJPTR_EXPOSE_PTR_REF
  193. operator T_OBJECT* &();
  194. #else
  195. operator T_OBJECT*();
  196. #endif
  197. Acad::ErrorStatus openStatus() const;
  198. Acad::ErrorStatus open(AcDbObjectId objId,
  199. AcDb::OpenMode mode,
  200. bool openErased = false);
  201. Acad::ErrorStatus acquire(T_OBJECT *& pObjToAcquire);
  202. Acad::ErrorStatus release(T_OBJECT *& pReleasedObj);
  203. Acad::ErrorStatus close();
  204. Acad::ErrorStatus create();
  205. protected:
  206. AcDbObjectPointerBase(AcDbObjectId objId,
  207. AcDb::OpenMode mode,
  208. bool openErased);
  209. #if DBOBJPTR_EXPOSE_PTR_REF
  210. AcDbObjectPointerBase(T_OBJECT * pObject);
  211. void operator=(T_OBJECT *pObject);
  212. #endif
  213. T_OBJECT * m_ptr;
  214. Acad::ErrorStatus m_status;
  215. private:
  216. // Copy and assignment prohibited.
  217. AcDbObjectPointerBase(AcDbObjectPointerBase & pObject);
  218. AcDbObjectPointerBase& operator=(AcDbObjectPointerBase & pObject);
  219. Acad::ErrorStatus closeInternal();
  220. };
  221. // --------- AcDbObjectPointer<T_OBJECT> ---------
  222. // This class allows you to open any AcDbObject given its object ID.
  223. // The single form of construction is:
  224. //
  225. // (AcDbObjectId objId, AcDb::OpenMode mode, bool openErased)
  226. //
  227. // These arguments have the same meaning as acdbOpenObject().
  228. //
  229. template<class T_OBJECT>
  230. class AcDbObjectPointer : public AcDbObjectPointerBase<T_OBJECT>
  231. {
  232. public:
  233. AcDbObjectPointer();
  234. AcDbObjectPointer(AcDbObjectId objId,
  235. AcDb::OpenMode mode,
  236. bool openErased = false);
  237. #if DBOBJPTR_EXPOSE_PTR_REF
  238. AcDbObjectPointer(T_OBJECT * pObject);
  239. void operator=(T_OBJECT *pObject);
  240. #endif
  241. Acad::ErrorStatus open(AcDbObjectId objId,
  242. AcDb::OpenMode mode,
  243. bool openErased = false);
  244. private:
  245. // Copy and assignment prohibited.
  246. AcDbObjectPointer(AcDbObjectPointer & pObject);
  247. AcDbObjectPointer& operator=(AcDbObjectPointer & pObject);
  248. };
  249. typedef AcDbObjectPointer<AcDbDictionary> AcDbDictionaryPointer;
  250. typedef AcDbObjectPointer<AcDbEntity> AcDbEntityPointer;
  251. // --------- AcDbSymbolTablePointer<T_OBJECT> ---------
  252. // This class allows you to open any AcDbSymbolTable or
  253. // AcDbSymbolTable-derived object given its object ID or
  254. // a pointer to the database containing the symbol table.
  255. // The different forms of construction are:
  256. //
  257. // (AcDbObjectId objId, AcDb::OpenMode mode)
  258. // (AcDbDatabase * pDb, AcDb::OpenMode mode)
  259. //
  260. // The object ID and open modes have the same meaning as those of
  261. // AcDbObjectPointer<T_OBJECT>. If the database pointer is NULL, the
  262. // open status after construction is eNullObjectPointer.
  263. //
  264. template<class T_OBJECT>
  265. class AcDbSymbolTablePointer : public AcDbObjectPointerBase<T_OBJECT>
  266. {
  267. public:
  268. AcDbSymbolTablePointer();
  269. AcDbSymbolTablePointer(AcDbObjectId objId, AcDb::OpenMode mode);
  270. AcDbSymbolTablePointer(AcDbDatabase * pDb, AcDb::OpenMode mode);
  271. #if DBOBJPTR_EXPOSE_PTR_REF
  272. AcDbSymbolTablePointer(T_OBJECT * pObject);
  273. void operator=(T_OBJECT *pObject);
  274. #endif
  275. Acad::ErrorStatus open(AcDbObjectId objId, AcDb::OpenMode mode);
  276. Acad::ErrorStatus open(AcDbDatabase* pDb, AcDb::OpenMode mode);
  277. private:
  278. // Copy and assignment prohibited.
  279. AcDbSymbolTablePointer(AcDbSymbolTablePointer & pObject);
  280. AcDbSymbolTablePointer& operator=(AcDbSymbolTablePointer & pObject);
  281. // Restrict T_OBJECT to AcDbSymbolTable and derived classes.
  282. typedef typename T_OBJECT::RecordType T2;
  283. };
  284. typedef AcDbSymbolTablePointer<AcDbBlockTable> AcDbBlockTablePointer;
  285. typedef AcDbSymbolTablePointer<AcDbDimStyleTable> AcDbDimStyleTablePointer;
  286. typedef AcDbSymbolTablePointer<AcDbLayerTable> AcDbLayerTablePointer;
  287. typedef AcDbSymbolTablePointer<AcDbLinetypeTable> AcDbLinetypeTablePointer;
  288. typedef AcDbSymbolTablePointer<AcDbRegAppTable> AcDbRegAppTablePointer;
  289. typedef AcDbSymbolTablePointer<AcDbTextStyleTable> AcDbTextStyleTablePointer;
  290. typedef AcDbSymbolTablePointer<AcDbUCSTable> AcDbUCSTablePointer;
  291. typedef AcDbSymbolTablePointer<AcDbViewTable> AcDbViewTablePointer;
  292. typedef AcDbSymbolTablePointer<AcDbViewportTable> AcDbViewportTablePointer;
  293. // --------- AcDbSymbolTableRecordPointer<T_OBJECT> ---------
  294. // This class allows you to open any AcDbSymbolTableRecord or
  295. // AcDbSymbolTableRecord-derived object given its object ID or
  296. // its name and containing database. The different forms of
  297. // construction are:
  298. //
  299. // (AcDbObjectId objId, AcDb::OpenMode mode, bool openErased)
  300. // (const ACHAR * name, AcDbDatabase * pDb,
  301. // AcDb::OpenMode mode, bool openErased)
  302. //
  303. // The object ID, open mode, and open-erased arguments have the
  304. // same meaning as those for AcDbObjectPointer<T_OBJECT>. If
  305. // the name is a null pointer, the open status after
  306. // construction is eInvalidInput. If the database pointer is a
  307. // null pointer, then the open status after construction is
  308. // eNullObjectPointer.
  309. template<class T_OBJECT>
  310. class AcDbSymbolTableRecordPointer : public AcDbObjectPointerBase<T_OBJECT>
  311. {
  312. public:
  313. AcDbSymbolTableRecordPointer();
  314. AcDbSymbolTableRecordPointer(AcDbObjectId objId,
  315. AcDb::OpenMode mode,
  316. bool openErased = false);
  317. AcDbSymbolTableRecordPointer(const ACHAR * name,
  318. AcDbDatabase * pDb,
  319. AcDb::OpenMode mode,
  320. bool openErased = false);
  321. #if DBOBJPTR_EXPOSE_PTR_REF
  322. AcDbSymbolTableRecordPointer(T_OBJECT * pObject);
  323. void operator=(T_OBJECT *pObject);
  324. #endif
  325. Acad::ErrorStatus open(AcDbObjectId objId,
  326. AcDb::OpenMode mode,
  327. bool openErased = false);
  328. Acad::ErrorStatus open(const ACHAR * name,
  329. AcDbDatabase * pDb,
  330. AcDb::OpenMode mode,
  331. bool openErased = false);
  332. private:
  333. // Copy and assignment prohibited.
  334. AcDbSymbolTableRecordPointer(AcDbSymbolTableRecordPointer & pObject);
  335. AcDbSymbolTableRecordPointer&
  336. operator=(AcDbSymbolTableRecordPointer & pObject);
  337. // Restrict T_OBJECT to AcDbSymbolTableRecord and derived classes.
  338. typedef typename T_OBJECT::TableType T2;
  339. };
  340. typedef AcDbSymbolTableRecordPointer<AcDbBlockTableRecord>
  341. AcDbBlockTableRecordPointer;
  342. typedef AcDbSymbolTableRecordPointer<AcDbDimStyleTableRecord>
  343. AcDbDimStyleTableRecordPointer;
  344. typedef AcDbSymbolTableRecordPointer<AcDbLayerTableRecord>
  345. AcDbLayerTableRecordPointer;
  346. typedef AcDbSymbolTableRecordPointer<AcDbLinetypeTableRecord>
  347. AcDbLinetypeTableRecordPointer;
  348. typedef AcDbSymbolTableRecordPointer<AcDbRegAppTableRecord>
  349. AcDbRegAppTableRecordPointer;
  350. typedef AcDbSymbolTableRecordPointer<AcDbTextStyleTableRecord>
  351. AcDbTextStyleTableRecordPointer;
  352. typedef AcDbSymbolTableRecordPointer<AcDbUCSTableRecord>
  353. AcDbUCSTableRecordPointer;
  354. typedef AcDbSymbolTableRecordPointer<AcDbViewTableRecord>
  355. AcDbViewTableRecordPointer;
  356. typedef AcDbSymbolTableRecordPointer<AcDbViewportTableRecord>
  357. AcDbViewportTableRecordPointer;
  358. // --------- Inline definitions ---------
  359. template<class T_OBJECT> inline
  360. AcDbObjectPointerBase<T_OBJECT>::AcDbObjectPointerBase()
  361. : m_ptr(NULL),
  362. m_status(Acad::eNullObjectPointer)
  363. {
  364. }
  365. template<class T_OBJECT> inline
  366. AcDbObjectPointerBase<T_OBJECT>::AcDbObjectPointerBase(
  367. AcDbObjectId objId,
  368. AcDb::OpenMode mode,
  369. bool openErased)
  370. : m_ptr(NULL),
  371. m_status(acdbOpenObject(m_ptr, objId, mode, openErased))
  372. {
  373. }
  374. template<class T_OBJECT> inline
  375. AcDbObjectPointerBase<T_OBJECT>::~AcDbObjectPointerBase()
  376. {
  377. if (m_ptr != NULL) {
  378. assert(m_status == Acad::eOk);
  379. Acad::ErrorStatus closeStatus = closeInternal();
  380. (void)closeStatus;
  381. assert(closeStatus == Acad::eOk);
  382. }
  383. }
  384. template<class T_OBJECT> inline Acad::ErrorStatus
  385. AcDbObjectPointerBase<T_OBJECT>::open(
  386. AcDbObjectId objId,
  387. AcDb::OpenMode mode,
  388. bool openErased)
  389. {
  390. if (m_ptr != NULL) {
  391. assert(m_status == Acad::eOk);
  392. Acad::ErrorStatus closeStatus = closeInternal();
  393. if (closeStatus != Acad::eOk)
  394. return closeStatus;
  395. }
  396. m_status = acdbOpenObject(m_ptr, objId, mode, openErased);
  397. return m_status;
  398. }
  399. template<class T_OBJECT> inline const T_OBJECT *
  400. AcDbObjectPointerBase<T_OBJECT>::object() const
  401. {
  402. assert(m_status == Acad::eOk);
  403. assert(m_ptr != NULL);
  404. DbObjPtr_Assert(m_ptr == NULL || m_ptr->isReadEnabled());
  405. return m_ptr;
  406. }
  407. // This function does not modify the object, but we may not make
  408. // it const. Doing so will overload it with the const operator->()
  409. // function above, which is not allowed (we're overloading on
  410. // const-ness).
  411. template<class T_OBJECT> inline T_OBJECT *
  412. AcDbObjectPointerBase<T_OBJECT>::object()
  413. {
  414. assert(m_status == Acad::eOk);
  415. assert(m_ptr != NULL);
  416. DbObjPtr_Assert(m_ptr == NULL || m_ptr->isReadEnabled());
  417. return m_ptr;
  418. }
  419. template<class T_OBJECT> inline const T_OBJECT *
  420. AcDbObjectPointerBase<T_OBJECT>::operator->() const
  421. {
  422. return object();
  423. }
  424. template<class T_OBJECT> inline T_OBJECT *
  425. AcDbObjectPointerBase<T_OBJECT>::operator->()
  426. {
  427. return object();
  428. }
  429. template<class T_OBJECT> inline
  430. AcDbObjectPointerBase<T_OBJECT>::operator const T_OBJECT*() const
  431. {
  432. return object();
  433. }
  434. #if DBOBJPTR_EXPOSE_PTR_REF
  435. template<class T_OBJECT> inline
  436. AcDbObjectPointerBase<T_OBJECT>::operator T_OBJECT* &()
  437. {
  438. // Allows direct modification of the pointer member
  439. return this->m_ptr;
  440. }
  441. #else
  442. template<class T_OBJECT> inline
  443. AcDbObjectPointerBase<T_OBJECT>::operator T_OBJECT*()
  444. {
  445. return object();
  446. }
  447. #endif
  448. template<class T_OBJECT> inline Acad::ErrorStatus
  449. AcDbObjectPointerBase<T_OBJECT>::openStatus() const
  450. {
  451. return m_status;
  452. }
  453. template<class T_OBJECT> inline Acad::ErrorStatus
  454. AcDbObjectPointerBase<T_OBJECT>::acquire(T_OBJECT *& pObjToAcquire)
  455. {
  456. if (pObjToAcquire == NULL)
  457. return Acad::eNullObjectPointer;
  458. if (m_ptr != NULL) {
  459. assert(m_status == Acad::eOk);
  460. Acad::ErrorStatus closeStatus = closeInternal();
  461. if (closeStatus != Acad::eOk)
  462. return closeStatus;
  463. }
  464. m_ptr = pObjToAcquire;
  465. m_status = Acad::eOk;
  466. pObjToAcquire = NULL;
  467. return Acad::eOk;
  468. }
  469. template<class T_OBJECT> inline Acad::ErrorStatus
  470. AcDbObjectPointerBase<T_OBJECT>::release(T_OBJECT *& pReleasedObj)
  471. {
  472. if (m_ptr == NULL)
  473. return Acad::eNullObjectPointer;
  474. assert(m_status == Acad::eOk);
  475. pReleasedObj = m_ptr;
  476. m_ptr = NULL;
  477. m_status = Acad::eNullObjectPointer;
  478. return Acad::eOk;
  479. }
  480. template<class T_OBJECT> inline Acad::ErrorStatus
  481. AcDbObjectPointerBase<T_OBJECT>::close()
  482. {
  483. if (m_ptr == NULL)
  484. return Acad::eNullObjectPointer;
  485. assert(m_status == Acad::eOk);
  486. Acad::ErrorStatus closeStatus = closeInternal();
  487. UNREFERENCED_PARAMETER(closeStatus);
  488. assert(closeStatus == Acad::eOk);
  489. return Acad::eOk;
  490. }
  491. template<class T_OBJECT> inline Acad::ErrorStatus
  492. AcDbObjectPointerBase<T_OBJECT>::create()
  493. {
  494. T_OBJECT * pObject = new T_OBJECT;
  495. if (pObject == NULL)
  496. return Acad::eNullObjectPointer;
  497. if (m_ptr != NULL) {
  498. assert(m_status == Acad::eOk);
  499. Acad::ErrorStatus closeStatus = closeInternal();
  500. if (closeStatus != Acad::eOk) {
  501. delete pObject;
  502. return closeStatus;
  503. }
  504. }
  505. m_ptr = pObject;
  506. m_status = Acad::eOk;
  507. return Acad::eOk;
  508. }
  509. template<class T_OBJECT> inline Acad::ErrorStatus
  510. AcDbObjectPointerBase<T_OBJECT>::closeInternal()
  511. {
  512. if (m_ptr == NULL)
  513. return Acad::eOk;
  514. Acad::ErrorStatus es = Acad::eOk;
  515. if (m_ptr->objectId().isNull()) {
  516. delete m_ptr;
  517. es = Acad::eOk;
  518. } else {
  519. es = m_ptr->close();
  520. }
  521. m_ptr = NULL;
  522. m_status = Acad::eNullObjectPointer;
  523. return es;
  524. }
  525. template<class T_OBJECT> inline
  526. AcDbObjectPointer<T_OBJECT>::AcDbObjectPointer()
  527. : AcDbObjectPointerBase<T_OBJECT>()
  528. {
  529. }
  530. template<class T_OBJECT> inline
  531. AcDbObjectPointer<T_OBJECT>::AcDbObjectPointer(
  532. AcDbObjectId objId,
  533. AcDb::OpenMode mode,
  534. bool openErased)
  535. : AcDbObjectPointerBase<T_OBJECT>(objId, mode, openErased)
  536. {
  537. }
  538. template<class T_OBJECT> inline Acad::ErrorStatus
  539. AcDbObjectPointer<T_OBJECT>::open(
  540. AcDbObjectId objId,
  541. AcDb::OpenMode mode,
  542. bool openErased)
  543. {
  544. return AcDbObjectPointerBase<T_OBJECT>::open(objId, mode, openErased);
  545. }
  546. template<class T_OBJECT> inline
  547. AcDbSymbolTablePointer<T_OBJECT>::AcDbSymbolTablePointer()
  548. : AcDbObjectPointerBase<T_OBJECT>()
  549. {
  550. }
  551. template<class T_OBJECT> inline
  552. AcDbSymbolTablePointer<T_OBJECT>::AcDbSymbolTablePointer(
  553. AcDbObjectId objId,
  554. AcDb::OpenMode mode)
  555. : AcDbObjectPointerBase<T_OBJECT>(objId, mode, false)
  556. {
  557. }
  558. template<class T_OBJECT> inline
  559. AcDbSymbolTablePointer<T_OBJECT>::AcDbSymbolTablePointer(
  560. AcDbDatabase * pDb,
  561. AcDb::OpenMode mode)
  562. : AcDbObjectPointerBase<T_OBJECT>()
  563. {
  564. this->m_status = (pDb == NULL) ? Acad::eNullObjectPointer
  565. : pDb->getSymbolTable(this->m_ptr, mode);
  566. }
  567. template<class T_OBJECT> inline Acad::ErrorStatus
  568. AcDbSymbolTablePointer<T_OBJECT>::open(
  569. AcDbObjectId objId,
  570. AcDb::OpenMode mode)
  571. {
  572. return AcDbObjectPointerBase<T_OBJECT>::open(objId, mode, false);
  573. }
  574. template<class T_OBJECT> inline Acad::ErrorStatus
  575. AcDbSymbolTablePointer<T_OBJECT>::open(
  576. AcDbDatabase* pDb,
  577. AcDb::OpenMode mode)
  578. {
  579. if (pDb == NULL)
  580. return Acad::eInvalidInput;
  581. Acad::ErrorStatus es = Acad::eOk;
  582. if (this->m_ptr != NULL)
  583. es = this->close();
  584. if (es == Acad::eOk) {
  585. es = pDb->getSymbolTable(this->m_ptr, mode);
  586. this->m_status = es;
  587. }
  588. return es;
  589. }
  590. template<class T_OBJECT> inline
  591. AcDbSymbolTableRecordPointer<T_OBJECT>::AcDbSymbolTableRecordPointer()
  592. : AcDbObjectPointerBase<T_OBJECT>()
  593. {
  594. }
  595. template<class T_OBJECT> inline
  596. AcDbSymbolTableRecordPointer<T_OBJECT>::AcDbSymbolTableRecordPointer(
  597. AcDbObjectId objId,
  598. AcDb::OpenMode mode,
  599. bool openErased)
  600. : AcDbObjectPointerBase<T_OBJECT>(objId, mode, openErased)
  601. {
  602. }
  603. template<class T_OBJECT> inline
  604. AcDbSymbolTableRecordPointer<T_OBJECT>
  605. ::AcDbSymbolTableRecordPointer(
  606. const ACHAR * name,
  607. AcDbDatabase * pDb,
  608. AcDb::OpenMode mode,
  609. bool openErased)
  610. : AcDbObjectPointerBase<T_OBJECT>()
  611. {
  612. if (name == NULL)
  613. this->m_status = Acad::eInvalidInput;
  614. else {
  615. AcDbSymbolTablePointer<typename T_OBJECT::TableType>
  616. pTable(pDb, AcDb::kForRead);
  617. this->m_status = pTable.openStatus();
  618. if (this->m_status == Acad::eOk)
  619. this->m_status = pTable->getAt(name, this->m_ptr, mode, openErased);
  620. }
  621. }
  622. template<class T_OBJECT> inline Acad::ErrorStatus
  623. AcDbSymbolTableRecordPointer<T_OBJECT>::open(
  624. AcDbObjectId objId,
  625. AcDb::OpenMode mode,
  626. bool openErased)
  627. {
  628. return AcDbObjectPointerBase<T_OBJECT>::open(objId, mode, openErased);
  629. }
  630. template<class T_OBJECT> inline Acad::ErrorStatus
  631. AcDbSymbolTableRecordPointer<T_OBJECT>
  632. ::open(const ACHAR * name,
  633. AcDbDatabase * pDb,
  634. AcDb::OpenMode mode,
  635. bool openErased)
  636. {
  637. if (name == NULL)
  638. return Acad::eInvalidInput;
  639. else {
  640. AcDbSymbolTablePointer<typename T_OBJECT::TableType>
  641. pTable(pDb, AcDb::kForRead);
  642. Acad::ErrorStatus es = pTable.openStatus();
  643. if (es == Acad::eOk) {
  644. if (this->m_ptr != NULL)
  645. es = this->close();
  646. if (es == Acad::eOk) {
  647. es = pTable->getAt(name, this->m_ptr, mode, openErased);
  648. this->m_status = es;
  649. }
  650. }
  651. return es;
  652. }
  653. }
  654. #if DBOBJPTR_EXPOSE_PTR_REF
  655. template<class T_OBJECT> inline
  656. AcDbObjectPointerBase<T_OBJECT>::AcDbObjectPointerBase(T_OBJECT *pObject)
  657. : m_ptr(NULL),
  658. m_status(Acad::eNullObjectPointer)
  659. {
  660. if (pObject != NULL)
  661. this->acquire(pObject);
  662. }
  663. template<class T_OBJECT> inline void
  664. AcDbObjectPointerBase<T_OBJECT>::operator=(T_OBJECT *pObject)
  665. {
  666. if (pObject == NULL) {
  667. DbObjPtr_Assert(this->m_ptr == NULL);
  668. }
  669. else
  670. this->acquire(pObject);
  671. }
  672. template<class T_OBJECT> inline
  673. AcDbObjectPointer<T_OBJECT>::AcDbObjectPointer(T_OBJECT *pObject)
  674. : AcDbObjectPointerBase<T_OBJECT>(pObject)
  675. {
  676. }
  677. template<class T_OBJECT> inline AcDbSymbolTablePointer<T_OBJECT>::
  678. AcDbSymbolTablePointer(T_OBJECT *pObject)
  679. : AcDbObjectPointerBase<T_OBJECT>(pObject)
  680. {
  681. }
  682. template<class T_OBJECT> inline AcDbSymbolTableRecordPointer<T_OBJECT>::
  683. AcDbSymbolTableRecordPointer(T_OBJECT *pObject)
  684. : AcDbObjectPointerBase<T_OBJECT>(pObject)
  685. {
  686. }
  687. template<class T_OBJECT> inline void
  688. AcDbObjectPointer<T_OBJECT>::operator=(T_OBJECT *pObject)
  689. {
  690. AcDbObjectPointerBase<T_OBJECT>::operator =(pObject);
  691. }
  692. template<class T_OBJECT> inline void
  693. AcDbSymbolTablePointer<T_OBJECT>::operator=(T_OBJECT *pObject)
  694. {
  695. AcDbObjectPointerBase<T_OBJECT>::operator =(pObject);
  696. }
  697. template<class T_OBJECT> inline void
  698. AcDbSymbolTableRecordPointer<T_OBJECT>::operator=(T_OBJECT *pObject)
  699. {
  700. AcDbObjectPointerBase<T_OBJECT>::operator =(pObject);
  701. }
  702. #endif // DBOBJPTR_EXPOSE_PTR_REF
  703. #pragma pack (pop)
  704. #endif // AD_DBOBJPTR_H