44 for (
const auto &o : other)
45 data.push_back(
Clone(*o));
51 for (
const auto &o : other)
52 data.push_back(
Clone(*o));
102 for (iterator it =
begin(); it !=
end(); ++it)
119 if (pos < data.size())
121 data.insert(data.begin() + pos, d);
123 else if ((pos == data.size()) || (pos == 0))
141 if (from.size() != data.size())
144 _(
"bad changeset size."));
146 std::set<size_t> cont;
147 for (
size_t i : from)
151 if (cont.size() != data.size())
154 _(
"changeset contains duplicates."));
156 if ((*cont.begin() != 0) || (*cont.rbegin() != data.size() - 1))
159 _(
"changeset contains values out of bounds."));
161 std::vector<SObject> newdata;
162 for (
size_t i : from)
164 newdata.push_back(data[i]);
179 if (to.size() != data.size())
182 _(
"bad changeset size."));
184 std::set<size_t> cont;
189 if (cont.size() != data.size())
192 _(
"changeset contains duplicates."));
194 if ((*cont.begin() != 0) || (*cont.rbegin() != data.size() - 1))
197 _(
"changeset contains values out of bounds."));
199 std::vector<SObject> newdata(data.size());
200 for (
size_t tmp = 0; tmp < to.size(); ++tmp)
202 newdata[to[tmp]] = data[tmp];
215 if (index >= data.size())
217 data.erase(data.begin() + index);
228 for (
auto it = data.begin(); it != data.end(); ++it)
253 data.erase(begin.it, end.it);
269 if (el.
GetValue() != getClassName())
272 _(
"Wrong XML element."));
274 std::multimap<int, SObject> xmllist;
285 U
"(xml::Element &el): ") +
String(
_(
"Unknown XML element: ")) +
291 try { index = te.GetAttribute<
int>(
"vector_index",
false); }
catch (...) { index = int(xmllist.size()); }
292 xmllist.insert(std::make_pair(index, d));
295 for (
auto & elem : xmllist)
296 data.push_back(elem.second);
312 for (
size_t tmp = 0; tmp < data.size(); tmp++)
328 data.swap(other.data);
334 std::vector<SObject> (data.begin(), data.end()).swap(data);
347 for (
auto tmp :
Range(v1))
354 Cloner::Register<Vector>();
355 Ruler::Register<Vector>();
xml::Element Serialize(const Object &obj, xml::Element &parent)
Writes an object to XML if possible.
void Swap(Vector &other) noexcept
Swaps contents with another vector.
ScalarRange< T > Range(T b, T e)
Creates a range [[b, e[[.
const_iterator Find(const SCObject &o) const
Finds an object in the container.
void ShrinkToFit()
Optimizes the memory usage.
iterator begin()
Returns an iterator to the first element.
void Remove(size_t index)
Removes an element (safe)
static UObject CreateData(xml::Element &el)
Creates and initializes a SObject from an XML element.
virtual ~Vector() override
Destructor.
Element BeginElement()
Gets the first child element.
#define CRN_END_CLASS_CONSTRUCTOR(classname)
Defines a class constructor.
Vector & operator=(const Vector &)
A UTF32 character string class.
void Insert(const SObject &d, size_t pos)
Inserts an object at a given position.
bool Contains(const SCObject &o) const
Checks of the object is in the vector.
#define CRN_DATA_FACTORY_REGISTER(elemname, classname)
Registers a class to the data factory.
virtual StringUTF8 GetValue() const
Gets the content of the node.
void SetAttribute(const StringUTF8 &name, const StringUTF8 &value)
Sets the value of an attribute.
void Clear() noexcept
Empties the vector.
double Distance(const Int &i1, const Int &i2) noexcept
xml::Element Serialize(xml::Element &parent) const
Dumps to an XML node if applicable.
iterator end()
Returns a iterator to the end of the list.
Vector()
Default constructor.
void Deserialize(xml::Element &el)
Reads from an XML node if applicable.
void ReorderFrom(const std::vector< size_t > &from)
Reorders the elements.
A character string class.
void PushBack(const SObject &d)
Adds an object at the end of the vector.
UObject Clone(const Object &obj)
Clones an object if possible.
Base class for exceptions.
Element PushBackElement(const StringUTF8 &name)
Adds an element at the end of the children list.
Element EndElement()
Gets a null node.
size_t Size() const noexcept
Returns the number of data objects in the vector.
void ReorderTo(const std::vector< size_t > &to)
Reorders the elements.
Invalid argument error (e.g.: nullptr pointer)
#define CRN_BEGIN_CLASS_CONSTRUCTOR(classname)
Defines a class constructor.
An item was not found in a container.