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.

170 lines
4.5 KiB

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