dbindex.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. // AcDbIndex is the base class for all index implementations.
  14. //
  15. // These indexes are associated with Block Spaces, and can be used
  16. // to perform an efficient filtered traversal of the block.
  17. //
  18. #ifndef AD_DBINDEX_H
  19. #define AD_DBINDEX_H
  20. #include "dbmain.h"
  21. #pragma pack(push, 8)
  22. class AcDbIndexIterator;
  23. class AcDbFilter;
  24. class AcDbIndexUpdateData;
  25. class AcDbBlockChangeIterator;
  26. class AcDbFilteredBlockIterator;
  27. class AcDbFilter;
  28. class AcDbImpDatabase;
  29. class AcDbBlockTableRecord;
  30. class AcDbBlockChangeIterator;
  31. class AcDbIndexUpdateData;
  32. class AcDbIndex : public AcDbObject
  33. {
  34. public:
  35. ACDB_DECLARE_MEMBERS(AcDbIndex);
  36. AcDbIndex();
  37. virtual ~AcDbIndex();
  38. virtual AcDbFilteredBlockIterator*
  39. newIterator(const AcDbFilter* pFilter) const;
  40. virtual Acad::ErrorStatus rebuildFull(AcDbIndexUpdateData* pIdxData);
  41. virtual AcDbObjectId objectBeingIndexedId() const;
  42. void setLastUpdatedAt(const AcDbDate& time);
  43. AcDbDate lastUpdatedAt() const;
  44. // Same as above two methods, but time vals are universal, not local.
  45. //
  46. void setLastUpdatedAtU(const AcDbDate& time);
  47. AcDbDate lastUpdatedAtU() const;
  48. Adesk::Boolean isUptoDate () const;
  49. protected:
  50. // Invoked by the AcIndexFilterManager::updateIndexes(), when
  51. // only modifications are being registered. This is not
  52. // exposed since all the Index objects need to be updated
  53. // when modifications are being propagated.
  54. virtual Acad::ErrorStatus rebuildModified(AcDbBlockChangeIterator* iter);
  55. friend class AcDbImpIndex;
  56. friend Acad::ErrorStatus processBTRIndexObjects(
  57. AcDbBlockTableRecord* pBTR,
  58. int indexCtlVal,
  59. AcDbBlockChangeIterator* pBlkChgIter,
  60. AcDbIndexUpdateData* pIdxUpdData);
  61. };
  62. class AcDbFilteredBlockIterator
  63. {
  64. public:
  65. AcDbFilteredBlockIterator() {}
  66. virtual ~AcDbFilteredBlockIterator() {}
  67. virtual Acad::ErrorStatus start() = 0;
  68. virtual AcDbObjectId next() = 0;
  69. virtual AcDbObjectId id() const = 0;
  70. virtual Acad::ErrorStatus seek(AcDbObjectId id) = 0;
  71. // Methods used for handling multiple index object based filters.
  72. virtual double estimatedHitFraction() const = 0;
  73. virtual Acad::ErrorStatus accepts(AcDbObjectId id,
  74. Adesk::Boolean& idPassesFilter) const = 0;
  75. // Defaults to false
  76. //
  77. virtual Adesk::Boolean buffersForComposition() const;
  78. virtual Acad::ErrorStatus addToBuffer(AcDbObjectId id);
  79. };
  80. class AcDbCompositeFilteredBlockIterator
  81. {
  82. private:
  83. AcDbCompositeFilteredBlockIterator(
  84. const AcDbCompositeFilteredBlockIterator& copyFrom);
  85. protected:
  86. AcDbCompositeFilteredBlockIterator() {}
  87. public:
  88. virtual ~AcDbCompositeFilteredBlockIterator() {}
  89. virtual Acad::ErrorStatus init(AcDbFilter* const * ppFilters,
  90. int numFilters,
  91. const AcDbBlockTableRecord* pBtr) = 0;
  92. virtual Acad::ErrorStatus start() = 0;
  93. virtual AcDbObjectId next() = 0;
  94. virtual AcDbObjectId id() const = 0;
  95. virtual Acad::ErrorStatus seek(AcDbObjectId id) = 0;
  96. static AcDbCompositeFilteredBlockIterator* newIterator();
  97. };
  98. class AcDbBlockTableRecord;
  99. class AcDbBlockReference;
  100. namespace AcDbIndexFilterManager
  101. {
  102. // Updates all indexes in the Block Table.
  103. //
  104. Acad::ErrorStatus updateIndexes(AcDbDatabase* pDb);
  105. // Block Table Record Index access methods.
  106. Acad::ErrorStatus addIndex (AcDbBlockTableRecord* pBTR,
  107. AcDbIndex* pIndex);
  108. Acad::ErrorStatus removeIndex (AcDbBlockTableRecord* pBTR,
  109. const AcRxClass* key);
  110. Acad::ErrorStatus getIndex(const AcDbBlockTableRecord* pBTR,
  111. const AcRxClass* key,
  112. AcDb::OpenMode readOrWrite,
  113. AcDbIndex*& pIndex);
  114. Acad::ErrorStatus getIndex(const AcDbBlockTableRecord* pBTR,
  115. int index,
  116. AcDb::OpenMode readOrWrite,
  117. AcDbIndex*& pIndex);
  118. int numIndexes(const AcDbBlockTableRecord* pBtr);
  119. // Block Reference Filter access methods.
  120. Acad::ErrorStatus addFilter(AcDbBlockReference* pBlkRef,
  121. AcDbFilter* pFilter);
  122. Acad::ErrorStatus removeFilter(AcDbBlockReference* pBlkRef,
  123. const AcRxClass* key);
  124. Acad::ErrorStatus getFilter(const AcDbBlockReference* pRef,
  125. const AcRxClass* key,
  126. AcDb::OpenMode readOrWrite,
  127. AcDbFilter*& pFilter);
  128. Acad::ErrorStatus getFilter(const AcDbBlockReference* pRef,
  129. int index,
  130. AcDb::OpenMode readOrWrite,
  131. AcDbFilter*& pFilter);
  132. int numFilters(const AcDbBlockReference* pBlkRef);
  133. };
  134. class AcDbHandleTable;
  135. class AcDbHandleTableIterator;
  136. // Is a form of an alternate table of ids, primarily modified ones
  137. // during partial index update.
  138. //
  139. class AcDbIndexUpdateData
  140. {
  141. public:
  142. enum UpdateFlags
  143. { // kModified and kDeleted are READ ONLY.
  144. kModified = 1, //
  145. kDeleted = 2, // kDeleted is somewhat redundant with AcDbObject::isErased()
  146. // except that it also accounts for uncreated
  147. // objects, and does not force an object to be
  148. // paged in.
  149. // These two are writable. They are for application use.
  150. kProcessed = 4, // kProcessed can be used to avoid rexamining an id.
  151. kUnknownKey = 8 // kUnknownKey is used, for example, to denote unknown
  152. // extents when building the spatial index.
  153. // The remaining bits can be used by applications as
  154. // they wish. (Bits 3- 7).
  155. };
  156. Acad::ErrorStatus addId (AcDbObjectId id);
  157. // Bits kModified and kDeleted are never changed by this method, since
  158. // they refer to the db state of the object. The kProcessed bit and
  159. // kUnknownKey are for specific Index (layer and spatial) processing.
  160. //
  161. Acad::ErrorStatus setIdFlags (AcDbObjectId id, Adesk::UInt8 flags);
  162. Acad::ErrorStatus setIdData (AcDbObjectId id, Adesk::ULongPtr data);
  163. Acad::ErrorStatus getIdData (AcDbObjectId id, Adesk::ULongPtr& data) const;
  164. Acad::ErrorStatus getIdFlags (AcDbObjectId id, Adesk::UInt8& flags) const;
  165. Acad::ErrorStatus getFlagsAndData (AcDbObjectId id,
  166. Adesk::UInt8& flags,
  167. Adesk::ULongPtr& data) const;
  168. private:
  169. AcDbIndexUpdateData();
  170. ~AcDbIndexUpdateData();
  171. AcDbIndexUpdateData(const AcDbIndexUpdateData&);
  172. AcDbHandleTable* mpTable;
  173. friend class AcDbIndexUpdateDataIterator;
  174. friend class AcDbImpDatabase;
  175. };
  176. class AcDbIndexUpdateDataIterator
  177. {
  178. public:
  179. AcDbIndexUpdateDataIterator (const AcDbIndexUpdateData* p);
  180. ~AcDbIndexUpdateDataIterator ();
  181. void start ();
  182. void next ();
  183. bool done ();
  184. Acad::ErrorStatus currentData (AcDbObjectId& id,
  185. Adesk::UInt8& flags,
  186. Adesk::ULongPtr& data) const;
  187. private:
  188. AcDbHandleTableIterator* mpIter;
  189. };
  190. // Iterates over only changed entities inside a block table record.
  191. //
  192. class AcDbBlockChangeIterator
  193. {
  194. private:
  195. AcDbBlockChangeIterator();
  196. AcDbBlockChangeIterator(const AcDbBlockChangeIterator&);
  197. AcDbBlockChangeIterator (AcDbObjectId btrId,
  198. AcDbIndexUpdateData* pIdxUpdData);
  199. ~AcDbBlockChangeIterator();
  200. public:
  201. void start ();
  202. AcDbObjectId id () const;
  203. void next ();
  204. bool done ();
  205. // Utility to get at this data without having to go through
  206. // the updateData() method.
  207. //
  208. Acad::ErrorStatus curIdInfo (AcDbObjectId& id,
  209. Adesk::UInt8& flags,
  210. Adesk::ULongPtr& data) const;
  211. Acad::ErrorStatus setCurIdInfo (Adesk::UInt8 flags,
  212. Adesk::ULongPtr data);
  213. AcDbIndexUpdateData* updateData () const;
  214. void clearProcessedFlags();
  215. private:
  216. AcDbIndexUpdateData* mpIds;
  217. AcDbObjectId mBTRId;
  218. AcDbIndexUpdateDataIterator* mpIter;
  219. friend class AcDbImpDatabase;
  220. };
  221. #pragma pack(pop)
  222. #endif // AD_DBINDEX_H