Add support for DBArray to parsing framework
MODIFY
src/lcf/reader_xml.h
src/lcf/reader_xml.h
#define LCF_READER_XML_H
#include "lcf/config.h"
+#include "lcf/dbarray.h"
#include <string>
#include <vector>
@@ -80,6 +81,12 @@ public:
template <class T>
static void ReadVector(std::vector<T>& ref, const std::string& data);
+ /**
+ * Parses a vector of primitive type.
+ */
+ template <class T>
+ static void ReadVector(DBArray<T>& ref, const std::string& data);
+
/**
* Start element callback.
*/

MODIFY
src/lcf/writer_xml.h
src/lcf/writer_xml.h
#include <cstdio>
#include <stdint.h>
#include "lcf/string_view.h"
+#include "lcf/span.h"
namespace lcf {
@@ -120,8 +121,8 @@ protected:
*
* @param val vector to write.
*/
- template <class T>
- void WriteVector(const std::vector<T>& val);
+ template <class ArrayType>
+ void WriteVector(const ArrayType& val);
void WriteString(StringView s);
};

MODIFY
src/ldb_eventcommand.cpp
src/ldb_eventcommand.cpp
@@ -48,8 +48,7 @@ void RawStruct<rpg::EventCommand>::ReadLcf(rpg::EventCommand& event_command, Lcf
param_buf.push_back(stream.ReadInt());
}
if (!param_buf.empty()) {
- event_command.parameters.reserve(param_buf.size());
- event_command.parameters.assign(param_buf.begin(), param_buf.end());
+ event_command.parameters = DBArray<int32_t>(param_buf.begin(), param_buf.end());
}
}
}

MODIFY
src/reader_xml.cpp
src/reader_xml.cpp
@@ -205,6 +205,14 @@ void XmlReader::ReadVector(std::vector<T>& val, const std::string& data) {
}
}
+template <class T>
+void XmlReader::ReadVector(DBArray<T>& val, const std::string& data) {
+ // FIXME: Adds copies
+ std::vector<T> tmp;
+ ReadVector(tmp, data);
+ val = DBArray<T>(tmp.begin(), tmp.end());
+}
+
template <>
void XmlReader::Read<std::vector<int32_t>>(std::vector<int32_t>& val, const std::string& data) {
ReadVector<int32_t>(val, data);
@@ -235,4 +243,35 @@ void XmlReader::Read<std::vector<double>>(std::vector<double>& val, const std::s
ReadVector<double>(val, data);
}
+template <>
+void XmlReader::Read<DBArray<int32_t>>(DBArray<int32_t>& val, const std::string& data) {
+ ReadVector<int32_t>(val, data);
+}
+
+template <>
+void XmlReader::Read<DBArray<bool>>(DBArray<bool>& val, const std::string& data) {
+ ReadVector<bool>(val, data);
+}
+
+template <>
+void XmlReader::Read<DBArray<uint8_t>>(DBArray<uint8_t>& val, const std::string& data) {
+ ReadVector<uint8_t>(val, data);
+}
+
+template <>
+void XmlReader::Read<DBArray<int16_t>>(DBArray<int16_t>& val, const std::string& data) {
+ ReadVector<int16_t>(val, data);
+}
+
+template <>
+void XmlReader::Read<DBArray<uint32_t>>(DBArray<uint32_t>& val, const std::string& data) {
+ ReadVector<uint32_t>(val, data);
+}
+
+template <>
+void XmlReader::Read<DBArray<double>>(DBArray<double>& val, const std::string& data) {
+ ReadVector<double>(val, data);
+}
+
+
} //namespace lcf

MODIFY
src/writer_xml.cpp
src/writer_xml.cpp
#include "lcf/writer_xml.h"
#include "lcf/dbstring.h"
+#include "lcf/dbarray.h"
namespace lcf {
@@ -113,48 +114,77 @@ void XmlWriter::Write<DBString>(const DBString& val) {
template <>
void XmlWriter::Write<std::vector<int32_t>>(const std::vector<int32_t>& val) {
- WriteVector<int32_t>(val);
+ WriteVector(val);
}
template <>
void XmlWriter::Write<std::vector<bool>>(const std::vector<bool>& val) {
- WriteVector<bool>(val);
+ WriteVector(val);
}
template <>
void XmlWriter::Write<std::vector<uint8_t>>(const std::vector<uint8_t>& val) {
- WriteVector<uint8_t>(val);
+ WriteVector(val);
}
template <>
void XmlWriter::Write<std::vector<int16_t>>(const std::vector<int16_t>& val) {
- WriteVector<int16_t>(val);
+ WriteVector(val);
}
template <>
void XmlWriter::Write<std::vector<uint32_t>>(const std::vector<uint32_t>& val) {
- WriteVector<uint32_t>(val);
+ WriteVector(val);
}
template <>
void XmlWriter::Write<std::vector<double>>(const std::vector<double>& val) {
- WriteVector<double>(val);
+ WriteVector(val);
+}
+
+template <>
+void XmlWriter::Write<DBArray<int32_t>>(const DBArray<int32_t>& val) {
+ WriteVector(val);
+}
+
+template <>
+void XmlWriter::Write<DBArray<bool>>(const DBArray<bool>& val) {
+ WriteVector(val);
+}
+
+template <>
+void XmlWriter::Write<DBArray<uint8_t>>(const DBArray<uint8_t>& val) {
+ WriteVector(val);
+}
+
+template <>
+void XmlWriter::Write<DBArray<int16_t>>(const DBArray<int16_t>& val) {
+ WriteVector(val);
+}
+
+template <>
+void XmlWriter::Write<DBArray<uint32_t>>(const DBArray<uint32_t>& val) {
+ WriteVector(val);
+}
+
+template <>
+void XmlWriter::Write<DBArray<double>>(const DBArray<double>& val) {
+ WriteVector(val);
}
void XmlWriter::WriteInt(int val) {
Write<int32_t>(val);
}
-template <class T>
-void XmlWriter::WriteVector(const std::vector<T>& val) {
+template <typename ArrayType>
+void XmlWriter::WriteVector(const ArrayType& val) {
Indent();
- typename std::vector<T>::const_iterator it;
bool first = true;
- for (it = val.begin(); it != val.end(); it++) {
+ for (auto&& e: val) {
if (!first)
stream.put(' ');
first = false;
- Write<T>(*it);
+ Write<typename ArrayType::value_type>(e);
}
}
@@ -222,4 +252,10 @@ template void XmlWriter::WriteNode<std::vector<int16_t>>(const std::string& name
template void XmlWriter::WriteNode<std::vector<uint32_t>>(const std::string& name, const std::vector<uint32_t>& val);
template void XmlWriter::WriteNode<std::vector<int32_t>>(const std::string& name, const std::vector<int32_t>& val);
+template void XmlWriter::WriteNode<DBArray<bool>>(const std::string& name, const DBArray<bool>& val);
+template void XmlWriter::WriteNode<DBArray<uint8_t>>(const std::string& name, const DBArray<uint8_t>& val);
+template void XmlWriter::WriteNode<DBArray<int16_t>>(const std::string& name, const DBArray<int16_t>& val);
+template void XmlWriter::WriteNode<DBArray<uint32_t>>(const std::string& name, const DBArray<uint32_t>& val);
+template void XmlWriter::WriteNode<DBArray<int32_t>>(const std::string& name, const DBArray<int32_t>& val);
+
} //namespace lcf

Add support for DBArray to parsing framework