dbid.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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. // DESCRIPTION:
  13. //
  14. // This file contains lightweight id classes distinguishing between
  15. // different types of object id's. A distinction is made between an
  16. // owned object and a reference or "pointer to" an object, as well as
  17. // whether the relationship protects the object from purge (hard/soft).
  18. //
  19. // Hard-owner:
  20. //
  21. // An owned object protected from purge. A layer symbol table and
  22. // layer 0 is an example of a hard-owner relationship.
  23. //
  24. // Soft-owner:
  25. //
  26. // An owned object not protected from purge. All symbol tables own
  27. // their records, but that relationship does not usually protect
  28. // the records from purge.
  29. //
  30. // Hard-pointer:
  31. //
  32. // A reference to an object that is not owned, but protected from
  33. // purge. An entity, for example, does not own the layer it is on
  34. // but its reference to it protects it from purge.
  35. //
  36. // Soft-pointer:
  37. //
  38. // A reference to an object that is not owned, and not protected
  39. // from purge.
  40. #ifndef _AD_DBID_H
  41. #define _AD_DBID_H 1
  42. #include "adesk.h"
  43. #include "dbhandle.h"
  44. #pragma pack(push, 8)
  45. class AcDbDatabase;
  46. class AcDbStub;
  47. class AcRxClass;
  48. class AcDbObjectId
  49. {
  50. public:
  51. AcDbObjectId();
  52. AcDbObjectId(const AcDbStub*);
  53. static const AcDbObjectId kNull; // see definition below
  54. bool isNull() const;
  55. void setNull();
  56. Adesk::IntDbId asOldId () const;
  57. AcDbObjectId& setFromOldId(Adesk::IntDbId oldId);
  58. #if defined(_WIN64) || defined(_AC64)
  59. private:
  60. // catch attempts to store the id in and set it from a 32-bit long
  61. AcDbObjectId& setFromOldId(long);
  62. public:
  63. // need this overload to allow passing of unsigned 64-bit
  64. inline AcDbObjectId& setFromOldId(Adesk::UIntPtr nUnsignedId)
  65. {
  66. const Adesk::IntDbId nSignedId =
  67. static_cast<Adesk::IntDbId>(nUnsignedId);
  68. return this->setFromOldId(nSignedId);
  69. }
  70. #endif
  71. bool isValid() const;
  72. AcDbObjectId& operator = (const AcDbObjectId&);
  73. AcDbObjectId& operator = (const AcDbStub*);
  74. bool operator < (const AcDbObjectId&) const;
  75. bool operator > (const AcDbObjectId&) const;
  76. bool operator >= (const AcDbObjectId&) const;
  77. bool operator <= (const AcDbObjectId&) const;
  78. bool operator == (const AcDbObjectId&) const;
  79. bool operator != (const AcDbObjectId&) const;
  80. bool operator < (const AcDbStub*) const;
  81. bool operator > (const AcDbStub*) const;
  82. bool operator >= (const AcDbStub*) const;
  83. bool operator <= (const AcDbStub*) const;
  84. bool operator == (const AcDbStub*) const;
  85. bool operator != (const AcDbStub*) const;
  86. operator AcDbStub* () const;
  87. AcDbDatabase* database() const;
  88. AcDbDatabase* originalDatabase() const;
  89. void convertToRedirectedId();
  90. bool isErased() const;
  91. bool isEffectivelyErased() const;
  92. bool isResident() const;
  93. bool objectLeftOnDisk() const;
  94. AcDbHandle handle() const;
  95. AcDbHandle nonForwardedHandle() const;
  96. AcRxClass* objectClass() const;
  97. protected:
  98. AcDbStub* mId;
  99. };
  100. class AcDbHardOwnershipId : public AcDbObjectId
  101. {
  102. public:
  103. AcDbHardOwnershipId();
  104. AcDbHardOwnershipId(const AcDbObjectId&);
  105. AcDbHardOwnershipId(const AcDbStub*);
  106. AcDbHardOwnershipId& operator =(const AcDbHardOwnershipId&);
  107. AcDbHardOwnershipId& operator =(const AcDbObjectId&);
  108. AcDbHardOwnershipId& operator =(const AcDbStub*);
  109. bool operator != (const AcDbObjectId&) const;
  110. bool operator != (const AcDbStub*) const;
  111. bool operator == (const AcDbObjectId&) const;
  112. bool operator == (const AcDbStub*) const;
  113. operator AcDbStub* () const;
  114. };
  115. class AcDbSoftOwnershipId : public AcDbObjectId
  116. {
  117. public:
  118. AcDbSoftOwnershipId();
  119. AcDbSoftOwnershipId(const AcDbObjectId&);
  120. AcDbSoftOwnershipId(const AcDbStub*);
  121. AcDbSoftOwnershipId& operator =(const AcDbSoftOwnershipId&);
  122. AcDbSoftOwnershipId& operator =(const AcDbObjectId&);
  123. AcDbSoftOwnershipId& operator =(const AcDbStub*);
  124. bool operator != (const AcDbObjectId&) const;
  125. bool operator != (const AcDbStub*) const;
  126. bool operator == (const AcDbObjectId&) const;
  127. bool operator == (const AcDbStub*) const;
  128. operator AcDbStub* () const;
  129. };
  130. class AcDbHardPointerId : public AcDbObjectId
  131. {
  132. public:
  133. AcDbHardPointerId();
  134. AcDbHardPointerId(const AcDbObjectId&);
  135. AcDbHardPointerId(const AcDbStub*);
  136. AcDbHardPointerId& operator =(const AcDbHardPointerId&);
  137. AcDbHardPointerId& operator =(const AcDbObjectId&);
  138. AcDbHardPointerId& operator =(const AcDbStub*);
  139. bool operator != (const AcDbObjectId&) const;
  140. bool operator != (const AcDbStub*) const;
  141. bool operator == (const AcDbObjectId&) const;
  142. bool operator == (const AcDbStub*) const;
  143. operator AcDbStub* () const;
  144. };
  145. class AcDbSoftPointerId : public AcDbObjectId
  146. {
  147. public:
  148. AcDbSoftPointerId();
  149. AcDbSoftPointerId(const AcDbObjectId&);
  150. AcDbSoftPointerId(const AcDbStub*);
  151. AcDbSoftPointerId& operator =(const AcDbSoftPointerId&);
  152. AcDbSoftPointerId& operator =(const AcDbObjectId&);
  153. AcDbSoftPointerId& operator =(const AcDbStub*);
  154. bool operator != (const AcDbObjectId&) const;
  155. bool operator != (const AcDbStub*) const;
  156. bool operator == (const AcDbObjectId&) const;
  157. bool operator == (const AcDbStub*) const;
  158. operator AcDbStub* () const;
  159. };
  160. //////////////////// AcDbObjectId inlines ////////////////////
  161. __declspec(selectany) const AcDbObjectId AcDbObjectId::kNull;
  162. inline
  163. AcDbObjectId::AcDbObjectId()
  164. { mId = nullptr; }
  165. //inline
  166. //AcDbObjectId::AcDbObjectId(const AcDbObjectId& id)
  167. //{ mId = id.mId; }
  168. inline
  169. AcDbObjectId::AcDbObjectId(const AcDbStub* pStub)
  170. { mId = const_cast<AcDbStub*>(pStub); }
  171. inline bool
  172. AcDbObjectId::isNull() const
  173. { return mId == nullptr; }
  174. inline void
  175. AcDbObjectId::setNull()
  176. { mId = nullptr; }
  177. inline
  178. Adesk::IntDbId AcDbObjectId::asOldId() const
  179. {
  180. return reinterpret_cast<Adesk::IntDbId>(this->mId);
  181. }
  182. inline
  183. AcDbObjectId& AcDbObjectId::setFromOldId(Adesk::IntDbId oldId)
  184. {
  185. this->mId = reinterpret_cast<AcDbStub*>(oldId);
  186. return *this;
  187. }
  188. inline
  189. AcDbObjectId& AcDbObjectId::operator = (const AcDbObjectId& id)
  190. { mId = id.mId; return *this; }
  191. inline
  192. AcDbObjectId& AcDbObjectId::operator = (const AcDbStub* pStub)
  193. { mId = const_cast<AcDbStub*>(pStub); return *this; }
  194. inline
  195. AcDbObjectId::operator AcDbStub* () const
  196. { return mId; }
  197. //////////////////// AcDbHardOwnershipId inlines ////////////////////
  198. inline
  199. AcDbHardOwnershipId::AcDbHardOwnershipId() {}
  200. inline
  201. AcDbHardOwnershipId::AcDbHardOwnershipId(const AcDbObjectId& id)
  202. : AcDbObjectId(id) {}
  203. inline
  204. AcDbHardOwnershipId::AcDbHardOwnershipId(const AcDbStub* pStub)
  205. : AcDbObjectId(pStub) {}
  206. inline
  207. AcDbHardOwnershipId& AcDbHardOwnershipId::operator = (
  208. const AcDbHardOwnershipId& id)
  209. { AcDbObjectId::operator=(id); return *this; }
  210. inline
  211. AcDbHardOwnershipId& AcDbHardOwnershipId::operator = (const AcDbObjectId& id)
  212. { AcDbObjectId::operator=(id); return *this; }
  213. inline
  214. AcDbHardOwnershipId& AcDbHardOwnershipId::operator = (const AcDbStub* pStub)
  215. { mId = const_cast<AcDbStub*>(pStub); return *this; }
  216. inline
  217. bool AcDbHardOwnershipId::operator != (const AcDbObjectId& id) const
  218. { return AcDbObjectId::operator!=(id); }
  219. inline
  220. bool AcDbHardOwnershipId::operator != (const AcDbStub* pStub) const
  221. { return AcDbObjectId::operator!=(pStub); }
  222. inline
  223. bool AcDbHardOwnershipId::operator == (const AcDbObjectId& id) const
  224. { return AcDbObjectId::operator==(id); }
  225. inline
  226. bool AcDbHardOwnershipId::operator == (const AcDbStub* pStub) const
  227. { return AcDbObjectId::operator==(pStub); }
  228. inline
  229. AcDbHardOwnershipId::operator AcDbStub* () const
  230. { return mId; }
  231. //////////////////// AcDbSoftOwnershipId inlines ////////////////////
  232. inline
  233. AcDbSoftOwnershipId::AcDbSoftOwnershipId() {}
  234. inline
  235. AcDbSoftOwnershipId::AcDbSoftOwnershipId(const AcDbObjectId& id)
  236. : AcDbObjectId(id) {}
  237. inline
  238. AcDbSoftOwnershipId::AcDbSoftOwnershipId(const AcDbStub* pStub)
  239. : AcDbObjectId(pStub) {}
  240. inline
  241. AcDbSoftOwnershipId& AcDbSoftOwnershipId::operator = (
  242. const AcDbSoftOwnershipId& id)
  243. { AcDbObjectId::operator=(id); return *this; }
  244. inline
  245. AcDbSoftOwnershipId& AcDbSoftOwnershipId::operator = (const AcDbObjectId& id)
  246. { AcDbObjectId::operator=(id); return *this; }
  247. inline
  248. AcDbSoftOwnershipId& AcDbSoftOwnershipId::operator = (const AcDbStub* pStub)
  249. { mId = const_cast<AcDbStub*>(pStub); return *this; }
  250. inline
  251. bool AcDbSoftOwnershipId::operator != (const AcDbObjectId& id) const
  252. { return AcDbObjectId::operator!=(id); }
  253. inline
  254. bool AcDbSoftOwnershipId::operator != (const AcDbStub* pStub) const
  255. { return AcDbObjectId::operator!=(pStub); }
  256. inline
  257. bool AcDbSoftOwnershipId::operator == (const AcDbObjectId& id) const
  258. { return AcDbObjectId::operator==(id); }
  259. inline
  260. bool AcDbSoftOwnershipId::operator == (const AcDbStub* pStub) const
  261. { return AcDbObjectId::operator==(pStub); }
  262. inline
  263. AcDbSoftOwnershipId::operator AcDbStub* () const
  264. { return mId; }
  265. //////////////////// AcDbHardPointerId inlines ////////////////////
  266. inline
  267. AcDbHardPointerId::AcDbHardPointerId() {}
  268. inline
  269. AcDbHardPointerId::AcDbHardPointerId(const AcDbObjectId& id)
  270. : AcDbObjectId(id) {}
  271. inline
  272. AcDbHardPointerId::AcDbHardPointerId(const AcDbStub* pStub)
  273. : AcDbObjectId(pStub) {}
  274. inline
  275. AcDbHardPointerId& AcDbHardPointerId::operator = (
  276. const AcDbHardPointerId& id)
  277. { AcDbObjectId::operator=(id); return *this; }
  278. inline
  279. AcDbHardPointerId& AcDbHardPointerId::operator = (const AcDbObjectId& id)
  280. { AcDbObjectId::operator=(id); return *this; }
  281. inline
  282. AcDbHardPointerId& AcDbHardPointerId::operator = (const AcDbStub* pStub)
  283. { mId = const_cast<AcDbStub*>(pStub); return *this; }
  284. inline
  285. bool AcDbHardPointerId::operator != (const AcDbObjectId& id) const
  286. { return AcDbObjectId::operator!=(id); }
  287. inline
  288. bool AcDbHardPointerId::operator != (const AcDbStub* pStub) const
  289. { return AcDbObjectId::operator!=(pStub); }
  290. inline
  291. bool AcDbHardPointerId::operator == (const AcDbObjectId& id) const
  292. { return AcDbObjectId::operator==(id); }
  293. inline
  294. bool AcDbHardPointerId::operator == (const AcDbStub* pStub) const
  295. { return AcDbObjectId::operator==(pStub); }
  296. inline
  297. AcDbHardPointerId::operator AcDbStub* () const
  298. { return mId; }
  299. //////////////////// AcDbSoftPointerId inlines ////////////////////
  300. inline
  301. AcDbSoftPointerId::AcDbSoftPointerId() {}
  302. inline
  303. AcDbSoftPointerId::AcDbSoftPointerId(const AcDbObjectId& id)
  304. : AcDbObjectId(id) {}
  305. inline
  306. AcDbSoftPointerId::AcDbSoftPointerId(const AcDbStub* pStub)
  307. : AcDbObjectId(pStub) {}
  308. inline
  309. AcDbSoftPointerId& AcDbSoftPointerId::operator = (const AcDbSoftPointerId& id)
  310. { AcDbObjectId::operator=(id); return *this; }
  311. inline
  312. AcDbSoftPointerId& AcDbSoftPointerId::operator = (const AcDbObjectId& id)
  313. { AcDbObjectId::operator=(id); return *this; }
  314. inline
  315. AcDbSoftPointerId& AcDbSoftPointerId::operator = (const AcDbStub* pStub)
  316. { mId = const_cast<AcDbStub*>(pStub); return *this; }
  317. inline
  318. bool AcDbSoftPointerId::operator != (const AcDbObjectId& id) const
  319. { return AcDbObjectId::operator!=(id); }
  320. inline
  321. bool AcDbSoftPointerId::operator != (const AcDbStub* pStub) const
  322. { return AcDbObjectId::operator!=(pStub); }
  323. inline
  324. bool AcDbSoftPointerId::operator == (const AcDbObjectId& id) const
  325. { return AcDbObjectId::operator==(id); }
  326. inline
  327. bool AcDbSoftPointerId::operator == (const AcDbStub* pStub) const
  328. { return AcDbObjectId::operator==(pStub); }
  329. inline
  330. AcDbSoftPointerId::operator AcDbStub* () const
  331. { return mId; }
  332. #define ADSK_ACDBOBJECTID_DEFINED
  333. #include "acarrayhelper.h"
  334. #pragma pack(pop)
  335. #endif