StringTable.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #include "StdH.h"
  13. #include <Engine/Templates/StaticStackArray.h>
  14. #include <Engine/Base/CTString.h>
  15. #include <Engine/Ska/StringTable.h>
  16. #include <Engine/Templates/StaticStackArray.cpp>
  17. struct stTable
  18. {
  19. INDEX st_iID;
  20. CTString strName;
  21. };
  22. CStaticStackArray<struct stTable> _arStringTable;
  23. // add index in table
  24. INDEX AddIndexToTable(CTString strName)
  25. {
  26. _arStringTable.Push();
  27. INDEX ctStrings = _arStringTable.Count();
  28. _arStringTable[ctStrings-1].strName = strName;
  29. _arStringTable[ctStrings-1].st_iID = ctStrings;
  30. return ctStrings-1;
  31. }
  32. // find string in table and return his index, if not found add new and return his index
  33. INDEX ska_GetIDFromStringTable(CTString strName)
  34. {
  35. if(strName == "") return -1;
  36. INDEX ctStrings = _arStringTable.Count();
  37. for(INDEX i=0;i<ctStrings;i++)
  38. {
  39. if(_arStringTable[i].strName == strName)
  40. {
  41. return i;
  42. }
  43. }
  44. return AddIndexToTable(strName);
  45. }
  46. // find string in table and return his index, if not found return -1
  47. INDEX ska_FindStringInTable(CTString strName)
  48. {
  49. if(strName == "") return -1;
  50. INDEX ctStrings = _arStringTable.Count();
  51. for(INDEX i=0;i<ctStrings;i++)
  52. {
  53. if(_arStringTable[i].strName == strName)
  54. {
  55. return i;
  56. }
  57. }
  58. return -1;
  59. }
  60. // return name for index iIndex
  61. CTString ska_GetStringFromTable(INDEX iIndex)
  62. {
  63. INDEX ctStrings = _arStringTable.Count();
  64. if((iIndex >= 0) && (iIndex <= ctStrings-1))
  65. {
  66. return _arStringTable[iIndex].strName;
  67. }
  68. return "";
  69. }