dbObjectContextCollection.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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: Abstract base class for collections of AcDbObjectContext
  13. // objects
  14. #ifndef ACDB_OBJECTCONTEXTCOLLECTION_H
  15. #define ACDB_OBJECTCONTEXTCOLLECTION_H
  16. #pragma once
  17. #include "acdb.h"
  18. #include "dbmain.h"
  19. #include "AcString.h"
  20. #include "dbObjContext.h"
  21. #pragma pack (push, 8)
  22. class AcDbObjectContextCollectionIterator;
  23. ////////////////////////////////////////////////////////////////////////
  24. // class AcDbObjectContextCollection
  25. ////////////////////////////////////////////////////////////////////////
  26. /// <summary>
  27. /// An interface to an application-defined collection of AcDbObjectContext
  28. /// objects.
  29. /// </summary>
  30. ///
  31. /// <remarks>
  32. /// Applications implement this interface to define custom object contexts for
  33. /// their context-sensitive objects. Applications must instantiate an instance
  34. /// of the collection (typically one instance for each database) and register
  35. /// it with the AcDbObjectContextCollectionManager for each AcDbDatabase which
  36. /// needs to support the context type. Each context collection has state,
  37. /// represented by the collection of contexts, the "current" context, and the
  38. /// ability to lock or unlock context instances.
  39. /// </remarks>
  40. ///
  41. class ADESK_NO_VTABLE AcDbObjectContextCollection: public AcRxObject
  42. {
  43. public:
  44. ACRX_DECLARE_MEMBERS(AcDbObjectContextCollection);
  45. /// <summary>
  46. /// The name of the context collection.
  47. /// </summary>
  48. ///
  49. /// <returns>
  50. /// Returns the name of the context collection.
  51. /// </returns>
  52. ///
  53. /// <remarks>
  54. /// Context collections must return a non-empty string from this method.
  55. /// The name of the collection is used to identify the collection to the
  56. /// manager, and to identify the kinds of context objects that may be added
  57. /// to the collection. (See also AcDbObjectContext::collectionName()).
  58. /// </remarks>
  59. virtual AcString name() const = 0;
  60. /// <summary>
  61. /// The current context for the collection.
  62. /// </summary>
  63. ///
  64. /// <param name="pRequestingObject">
  65. /// A pointer to the AcDbObject requesting the current context,
  66. /// may be NULL.
  67. /// </param>
  68. ///
  69. /// <returns>
  70. /// Returns a pointer to a copy of the currently active context in
  71. /// the collection, or NULL if there is no active context.
  72. /// </returns>
  73. ///
  74. /// <remarks>
  75. /// Context collections support a single current context. Some collections
  76. /// may support business logic where, depending on the requesting object,
  77. /// the collection exposes a different current context than the one
  78. /// last specified via a call to setCurrentContext(). For example,
  79. /// an application may attach data to custom objects which it uses to
  80. /// determine the current context when the custom object is passed to this
  81. /// method. Applications are responsible for deleting the returned object.
  82. /// </remarks>
  83. ///
  84. virtual AcDbObjectContext* currentContext(
  85. const AcDbObject* pRequestingObject) const = 0;
  86. /// <summary>
  87. /// Sets the current context for the collection.
  88. /// </summary>
  89. ///
  90. /// <param name="pContext">
  91. /// A pointer to the context to make current for the collection.
  92. /// </param>
  93. ///
  94. /// <returns>
  95. /// Returns Acad::eOk if the context is made current.
  96. /// </returns>
  97. ///
  98. /// <remarks>
  99. /// For a context to become active a context with the same identifier
  100. /// (AcDbObjectContext::uniqueIdentifier()) must be present in the
  101. /// collection.
  102. /// </remarks>
  103. ///
  104. virtual Acad::ErrorStatus setCurrentContext(
  105. const AcDbObjectContext* pContext) = 0;
  106. /// <summary>
  107. /// Adds a copy of a context to the collection.
  108. /// </summary>
  109. ///
  110. /// <param name="pContext">
  111. /// A pointer to the context to copy and add to the collection.
  112. /// </param>
  113. ///
  114. /// <returns>
  115. /// Returns Acad::eOk if successful.
  116. /// </returns>
  117. ///
  118. /// <remarks>
  119. /// Because the unique identifier of the collection resident contexts must
  120. /// be unique, the copied context added to the collection may be assigned
  121. /// a different identifier than the context it is copied from.
  122. /// </remarks>
  123. virtual Acad::ErrorStatus addContext(
  124. const AcDbObjectContext* pContext) = 0;
  125. // to set the currentContext() to NULL.
  126. /// <summary>
  127. /// Removes a context from the collection.
  128. /// </summary>
  129. ///
  130. /// <param name="contextName">
  131. /// The name of the context to remove from the collection.
  132. /// </param>
  133. ///
  134. /// <returns>
  135. /// Returns Acad::eOk if successful. Returns Acad::eKeyNotFound if no such
  136. /// context exists in the collection. Returns Acad::eObjectIsReferenced if
  137. /// the scale is the current scale.
  138. /// </returns>
  139. ///
  140. /// <remarks>
  141. /// The active context cannot be removed from a collection.
  142. /// </remarks>
  143. ///
  144. virtual Acad::ErrorStatus removeContext(
  145. const AcString& contextName) = 0;
  146. /// <summary>
  147. /// For internal use only.
  148. /// </summary>
  149. ///
  150. /// <returns>
  151. /// Returns Acad::eOk if successful.
  152. /// </returns>
  153. ///
  154. /// <remarks>
  155. /// For internal use only.
  156. /// </remarks>
  157. virtual Acad::ErrorStatus lockContext(
  158. const AcDbObjectContext* pContext) = 0;
  159. /// <summary>
  160. /// For internal use only.
  161. /// </summary>
  162. ///
  163. /// <returns>
  164. /// Returns Acad::eOk if successful.
  165. /// </returns>
  166. ///
  167. /// <remarks>
  168. /// For internal use only.
  169. /// </remarks>
  170. virtual Acad::ErrorStatus unlockContext() = 0;
  171. /// <summary>
  172. /// For internal use only.
  173. /// </summary>
  174. ///
  175. /// <returns>
  176. /// Returns true if the collection is locked.
  177. /// </returns>
  178. ///
  179. /// <remarks>
  180. /// For internal use only.
  181. /// </remarks>
  182. virtual bool locked() const = 0;
  183. /// <summary>
  184. /// Gets a copy of a context with the specified name.
  185. /// </summary>
  186. ///
  187. /// <param name="contextName">
  188. /// The name of the context to copy and return.
  189. /// </param>
  190. ///
  191. /// <returns>
  192. /// Returns a pointer to a copy of the specified context, or NULL if no
  193. /// such context exists in the collection.
  194. /// </returns>
  195. ///
  196. /// <remarks>
  197. /// Callers are responsible for freeing the copy of the context by calling
  198. /// delete on the returned pointer.
  199. /// </remarks>
  200. ///
  201. virtual AcDbObjectContext* getContext(
  202. const AcString& contextName) const = 0;
  203. /// <summary>
  204. /// Determines whether a context with the specified name exists in the
  205. /// collection.
  206. /// </summary>
  207. ///
  208. /// <param name="contextName">
  209. /// The name of the context to find.
  210. /// </param>
  211. ///
  212. /// <returns>
  213. /// Returns true if a context with the specified name exists in the
  214. /// collection.
  215. /// </returns>
  216. ///
  217. virtual bool hasContext(
  218. const AcString& contextName) const = 0;
  219. /// <summary>
  220. /// Returns a private iterator to the contexts in the collection.
  221. /// </summary>
  222. ///
  223. /// <returns>
  224. /// Returns a pointer to an AcDbObjectContextCollectionIterator that callers
  225. /// can use to enumerate the contexts in the collection.
  226. /// </returns>
  227. ///
  228. /// <remarks>
  229. /// Callers are responsible for freeing the iterator when it is no longer
  230. /// needed by calling delete on the returned pointer.
  231. /// </remarks>
  232. ///
  233. virtual AcDbObjectContextCollectionIterator* newIterator() const = 0;
  234. };
  235. ////////////////////////////////////////////////////////////////////////
  236. // class AcDbObjectContextCollectionIterator
  237. ////////////////////////////////////////////////////////////////////////
  238. /// <summary>
  239. /// An iterator iterface for AcDbObjectContext objects stored in an
  240. /// AcDbObjectContextCollection.
  241. /// </summary>
  242. ///
  243. /// <remarks>
  244. /// Callers obtain an iterator by calling
  245. /// AcDbObjectContextCollection::newIterator(). Applications that provide
  246. /// custom AcDbObjectContextCollection implementations must also implement this
  247. /// interface in a custom iterator for their collection.
  248. /// </remarks>
  249. ///
  250. class ADESK_NO_VTABLE AcDbObjectContextCollectionIterator : public AcRxObject
  251. {
  252. public:
  253. ACRX_DECLARE_MEMBERS(AcDbObjectContextCollectionIterator);
  254. /// <summary>
  255. /// Positions the iterator to the beginning of the collection.
  256. /// </summary>
  257. ///
  258. /// <returns>
  259. /// Returns Acad::eOk if successful.
  260. /// </returns>
  261. ///
  262. virtual Acad::ErrorStatus start() = 0;
  263. /// <summary>
  264. /// Positions the iterator to the next context in the collection.
  265. /// </summary>
  266. ///
  267. /// <returns>
  268. /// Returns true if the iterator was positioned to a context in the
  269. /// collection, or false if it has reached the end of the collection.
  270. /// </returns>
  271. virtual bool next() = 0;
  272. /// <summary>
  273. /// Determines whether the iterator has reached the end of the collection.
  274. /// </summary>
  275. ///
  276. /// <returns>
  277. /// Returns true if the iterator has reached the end of the collection.
  278. /// </returns>
  279. ///
  280. virtual bool done() const = 0;
  281. /// <summary>
  282. /// Retrieves a copy of the context at the current position of the
  283. /// iterator.
  284. /// </summary>
  285. ///
  286. /// <param name="pObjectContext">
  287. /// Pointer to a copy of the context at the current iterator position.
  288. /// </param>
  289. ///
  290. /// <returns>
  291. /// Returns Acad::eOk if successful and a copy of the context was returned.
  292. /// </returns>
  293. ///
  294. /// <remarks>
  295. /// Callers are responsible for deleting the returned copy of the context
  296. /// by calling delete on the returned pointer when it is no longer needed.
  297. /// </remarks>
  298. ///
  299. virtual Acad::ErrorStatus getContext(AcDbObjectContext*& pObjectContext) const = 0;
  300. };
  301. #pragma pack (pop)
  302. #endif