Skip to content

Commit 6275410

Browse files
committed
buffers should be lists
1 parent 13ce4da commit 6275410

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

export/include/fmu4cpp/fmu_base.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ namespace fmu4cpp {
226226
std::unordered_map<unsigned int, size_t> vrToBooleanIndices_;
227227

228228
std::vector<StringVariable> strings_;
229-
std::string stringBuffer_;
229+
std::vector<std::string> stringBuffer_;
230230
std::unordered_map<unsigned int, size_t> vrToStringIndices_;
231231

232232
std::vector<BinaryVariable> binary_;
233-
std::vector<uint8_t> binaryBuffer_;
233+
std::vector<std::vector<uint8_t>> binaryBuffer_;
234234
std::unordered_map<unsigned int, size_t> vrToBinaryIndices_;
235235

236236
std::function<void *(void *)> get_state_ptr_{nullptr};

export/src/fmu4cpp/fmu_base.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,24 @@ void fmu_base::get_boolean(const unsigned int vr[], size_t nvr, bool value[]) co
132132
}
133133

134134
void fmu_base::get_string(const unsigned int vr[], size_t nvr, const char *value[]) {
135+
stringBuffer_.clear();
135136
for (unsigned i = 0; i < nvr; i++) {
136137
const auto ref = vr[i];
137138
const auto idx = vrToStringIndices_.at(ref);
138-
stringBuffer_ = strings_[idx].get();
139-
value[i] = stringBuffer_.c_str();
139+
stringBuffer_.emplace_back(strings_[idx].get());
140+
value[i] = stringBuffer_.back().c_str();
140141
}
141142
}
142143

143144
void fmu_base::get_binary(const unsigned int vr[], size_t nvr, size_t valueSizes[], const uint8_t *values[]) {
144-
145+
binaryBuffer_.clear();
145146
for (auto i = 0; i < nvr; i++) {
146147
const auto ref = vr[i];
147148
const auto idx = vrToBinaryIndices_.at(ref);
148149
const auto &data = binary_[idx].get();
149150
valueSizes[i] = data.size();
150-
binaryBuffer_.assign(data.begin(), data.end());
151-
values[i] = binaryBuffer_.data();
151+
binaryBuffer_.emplace_back(data.begin(), data.end());
152+
values[i] = binaryBuffer_.back().data();
152153
}
153154
}
154155

0 commit comments

Comments
 (0)