43 for (
const auto &p : other)
44 data.emplace(p.first,
Clone(*p.second));
50 for (
const auto &p : other)
51 data.emplace(p.first,
Clone(*p.second));
106 if (!data.erase(key))
119 for (
auto it =
begin(); it !=
end(); ++it)
120 if (it->second == obj)
163 data.erase(first, end_);
166 for (
auto tmp = first; tmp !=
end(); ++tmp)
170 data.erase(first, end_);
192 _(
"Wrong XML element."));
203 catch (std::exception &e)
207 String(
_(
"Cannot deserialize: ")) + te.GetValue() +
String(
_(
" because ")) + e.what());
223 for (
const auto & elem : *
this)
238 std::set<String> keys;
239 for (
const auto & elem : *
this)
241 keys.insert(elem.first);
256 return data.begin()->first;
269 return data.rbegin()->first;
279 data.swap(other.data);
285 auto root = xdoc.GetRoot();
288 _(
"Cannot find root element.")};
289 auto el = root.GetFirstChildElement();
xml::Element Serialize(const Object &obj, xml::Element &parent)
Writes an object to XML if possible.
String FirstKey() const
Returns the first (lowest) key.
void Clear() noexcept
Empties the map.
iterator Find(const String &key)
Returns an iterator to a specific key.
void Set(const String &key, SObject value)
Sets a value for a key with constraints check.
Element PushBackElement(const StringUTF8 &name)
Adds an element at the end of the children list.
void Deserialize(xml::Element &el)
Reads from an XML node if applicable.
static UObject CreateData(xml::Element &el)
Creates and initializes a SObject from an XML element.
void Remove(const String &key)
Removes an element (safe)
void Load(const Path &fname)
Element BeginElement()
Gets the first child element.
#define CRN_END_CLASS_CONSTRUCTOR(classname)
Defines a class constructor.
void Swap(Map &other) noexcept
Swaps contents with another map.
A UTF32 character string class.
std::map< String, SObject >::iterator iterator
iterator on the contents of the container
void Save(const Path &fname) const
Map()
Default constructor.
String LastKey() const
Returns the last (greatest) key.
A convenience class for file paths.
iterator begin()
Returns an iterator to the first element.
xml::Element Serialize(xml::Element &parent) const
Dumps to an XML node if applicable.
#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.
SObject Get(const String &s)
Returns an object from index or nullptr if inexistent.
A character string class.
UObject Clone(const Object &obj)
Clones an object if possible.
iterator end()
Returns an iterator after the last element.
Element PushBackElement(const StringUTF8 &name)
Adds an element at the end of the children list.
Map & operator=(const Map &other)
Element EndElement()
Gets a null node.
virtual ~Map() override
Destructor.
Invalid argument error (e.g.: nullptr pointer)
std::set< String > GetKeys() const
Returns all keys.
#define CRN_BEGIN_CLASS_CONSTRUCTOR(classname)
Defines a class constructor.
An item was not found in a container.