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.

171 lines
4.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include <tier0/dbg.h>
  7. #include "fgdlib/InputOutput.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include <tier0/memdbgon.h>
  10. typedef struct
  11. {
  12. InputOutputType_t eType; // The enumeration of this type.
  13. char *pszName; // The name of this type.
  14. } TypeMap_t;
  15. char *CClassInputOutputBase::g_pszEmpty = "";
  16. //-----------------------------------------------------------------------------
  17. // Maps type names to type enums for inputs and outputs.
  18. //-----------------------------------------------------------------------------
  19. static TypeMap_t TypeMap[] =
  20. {
  21. { iotVoid, "void" },
  22. { iotInt, "integer" },
  23. { iotBool, "bool" },
  24. { iotString, "string" },
  25. { iotFloat, "float" },
  26. { iotVector, "vector" },
  27. { iotEHandle, "target_destination" },
  28. { iotColor, "color255" },
  29. { iotEHandle, "ehandle" }, // for backwards compatibility
  30. };
  31. //-----------------------------------------------------------------------------
  32. // Purpose:
  33. //-----------------------------------------------------------------------------
  34. CClassInputOutputBase::CClassInputOutputBase(void)
  35. {
  36. m_eType = iotInvalid;
  37. m_pszDescription = NULL;
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Purpose:
  41. // Input : pszName -
  42. // eType -
  43. //-----------------------------------------------------------------------------
  44. CClassInputOutputBase::CClassInputOutputBase(const char *pszName, InputOutputType_t eType)
  45. {
  46. m_pszDescription = NULL;
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Purpose: Destructor.
  50. //-----------------------------------------------------------------------------
  51. CClassInputOutputBase::~CClassInputOutputBase(void)
  52. {
  53. delete m_pszDescription;
  54. m_pszDescription = NULL;
  55. }
  56. //-----------------------------------------------------------------------------
  57. // Purpose: Returns a string representing the type of this I/O, eg. "integer".
  58. //-----------------------------------------------------------------------------
  59. const char *CClassInputOutputBase::GetTypeText(void)
  60. {
  61. for (int i = 0; i < sizeof(TypeMap) / sizeof(TypeMap[0]); i++)
  62. {
  63. if (TypeMap[i].eType == m_eType)
  64. {
  65. return(TypeMap[i].pszName);
  66. }
  67. }
  68. return("unknown");
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Purpose:
  72. // Input : szType -
  73. // Output : InputOutputType_t
  74. //-----------------------------------------------------------------------------
  75. InputOutputType_t CClassInputOutputBase::SetType(const char *szType)
  76. {
  77. for (int i = 0; i < sizeof(TypeMap) / sizeof(TypeMap[0]); i++)
  78. {
  79. if (!stricmp(TypeMap[i].pszName, szType))
  80. {
  81. m_eType = TypeMap[i].eType;
  82. return(m_eType);
  83. }
  84. }
  85. return(iotInvalid);
  86. }
  87. //-----------------------------------------------------------------------------
  88. // Purpose: Assignment operator.
  89. //-----------------------------------------------------------------------------
  90. CClassInputOutputBase &CClassInputOutputBase::operator =(CClassInputOutputBase &Other)
  91. {
  92. strcpy(m_szName, Other.m_szName);
  93. m_eType = Other.m_eType;
  94. //
  95. // Copy the description.
  96. //
  97. delete m_pszDescription;
  98. if (Other.m_pszDescription != NULL)
  99. {
  100. m_pszDescription = new char[strlen(Other.m_pszDescription) + 1];
  101. strcpy(m_pszDescription, Other.m_pszDescription);
  102. }
  103. else
  104. {
  105. m_pszDescription = NULL;
  106. }
  107. return(*this);
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Purpose:
  111. //-----------------------------------------------------------------------------
  112. CClassInput::CClassInput(void)
  113. {
  114. }
  115. //-----------------------------------------------------------------------------
  116. // Purpose:
  117. // Input : pszName -
  118. // eType -
  119. //-----------------------------------------------------------------------------
  120. CClassInput::CClassInput(const char *pszName, InputOutputType_t eType)
  121. : CClassInputOutputBase(pszName, eType)
  122. {
  123. }
  124. //-----------------------------------------------------------------------------
  125. // Purpose:
  126. //-----------------------------------------------------------------------------
  127. CClassOutput::CClassOutput(void)
  128. {
  129. }
  130. //-----------------------------------------------------------------------------
  131. // Purpose:
  132. // Input : pszName -
  133. // eType -
  134. //-----------------------------------------------------------------------------
  135. CClassOutput::CClassOutput(const char *pszName, InputOutputType_t eType)
  136. : CClassInputOutputBase(pszName, eType)
  137. {
  138. }