29#include <sptk5/Field.h>
30#include <sptk5/wsdl/WSFieldIndex.h>
31#include <sptk5/wsdl/WSType.h>
32#include <sptk5/xdoc/Document.h>
33#include <sptk5/xdoc/Node.h>
46 using iterator =
typename std::vector<T>::iterator;
47 using const_iterator =
typename std::vector<T>::const_iterator;
53 explicit WSArray(
const char* name =
"array")
66 [[nodiscard]]
bool isNull()
const override
68 return m_array.empty();
71 [[nodiscard]]
size_t size()
const
73 return m_array.size();
78 return m_array.clear();
83 return m_array.empty();
86 T& operator[](
size_t index)
88 return m_array[index];
91 const T& operator[](
size_t index)
const
93 return m_array[index];
98 return m_array.begin();
103 return m_array.end();
106 const_iterator begin()
const
108 return m_array.begin();
111 const_iterator end()
const
113 return m_array.end();
118 return m_array.front();
121 const T& front()
const
123 return m_array.front();
128 return m_array.back();
131 const T& back()
const
133 return m_array.back();
136 void push_back(
const T& value)
138 m_array.push_back(value);
141 void push_back(T&& value)
143 m_array.push_back(value);
146 void emplace_back(
const T& value)
148 m_array.emplace_back(value);
151 void emplace_back(T&& value)
153 m_array.emplace_back(value);
156 void resize(
size_t sz)
161 auto erase(
const iterator& pos)
163 return m_array.erase(pos);
166 auto erase(
const iterator& first,
const iterator& last)
168 return m_array.erase(first, last);
171 void load(
const xdoc::SNode& node,
bool nullLargeData)
override
173 for (
const auto& arrayElement: node->nodes())
175 T item(name().c_str(),
false);
176 item.load(arrayElement, nullLargeData);
177 m_array.push_back(std::move(item));
188 exportTo(document.root());
189 const auto& arrayNode = document.root()->findFirst(name());
190 arrayNode->exportTo(xdoc::DataFormat::JSON, buffer,
false);
199 void exportTo(
const xdoc::SNode& output,
const char* name =
nullptr)
const override
201 const char* itemName = name ==
nullptr ?
"item" : name;
202 auto& arrayNode = output->pushNode(this->name(), xdoc::Node::Type::Array);
203 for (
const auto& element: m_array)
205 element.exportTo(arrayNode, itemName);
210 std::vector<T> m_array;
void clear() override
Definition: WSArray.h:76
String asString() const override
Definition: WSArray.h:184
String className() const override
Definition: WSArray.h:61
WSArray(const char *name="array")
Definition: WSArray.h:53
void exportTo(const xdoc::SNode &output, const char *name=nullptr) const override
Definition: WSArray.h:199
void load(const xdoc::SNode &node, bool nullLargeData) override
Definition: WSArray.h:171
Definition: Document.h:34