DataString.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include "DataString.h"
  2. #include "..\..\icommon\memfile.h"
  3. #include "..\..\..\common_h\core.h"
  4. #include "fieldlist.h"
  5. #include "..\..\TextFile.h"
  6. #ifndef _XBOX
  7. #include "..\..\..\common_h\tinyxml\tinyxml.h"
  8. #endif
  9. #include "..\..\..\Common_h\data_swizzle.h"
  10. //конструктор/деструктор
  11. DataString::DataString (FieldList* pMaster)
  12. {
  13. szName = NULL;
  14. szEditorName = NULL;
  15. Master = pMaster;
  16. }
  17. DataString::~DataString ()
  18. {
  19. }
  20. //Получить значение
  21. const char* DataString::GetValue ()
  22. {
  23. return Value.GetBuffer();
  24. }
  25. //Установить значение
  26. void DataString::SetValue (const char* val)
  27. {
  28. Value = val;
  29. if (Master) Master->UpdateCache();
  30. }
  31. void DataString::Load (MemFile* File)
  32. {
  33. static char TempString[128];
  34. File->Read(TempString, 128);
  35. SetValue(TempString);
  36. //static char AttribueName[128];
  37. dword NameLength = 0;
  38. File->ReadType(NameLength);
  39. XSwizzleDWord(NameLength);
  40. Assert (NameLength < 128);
  41. //File->Read(AttribueName, NameLength);
  42. const char* AttribueName = File->GetPointerToString(NameLength);
  43. SetName (AttribueName, "a");
  44. if (Master) Master->UpdateCache();
  45. }
  46. void DataString::SetName (const char* szName, const char* szEditorName)
  47. {
  48. //api->Trace("DataString::SetName - '%s'", szName);
  49. this->szName = szName;
  50. this->szEditorName = szEditorName;
  51. }
  52. const char* DataString::GetName ()
  53. {
  54. return szName;
  55. }
  56. void DataString::Write (MemFile* File)
  57. {
  58. static char WriteTempString[128];
  59. memset (WriteTempString, 0, 128);
  60. crt_strncpy (WriteTempString, 128, GetValue (), 127);
  61. File->Write(WriteTempString, 128);
  62. //save name
  63. DWORD NameLength = crt_strlen(szName);
  64. DWORD NameLengthPlusZero = NameLength+1;
  65. File->WriteType(NameLengthPlusZero);
  66. Assert (NameLength < 128);
  67. File->Write(szName, NameLength);
  68. File->WriteZeroByte();
  69. }
  70. const char* DataString::GetEditorName ()
  71. {
  72. return szEditorName;
  73. }
  74. #ifndef _XBOX
  75. void DataString::WriteXML (TextFile* xmlFile, dword level)
  76. {
  77. xmlFile->Write((level+1), "<Name val = \"%s\" />\n", szName);
  78. xmlFile->Write((level+1), "<Value val = \"%s\" />\n", GetValue ());
  79. }
  80. void DataString::LoadXML (TiXmlElement* root)
  81. {
  82. TiXmlElement* name = root->FirstChildElement("Name");
  83. TiXmlElement* value = root->FirstChildElement("Value");
  84. if (name)
  85. {
  86. const char* strValue = name->Attribute("val");
  87. SetName (strValue, "a");
  88. }
  89. if (value)
  90. {
  91. const char* strValue =value->Attribute("val");
  92. SetValue (strValue);
  93. }
  94. }
  95. #endif