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.

128 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=============================================================================
  4. #ifndef HELPERINFO_H
  5. #define HELPERINFO_H
  6. #pragma once
  7. #include <tier0/dbg.h>
  8. #include <utlvector.h>
  9. #define MAX_HELPER_NAME_LEN 256
  10. typedef CUtlVector<char *> CParameterList;
  11. //-----------------------------------------------------------------------------
  12. // Purpose:
  13. //-----------------------------------------------------------------------------
  14. class CHelperInfo
  15. {
  16. public:
  17. inline CHelperInfo(void);
  18. inline ~CHelperInfo(void);
  19. inline const char *GetName(void) const { return(m_szName); }
  20. inline void SetName(const char *pszName);
  21. inline bool AddParameter(const char *pszParameter);
  22. inline int GetParameterCount(void) const { return(m_Parameters.Count()); }
  23. inline const char *GetParameter(int nIndex) const;
  24. protected:
  25. char m_szName[MAX_HELPER_NAME_LEN];
  26. CParameterList m_Parameters;
  27. };
  28. //-----------------------------------------------------------------------------
  29. // Purpose:
  30. //-----------------------------------------------------------------------------
  31. inline CHelperInfo::CHelperInfo(void)
  32. {
  33. m_szName[0] = '\0';
  34. }
  35. //-----------------------------------------------------------------------------
  36. // Purpose:
  37. //-----------------------------------------------------------------------------
  38. inline CHelperInfo::~CHelperInfo(void)
  39. {
  40. int nCount = m_Parameters.Count();
  41. for (int i = 0; i < nCount; i++)
  42. {
  43. char *pszParam = m_Parameters.Element(i);
  44. Assert(pszParam != NULL);
  45. if (pszParam != NULL)
  46. {
  47. delete [] pszParam;
  48. }
  49. }
  50. m_Parameters.RemoveAll();
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose:
  54. // Input : char *pszParameter -
  55. // Output : Returns true on success, false on failure.
  56. //-----------------------------------------------------------------------------
  57. inline bool CHelperInfo::AddParameter(const char *pszParameter)
  58. {
  59. if ((pszParameter != NULL) && (pszParameter[0] != '\0'))
  60. {
  61. int nLen = strlen(pszParameter);
  62. if (nLen > 0)
  63. {
  64. char *pszNew = new char [nLen + 1];
  65. if (pszNew != NULL)
  66. {
  67. strcpy(pszNew, pszParameter);
  68. m_Parameters.AddToTail(pszNew);
  69. return(true);
  70. }
  71. }
  72. }
  73. return(false);
  74. }
  75. //-----------------------------------------------------------------------------
  76. //-----------------------------------------------------------------------------
  77. inline const char *CHelperInfo::GetParameter(int nIndex) const
  78. {
  79. if (nIndex >= m_Parameters.Count())
  80. return NULL;
  81. return m_Parameters.Element(nIndex);
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Purpose:
  85. // Input : char *pszName -
  86. //-----------------------------------------------------------------------------
  87. inline void CHelperInfo::SetName(const char *pszName)
  88. {
  89. if (pszName != NULL)
  90. {
  91. strcpy(m_szName, pszName);
  92. }
  93. }
  94. typedef CUtlVector<CHelperInfo *> CHelperInfoList;
  95. #endif // HELPERINFO_H