MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / TransferString

Method TransferString

engine/Poseidon/IO/ParamFile/ParamFileParse.cpp:70–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70void ParamFileContext::TransferString(SerializeBinStream& f, RStringB& string)
71{
72 if (f.IsSaving())
73 {
74 // check if name is already in table
75 RStringB stringB = (const char*)string;
76 int index = _strings.Find(stringB);
77 if (index >= 0)
78 {
79 // already there - transfer only index
80 TransferIndex(f, index);
81 }
82 else
83 {
84 // transfer new index and string defition
85 RStringB stringB = (const char*)string;
86 index = _strings.Add(stringB);
87 TransferIndex(f, index);
88 f.Transfer(stringB);
89 }
90 }
91 else
92 {
93 // transfer index
94 int index = -1;
95 TransferIndex(f, index);
96 if (index < 0)
97 {
98 f.SetError(f.EFileStructure);
99 return;
100 }
101 if (index < _strings.Size())
102 {
103 // old string - use it
104 string = (const char*)(_strings[index]);
105 }
106 else
107 {
108 // new string - define and use it. A new string's index must be the next
109 // sequential slot; a wire index past the end of the table is malformed and
110 // would grow _strings to index+1 (OOM) via Access(index). The assert that
111 // documented this invariant compiles out under NDEBUG (the shipping save
112 // loader), so enforce it explicitly.
113 if (index != _strings.Size())
114 {
115 f.SetError(f.EFileStructure);
116 return;
117 }
118 RStringB stringB;
119 f.Transfer(stringB);
120 _strings.Access(index);
121 _strings[index] = stringB;
122 string = (const char*)stringB;
123 }
124 }
125}
126
127void ParamFileContext::TransferInt(SerializeBinStream& f, int& a)

Callers 1

SerializeBinMethod · 0.80

Calls 7

TransferMethod · 0.80
AccessMethod · 0.80
IsSavingMethod · 0.45
FindMethod · 0.45
AddMethod · 0.45
SetErrorMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected