AcApDMgr.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #pragma once
  13. //-----------------------------------------------------------------------------
  14. //----- Defines
  15. //----- #pragma warning(disable: 4786)
  16. //----- in your precompiled header to get rid of this warning
  17. //-----------------------------------------------------------------------------
  18. #include "acdocman.h"
  19. #include <map>
  20. //-----------------------------------------------------------------------------
  21. template <class T> class AcApDataManager : public AcApDocManagerReactor {
  22. public:
  23. AcApDataManager () {
  24. acDocManager->addReactor (this) ;
  25. }
  26. ~AcApDataManager () {
  27. if ( acDocManager != NULL )
  28. acDocManager->removeReactor (this) ;
  29. }
  30. virtual void documentToBeDestroyed (AcApDocument *pDoc) {
  31. m_dataMap.erase (pDoc) ;
  32. }
  33. T &docData (AcApDocument *pDoc) {
  34. if ( m_dataMap.find(pDoc) == m_dataMap.end () )
  35. return (m_dataMap[pDoc]) ;
  36. return ((*(m_dataMap.find(pDoc))).second) ;
  37. }
  38. T &docData () {
  39. return (docData (acDocManager->curDocument ())) ;
  40. }
  41. private:
  42. std::map<AcApDocument *, T> m_dataMap ;
  43. } ;