Team Fortress 2 Source Code as on 22/4/2020
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.

100 lines
3.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "datamodel/dmelementfactoryhelper.h"
  7. #include "tier0/dbg.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. CDmElementFactoryHelper *CDmElementFactoryHelper::s_pHelpers[2] = { NULL, NULL };
  11. //-----------------------------------------------------------------------------
  12. // Constructor
  13. //-----------------------------------------------------------------------------
  14. CDmElementFactoryHelper::CDmElementFactoryHelper( const char *classname, IDmElementFactoryInternal *pFactory, bool bIsStandardFactory )
  15. {
  16. m_pNext = s_pHelpers[bIsStandardFactory];
  17. s_pHelpers[bIsStandardFactory] = this;
  18. // Set attributes
  19. Assert( pFactory );
  20. m_pFactory = pFactory;
  21. Assert( classname );
  22. m_pszClassname = classname;
  23. }
  24. //-----------------------------------------------------------------------------
  25. // Purpose: Returns next object in list
  26. // Output : CDmElementFactoryHelper
  27. //-----------------------------------------------------------------------------
  28. CDmElementFactoryHelper *CDmElementFactoryHelper::GetNext( void )
  29. {
  30. return m_pNext;
  31. }
  32. //-----------------------------------------------------------------------------
  33. // Installs all factories into the datamodel system
  34. //-----------------------------------------------------------------------------
  35. // NOTE: The name of this extern is defined by the macro IMPLEMENT_ELEMENT_FACTORY
  36. extern CDmElementFactoryHelper g_CDmElement_Helper;
  37. void CDmElementFactoryHelper::InstallFactories( )
  38. {
  39. // Just set up the type symbols of the other factories
  40. CDmElementFactoryHelper *p = s_pHelpers[0];
  41. while ( p )
  42. {
  43. // Add factories to database
  44. if ( !p->GetFactory()->IsAbstract() )
  45. {
  46. g_pDataModel->AddElementFactory( p->GetClassname(), p->GetFactory() );
  47. }
  48. // Set up the type symbol. Note this can't be done at
  49. // constructor time since we don't have a DataModel pointer then
  50. p->GetFactory()->SetElementTypeSymbol( g_pDataModel->GetSymbol( p->GetClassname() ) );
  51. p = p->GetNext();
  52. }
  53. p = s_pHelpers[1];
  54. while ( p )
  55. {
  56. // Add factories to database, but not if they've been overridden
  57. if ( !g_pDataModel->HasElementFactory( p->GetClassname() ) )
  58. {
  59. if ( !p->GetFactory()->IsAbstract() )
  60. {
  61. g_pDataModel->AddElementFactory( p->GetClassname(), p->GetFactory() );
  62. }
  63. // Set up the type symbol. Note this can't be done at
  64. // constructor time since we don't have a DataModel pointer then
  65. // Backward compat--don't let the type symbol be 'DmeElement'
  66. if ( Q_stricmp( p->GetClassname(), "DmeElement" ) )
  67. {
  68. p->GetFactory()->SetElementTypeSymbol( g_pDataModel->GetSymbol( p->GetClassname() ) );
  69. }
  70. }
  71. p = p->GetNext();
  72. }
  73. // Also install the DmElement factory as the default factory
  74. g_pDataModel->SetDefaultElementFactory( g_CDmElement_Helper.GetFactory() );
  75. }
  76. //-----------------------------------------------------------------------------
  77. // Installs all DmElement factories
  78. //-----------------------------------------------------------------------------
  79. void InstallDmElementFactories( )
  80. {
  81. CDmElementFactoryHelper::InstallFactories( );
  82. }