Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

536 lines
22 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef DATAMODEL_H
  7. #define DATAMODEL_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "datamodel/dmattribute.h"
  12. #include "datamodel/idatamodel.h"
  13. #include "datamodel/dmelement.h"
  14. #include "datamodel/dmehandle.h"
  15. #include "tier1/uniqueid.h"
  16. #include "tier1/utlsymbol.h"
  17. #include "tier1/utllinkedlist.h"
  18. #include "tier1/utldict.h"
  19. #include "tier1/utlstring.h"
  20. #include "tier1/utlhandletable.h"
  21. #include "tier1/utlhash.h"
  22. #include "tier2/tier2.h"
  23. #include "clipboardmanager.h"
  24. #include "undomanager.h"
  25. #include "tier1/convar.h"
  26. #include "tier0/vprof.h"
  27. //-----------------------------------------------------------------------------
  28. // forward declarations
  29. //-----------------------------------------------------------------------------
  30. class IDmElementFramework;
  31. class IUndoElement;
  32. class CDmElement;
  33. enum DmHandleReleasePolicy
  34. {
  35. HR_ALWAYS,
  36. HR_NEVER,
  37. HR_IF_NOT_REFERENCED,
  38. };
  39. //-----------------------------------------------------------------------------
  40. // memory categories
  41. //-----------------------------------------------------------------------------
  42. enum
  43. {
  44. MEMORY_CATEGORY_OUTER,
  45. MEMORY_CATEGORY_ELEMENT_INTERNAL,
  46. MEMORY_CATEGORY_DATAMODEL,
  47. MEMORY_CATEGORY_REFERENCES,
  48. MEMORY_CATEGORY_ATTRIBUTE_TREE,
  49. MEMORY_CATEGORY_ATTRIBUTE_OVERHEAD,
  50. MEMORY_CATEGORY_ATTRIBUTE_DATA,
  51. MEMORY_CATEGORY_ATTRIBUTE_COUNT,
  52. MEMORY_CATEGORY_COUNT,
  53. };
  54. //-----------------------------------------------------------------------------
  55. // hash map of id->element, with the id storage optimized out
  56. //-----------------------------------------------------------------------------
  57. class CElementIdHash : public CUtlHash< DmElementHandle_t >
  58. {
  59. public:
  60. CElementIdHash( int nBucketCount = 0, int nGrowCount = 0, int nInitCount = 0 )
  61. : CUtlHash< DmElementHandle_t >( nBucketCount, nGrowCount, nInitCount, CompareFunc, KeyFunc )
  62. {
  63. }
  64. protected:
  65. typedef CUtlHash< DmElementHandle_t > BaseClass;
  66. static bool CompareFunc( DmElementHandle_t const& a, DmElementHandle_t const& b ) { return a == b; }
  67. static bool IdCompareFunc( DmElementHandle_t const& hElement, DmObjectId_t const& id )
  68. {
  69. CDmElement *pElement = g_pDataModel->GetElement( hElement );
  70. Assert( pElement );
  71. if ( !pElement )
  72. return false;
  73. return IsUniqueIdEqual( id, pElement->GetId() );
  74. }
  75. static unsigned int KeyFunc( DmElementHandle_t const& hElement )
  76. {
  77. CDmElement *pElement = g_pDataModel->GetElement( hElement );
  78. Assert( pElement );
  79. if ( !pElement )
  80. return 0;
  81. return *( unsigned int* )&pElement->GetId();
  82. }
  83. static unsigned int IdKeyFunc( DmObjectId_t const &src )
  84. {
  85. return *(unsigned int*)&src;
  86. }
  87. protected:
  88. bool DoFind( DmObjectId_t const &src, unsigned int *pBucket, int *pIndex )
  89. {
  90. // generate the data "key"
  91. unsigned int key = IdKeyFunc( src );
  92. // hash the "key" - get the correct hash table "bucket"
  93. unsigned int ndxBucket;
  94. if( m_bPowerOfTwo )
  95. {
  96. *pBucket = ndxBucket = ( key & m_ModMask );
  97. }
  98. else
  99. {
  100. int bucketCount = m_Buckets.Count();
  101. *pBucket = ndxBucket = key % bucketCount;
  102. }
  103. int ndxKeyData;
  104. CUtlVector< DmElementHandle_t > &bucket = m_Buckets[ndxBucket];
  105. int keyDataCount = bucket.Count();
  106. for( ndxKeyData = 0; ndxKeyData < keyDataCount; ndxKeyData++ )
  107. {
  108. if( IdCompareFunc( bucket.Element( ndxKeyData ), src ) )
  109. break;
  110. }
  111. if( ndxKeyData == keyDataCount )
  112. return false;
  113. *pIndex = ndxKeyData;
  114. return true;
  115. }
  116. public:
  117. UtlHashHandle_t Find( DmElementHandle_t const &src ) { return BaseClass::Find( src ); }
  118. UtlHashHandle_t Find( DmObjectId_t const &src )
  119. {
  120. unsigned int ndxBucket;
  121. int ndxKeyData;
  122. if ( DoFind( src, &ndxBucket, &ndxKeyData ) )
  123. return BuildHandle( ndxBucket, ndxKeyData );
  124. return InvalidHandle();
  125. }
  126. };
  127. //-----------------------------------------------------------------------------
  128. // struct to hold the set of elements in any given file
  129. //-----------------------------------------------------------------------------
  130. struct FileElementSet_t
  131. {
  132. FileElementSet_t( CUtlSymbolLarge filename = UTL_INVAL_SYMBOL_LARGE, CUtlSymbolLarge format = UTL_INVAL_SYMBOL_LARGE ) :
  133. m_filename( filename ), m_format( format ),
  134. m_hRoot( DMELEMENT_HANDLE_INVALID ),
  135. m_bLoaded( true ),
  136. m_nElements( 0 ),
  137. m_fileModificationTime( 0 )
  138. {
  139. }
  140. FileElementSet_t( const FileElementSet_t& that ) : m_filename( that.m_filename ), m_format( that.m_format ), m_hRoot( DMELEMENT_HANDLE_INVALID ), m_bLoaded( that.m_bLoaded ), m_nElements( that.m_nElements )
  141. {
  142. // the only time this should be copy constructed is when passing in an empty set to the parent array
  143. // otherwise it could get prohibitively expensive time and memory wise
  144. Assert( that.m_nElements == 0 );
  145. }
  146. CUtlSymbolLarge m_filename;
  147. CUtlSymbolLarge m_format;
  148. CDmeCountedHandle m_hRoot;
  149. bool m_bLoaded;
  150. int m_nElements;
  151. long m_fileModificationTime;
  152. };
  153. //-----------------------------------------------------------------------------
  154. // Purpose: Versionable factor for element types
  155. //-----------------------------------------------------------------------------
  156. class CDataModel : public CBaseAppSystem< IDataModel >
  157. {
  158. typedef CBaseAppSystem< IDataModel > BaseClass;
  159. public:
  160. CDataModel();
  161. virtual ~CDataModel();
  162. // External interface
  163. public:
  164. // Methods of IAppSystem
  165. virtual bool Connect( CreateInterfaceFn factory );
  166. virtual void *QueryInterface( const char *pInterfaceName );
  167. virtual InitReturnVal_t Init();
  168. virtual void Shutdown();
  169. // Methods of IDataModel
  170. virtual void AddElementFactory( CDmElementFactoryHelper *pFactoryHelper );
  171. virtual CDmElementFactoryHelper *GetElementFactoryHelper( const char *pClassName );
  172. virtual bool HasElementFactory( const char *pElementType ) const;
  173. virtual void SetDefaultElementFactory( IDmElementFactory *pFactory );
  174. virtual int GetFirstFactory() const;
  175. virtual int GetNextFactory( int index ) const;
  176. virtual bool IsValidFactory( int index ) const;
  177. virtual char const *GetFactoryName( int index ) const;
  178. virtual DmElementHandle_t CreateElement( CUtlSymbolLarge typeSymbol, const char *pElementName, DmFileId_t fileid, const DmObjectId_t *pObjectID = NULL );
  179. virtual DmElementHandle_t CreateElement( const char *pTypeName, const char *pElementName, DmFileId_t fileid, const DmObjectId_t *pObjectID = NULL );
  180. virtual void DestroyElement( DmElementHandle_t hElement );
  181. virtual CDmElement* GetElement( DmElementHandle_t hElement ) const;
  182. virtual CUtlSymbolLarge GetElementType( DmElementHandle_t hElement ) const;
  183. virtual const char* GetElementName( DmElementHandle_t hElement ) const;
  184. virtual const DmObjectId_t& GetElementId( DmElementHandle_t hElement ) const;
  185. virtual const char *GetAttributeNameForType( DmAttributeType_t attType ) const;
  186. virtual DmAttributeType_t GetAttributeTypeForName( const char *name ) const;
  187. virtual void AddSerializer( IDmSerializer *pSerializer );
  188. virtual void AddLegacyUpdater( IDmLegacyUpdater *pUpdater );
  189. virtual void AddFormatUpdater( IDmFormatUpdater *pUpdater );
  190. virtual const char* GetFormatExtension( const char *pFormatName );
  191. virtual const char* GetFormatDescription( const char *pFormatName );
  192. virtual int GetFormatCount() const;
  193. virtual const char * GetFormatName( int i ) const;
  194. virtual const char * GetDefaultEncoding( const char *pFormatName );
  195. virtual int GetEncodingCount() const;
  196. virtual const char * GetEncodingName( int i ) const;
  197. virtual bool IsEncodingBinary( const char *pEncodingName ) const;
  198. virtual bool DoesEncodingStoreVersionInFile( const char *pEncodingName ) const;
  199. virtual void SetSerializationDelimiter( CUtlCharConversion *pConv );
  200. virtual void SetSerializationArrayDelimiter( const char *pDelimiter );
  201. virtual bool IsUnserializing();
  202. virtual bool Serialize( CUtlBuffer &outBuf, const char *pEncodingName, const char *pFormatName, DmElementHandle_t hRoot );
  203. virtual bool Unserialize( CUtlBuffer &buf, const char *pEncodingName, const char *pSourceFormatName, const char *pFormatHint,
  204. const char *pFileName, DmConflictResolution_t idConflictResolution, DmElementHandle_t &hRoot );
  205. virtual bool UpdateUnserializedElements( const char *pSourceFormatName, int nSourceFormatVersion,
  206. DmFileId_t fileid, DmConflictResolution_t idConflictResolution, CDmElement **ppRoot );
  207. virtual IDmSerializer* FindSerializer( const char *pEncodingName ) const;
  208. virtual IDmLegacyUpdater* FindLegacyUpdater( const char *pLegacyFormatName ) const;
  209. virtual IDmFormatUpdater* FindFormatUpdater( const char *pFormatName ) const;
  210. virtual bool SaveToFile( char const *pFileName, char const *pPathID, const char *pEncodingName, const char *pFormatName, CDmElement *pRoot );
  211. virtual DmFileId_t RestoreFromFile( char const *pFileName, char const *pPathID, const char *pFormatHint, CDmElement **ppRoot, DmConflictResolution_t idConflictResolution = CR_DELETE_NEW, DmxHeader_t *pHeaderOut = NULL );
  212. virtual bool IsDMXFormat( CUtlBuffer &buf ) const;
  213. virtual void SetKeyValuesElementCallback( IElementForKeyValueCallback *pCallbackInterface );
  214. virtual const char * GetKeyValuesElementName( const char *pszKeyName, int iNestingLevel );
  215. virtual CUtlSymbolLarge GetSymbol( const char *pString );
  216. virtual int GetElementsAllocatedSoFar();
  217. virtual int GetMaxNumberOfElements();
  218. virtual int GetAllocatedAttributeCount();
  219. virtual int GetAllocatedElementCount();
  220. virtual DmElementHandle_t FirstAllocatedElement();
  221. virtual DmElementHandle_t NextAllocatedElement( DmElementHandle_t hElement );
  222. virtual int EstimateMemoryUsage( DmElementHandle_t hElement, TraversalDepth_t depth = TD_DEEP );
  223. virtual void SetUndoEnabled( bool enable );
  224. virtual bool IsUndoEnabled() const;
  225. virtual bool UndoEnabledForElement( const CDmElement *pElement ) const;
  226. virtual bool IsDirty() const;
  227. virtual bool CanUndo() const;
  228. virtual bool CanRedo() const;
  229. virtual void StartUndo( const char *undodesc, const char *redodesc, int nChainingID = 0 );
  230. virtual void FinishUndo();
  231. virtual void AbortUndoableOperation();
  232. virtual void ClearRedo();
  233. virtual const char *GetUndoDesc();
  234. virtual const char *GetRedoDesc();
  235. virtual void Undo();
  236. virtual void Redo();
  237. virtual void TraceUndo( bool state ); // if true, undo records spew as they are added
  238. virtual void ClearUndo();
  239. virtual void GetUndoInfo( CUtlVector< UndoInfo_t >& list );
  240. virtual const char * GetUndoString( CUtlSymbolLarge sym );
  241. virtual void AddUndoElement( IUndoElement *pElement );
  242. virtual CUtlSymbolLarge GetUndoDescInternal( const char *context );
  243. virtual CUtlSymbolLarge GetRedoDescInternal( const char *context );
  244. virtual void EmptyClipboard();
  245. virtual void SetClipboardData( CUtlVector< KeyValues * >& data, IClipboardCleanup *pfnOptionalCleanuFunction = 0 );
  246. virtual void AddToClipboardData( KeyValues *add );
  247. virtual void GetClipboardData( CUtlVector< KeyValues * >& data );
  248. virtual bool HasClipboardData() const;
  249. virtual CDmAttribute * GetAttribute( DmAttributeHandle_t h );
  250. virtual bool IsAttributeHandleValid( DmAttributeHandle_t h ) const;
  251. virtual void OnlyCreateUntypedElements( bool bEnable );
  252. virtual int NumFileIds();
  253. virtual DmFileId_t GetFileId( int i );
  254. virtual DmFileId_t FindOrCreateFileId( const char *pFilename );
  255. virtual void RemoveFileId( DmFileId_t fileid );
  256. virtual DmFileId_t GetFileId( const char *pFilename );
  257. virtual const char * GetFileName( DmFileId_t fileid );
  258. virtual void SetFileName( DmFileId_t fileid, const char *pFileName );
  259. virtual const char * GetFileFormat( DmFileId_t fileid );
  260. virtual void SetFileFormat( DmFileId_t fileid, const char *pFormat );
  261. virtual DmElementHandle_t GetFileRoot( DmFileId_t fileid );
  262. virtual void SetFileRoot( DmFileId_t fileid, DmElementHandle_t hRoot );
  263. virtual long GetFileModificationUTCTime( DmFileId_t fileid );
  264. virtual long GetCurrentUTCTime();
  265. virtual void UTCTimeToString( char *pString, int maxChars, long fileTime );
  266. virtual bool IsFileLoaded( DmFileId_t fileid );
  267. virtual void MarkFileLoaded( DmFileId_t fileid );
  268. virtual void UnloadFile( DmFileId_t fileid );
  269. virtual int NumElementsInFile( DmFileId_t fileid );
  270. virtual void DontAutoDelete( DmElementHandle_t hElement );
  271. virtual void MarkHandleInvalid( DmElementHandle_t hElement );
  272. virtual void MarkHandleValid( DmElementHandle_t hElement );
  273. virtual DmElementHandle_t FindElement( const DmObjectId_t &id );
  274. virtual void GetExistingElements( CElementIdHash &hash ) const;
  275. virtual DmAttributeReferenceIterator_t FirstAttributeReferencingElement( DmElementHandle_t hElement );
  276. virtual DmAttributeReferenceIterator_t NextAttributeReferencingElement( DmAttributeReferenceIterator_t hAttrIter );
  277. virtual CDmAttribute * GetAttribute( DmAttributeReferenceIterator_t hAttrIter );
  278. virtual bool InstallNotificationCallback( IDmNotify *pNotify );
  279. virtual void RemoveNotificationCallback( IDmNotify *pNotify );
  280. virtual bool IsSuppressingNotify( ) const;
  281. virtual void SetSuppressingNotify( bool bSuppress );
  282. virtual void PushNotificationScope( const char *pReason, int nNotifySource, int nNotifyFlags );
  283. virtual void PopNotificationScope( bool bAbort );
  284. virtual void SetUndoDepth( int nSize );
  285. virtual void DisplayMemoryStats(DmElementHandle_t hElement = DMELEMENT_HANDLE_INVALID);
  286. // Dump the symbol table to the console
  287. virtual void DumpSymbolTable();
  288. virtual void AddOnElementCreatedCallback( const char* pElementType, IDmeElementCreated *callback );
  289. virtual void RemoveOnElementCreatedCallback( const char* pElementType, IDmeElementCreated *callback );
  290. public:
  291. // Commits symbols in symbol table
  292. void CommitSymbols();
  293. // Internal public methods
  294. int GetCurrentFormatVersion( const char *pFormatName );
  295. // CreateElement references the attribute list passed in via ref, so don't edit or purge ref's attribute list afterwards
  296. CDmElement* CreateElement( const DmElementReference_t &ref, const char *pElementType, const char *pElementName, DmFileId_t fileid, const DmObjectId_t *pObjectID );
  297. void DeleteElement( DmElementHandle_t hElement, DmHandleReleasePolicy hrp = HR_ALWAYS );
  298. // element handle related methods
  299. DmElementHandle_t AcquireElementHandle();
  300. void ReleaseElementHandle( DmElementHandle_t hElement );
  301. // Handles to attributes
  302. DmAttributeHandle_t AcquireAttributeHandle( CDmAttribute *pAttribute );
  303. void ReleaseAttributeHandle( DmAttributeHandle_t hAttribute );
  304. // remove orphaned element subtrees
  305. void FindAndDeleteOrphanedElements();
  306. void GetInvalidHandles( CUtlVector< DmElementHandle_t > &handles );
  307. void MarkHandlesValid( CUtlVector< DmElementHandle_t > &handles );
  308. void MarkHandlesInvalid( CUtlVector< DmElementHandle_t > &handles );
  309. // search id->handle table (both loaded and unloaded) for id, and if not found, create a new handle, map it to the id and return it
  310. DmElementHandle_t FindOrCreateElementHandle( const DmObjectId_t &id );
  311. // changes an element's id and associated mappings - generally during unserialization
  312. DmElementHandle_t ChangeElementId( DmElementHandle_t hElement, const DmObjectId_t &oldId, const DmObjectId_t &newId );
  313. DmElementReference_t *FindElementReference( DmElementHandle_t hElement, DmObjectId_t **ppId = NULL );
  314. void RemoveUnreferencedElements();
  315. void RemoveElementFromFile( DmElementHandle_t hElement, DmFileId_t fileid );
  316. void AddElementToFile( DmElementHandle_t hElement, DmFileId_t fileid );
  317. void NotifyState( int nNotifyFlags );
  318. int EstimateMemoryOverhead() const;
  319. bool IsCreatingUntypedElements() const { return m_bOnlyCreateUntypedElements; }
  320. void UpdateReferenceToElements( CDmAttribute *pAttr, CDmElement *pChild, bool bDetach );
  321. void UpdateReferencesToElements( CDmElement *pElement, bool bDetach );
  322. private:
  323. struct MailingList_t
  324. {
  325. CUtlVector<DmElementHandle_t> m_Elements;
  326. };
  327. struct ElementIdHandlePair_t
  328. {
  329. DmObjectId_t m_id;
  330. DmElementReference_t m_ref;
  331. ElementIdHandlePair_t() {}
  332. explicit ElementIdHandlePair_t( const DmObjectId_t &id ) : m_ref()
  333. {
  334. CopyUniqueId( id, &m_id );
  335. }
  336. ElementIdHandlePair_t( const DmObjectId_t &id, const DmElementReference_t &ref ) : m_ref( ref )
  337. {
  338. CopyUniqueId( id, &m_id );
  339. }
  340. ElementIdHandlePair_t( const ElementIdHandlePair_t& that ) : m_ref( that.m_ref )
  341. {
  342. CopyUniqueId( that.m_id, &m_id );
  343. }
  344. ElementIdHandlePair_t &operator=( const ElementIdHandlePair_t &that )
  345. {
  346. CopyUniqueId( that.m_id, &m_id );
  347. m_ref = that.m_ref;
  348. return *this;
  349. }
  350. static unsigned int HashKey( const ElementIdHandlePair_t& that )
  351. {
  352. return *( unsigned int* )&that.m_id.m_Value;
  353. }
  354. static bool Compare( const ElementIdHandlePair_t& a, const ElementIdHandlePair_t& b )
  355. {
  356. return IsUniqueIdEqual( a.m_id, b.m_id );
  357. }
  358. };
  359. private:
  360. CDmElement *Unserialize( CUtlBuffer& buf );
  361. void Serialize( CDmElement *element, CUtlBuffer& buf );
  362. // Read the header, return the version (or false if it's not a DMX file)
  363. bool ReadDMXHeader( CUtlBuffer &inBuf, DmxHeader_t *pHeader ) const;
  364. const char *GetEncodingFromLegacyFormat( const char *pLegacyFormatName ) const;
  365. bool IsValidNonDMXFormat( const char *pFormatName ) const;
  366. bool IsLegacyFormat( const char *pFormatName ) const;
  367. // Returns the current undo manager
  368. CUndoManager* GetUndoMgr();
  369. const CUndoManager* GetUndoMgr() const;
  370. CClipboardManager *GetClipboardMgr();
  371. const CClipboardManager *GetClipboardMgr() const;
  372. void UnloadFile( DmFileId_t fileid, bool bDeleteElements );
  373. void SetFileModificationUTCTime( DmFileId_t fileid, long fileModificationTime );
  374. friend class CDmeElementRefHelper;
  375. friend class CDmAttribute;
  376. template< class T > friend class CDmArrayAttributeOp;
  377. void OnElementReferenceAdded ( DmElementHandle_t hElement, CDmAttribute *pAttribute );
  378. void OnElementReferenceRemoved( DmElementHandle_t hElement, CDmAttribute *pAttribute );
  379. void OnElementReferenceAdded ( DmElementHandle_t hElement, HandleType_t handleType );
  380. void OnElementReferenceRemoved( DmElementHandle_t hElement, HandleType_t handleType );
  381. void BuildHistogramForHandles( CUtlMap< CUtlSymbolLarge, struct DmMemoryInfo_t > &typeHistogram, CUtlVector< DmElementHandle_t > &handles );
  382. private:
  383. CUtlVector< IDmSerializer* > m_Serializers;
  384. CUtlVector< IDmLegacyUpdater* > m_LegacyUpdaters;
  385. CUtlVector< IDmFormatUpdater* > m_FormatUpdaters;
  386. IDmElementFactory *m_pDefaultFactory;
  387. CUtlDict< CDmElementFactoryHelper*, int > m_Factories;
  388. CUtlSymbolTableLargeMT m_SymbolTable;
  389. CUtlHandleTable< CDmElement, 21 > m_Handles;
  390. CUtlHandleTable< CDmAttribute, 21 > m_AttributeHandles;
  391. CUndoManager m_UndoMgr;
  392. bool m_bIsUnserializing : 1;
  393. bool m_bUnableToSetDefaultFactory : 1;
  394. bool m_bOnlyCreateUntypedElements : 1;
  395. bool m_bUnableToCreateOnlyUntypedElements : 1;
  396. bool m_bDeleteOrphanedElements : 1;
  397. CUtlHandleTable< FileElementSet_t, 20 > m_openFiles;
  398. CElementIdHash m_elementIds;
  399. CUtlHash< ElementIdHandlePair_t > m_unloadedIdElementMap;
  400. CClipboardManager m_ClipboardMgr;
  401. IElementForKeyValueCallback *m_pKeyvaluesCallbackInterface;
  402. int m_nElementsAllocatedSoFar;
  403. int m_nMaxNumberOfElements;
  404. };
  405. //-----------------------------------------------------------------------------
  406. // Singleton
  407. //-----------------------------------------------------------------------------
  408. extern CDataModel *g_pDataModelImp;
  409. //-----------------------------------------------------------------------------
  410. // Inline methods
  411. //-----------------------------------------------------------------------------
  412. inline CUndoManager* CDataModel::GetUndoMgr()
  413. {
  414. return &m_UndoMgr;
  415. }
  416. inline const CUndoManager* CDataModel::GetUndoMgr() const
  417. {
  418. return &m_UndoMgr;
  419. }
  420. inline void CDataModel::NotifyState( int nNotifyFlags )
  421. {
  422. GetUndoMgr()->NotifyState( nNotifyFlags );
  423. }
  424. inline CClipboardManager *CDataModel::GetClipboardMgr()
  425. {
  426. return &m_ClipboardMgr;
  427. }
  428. inline const CClipboardManager *CDataModel::GetClipboardMgr() const
  429. {
  430. return &m_ClipboardMgr;
  431. }
  432. //-----------------------------------------------------------------------------
  433. // Methods of DmElement which are public to datamodel
  434. //-----------------------------------------------------------------------------
  435. class CDmeElementAccessor
  436. {
  437. public:
  438. static void Purge( CDmElement *pElement ) { pElement->Purge(); }
  439. static void SetId( CDmElement *pElement, const DmObjectId_t &id ) { pElement->SetId( id ); }
  440. static bool IsDirty( const CDmElement *pElement ) { return pElement->IsDirty(); }
  441. static void MarkDirty( CDmElement *pElement, bool dirty = true ) { pElement->MarkDirty( dirty ); }
  442. static void MarkAttributesClean( CDmElement *pElement ) { pElement->MarkAttributesClean(); }
  443. static void DisableOnChangedCallbacks( CDmElement *pElement ) { pElement->DisableOnChangedCallbacks(); }
  444. static void EnableOnChangedCallbacks( CDmElement *pElement ) { pElement->EnableOnChangedCallbacks(); }
  445. static bool AreOnChangedCallbacksEnabled( CDmElement *pElement ) { return pElement->AreOnChangedCallbacksEnabled(); }
  446. static void FinishUnserialization( CDmElement *pElement ) { pElement->FinishUnserialization(); }
  447. static void AddAttributeByPtr( CDmElement *pElement, CDmAttribute *ptr ) { pElement->AddAttributeByPtr( ptr ); }
  448. static void RemoveAttributeByPtrNoDelete( CDmElement *pElement, CDmAttribute *ptr ) { pElement->RemoveAttributeByPtrNoDelete( ptr); }
  449. static void ChangeHandle( CDmElement *pElement, DmElementHandle_t handle ) { pElement->ChangeHandle( handle ); }
  450. static DmElementReference_t *GetReference( CDmElement *pElement ) { return pElement->GetReference(); }
  451. static void SetReference( CDmElement *pElement, const DmElementReference_t &ref ) { pElement->SetReference( ref ); }
  452. static int EstimateMemoryUsage( CDmElement *pElement, CUtlHash< DmElementHandle_t > &visited, TraversalDepth_t depth, int *pCategories ) { return pElement->EstimateMemoryUsage( visited, depth, pCategories ); }
  453. static void PerformConstruction( CDmElement *pElement ) { pElement->PerformConstruction(); }
  454. static void PerformDestruction( CDmElement *pElement ) { pElement->PerformDestruction(); }
  455. static void OnAdoptedFromUndo( CDmElement *pElement ) { pElement->OnAdoptedFromUndo(); }
  456. static void OnOrphanedToUndo( CDmElement *pElement ) { pElement->OnOrphanedToUndo(); }
  457. };
  458. #endif // DATAMODEL_H