32 using SetOfAttributes = std::vector<Attributes>;
79 inline int size()
const;
85 inline bool empty()
const;
109 inline void replace(
int id, QString newName,
Value newValue);
121 inline const std::vector<QString>&
names()
const;
126 inline const QString&
name(
int id)
const;
131 inline const std::vector<Value>&
values()
const;
154 std::vector<QString> m_names;
155 std::vector<Value> m_values;
164 size_t s = size < 0 ? 0 : static_cast<size_t>(
size);
170 size_t s = size < 0 ? 0 : static_cast<size_t>(
size);
176 {
return static_cast<int>(m_values.size()); }
179 {
return m_names.empty(); }
182 {
return m_names.empty(); }
185 {
return Utils::indexOf(m_names,
name); }
191 if (
id < 0)
throw std::out_of_range(
"id must be positive!");
192 size_t _id =
static_cast<size_t>(id);
193 m_names.at(_id) = newName;
194 m_values.at(_id) = newValue;
198 m_names.emplace_back(
name);
199 m_values.emplace_back(
value);
200 if (m_names.size() >= INT32_MAX)
201 throw std::length_error(
"too many attributes");
208 {
return m_names.at(
id); }
214 {
return m_values.at(
id); }
218 return idx < 0 ? defaultValue : m_values.at(static_cast<size_t>(idx));
222 if (
id < 0)
throw std::out_of_range(
"id must be positive!");
223 m_values.at(static_cast<size_t>(
id)) =
value;
227 #endif // ATTRIBUTES_H A class for variant data types (tagged union).
Definition: value.h:56
void reserve(int size)
Attempt to preallocate enough memory for specified number of elements.
Definition: attributes.h:169
const std::vector< QString > & names() const
Gets the name of all attributes.
Definition: attributes.h:204
Attributes(int size)
Constructor.
Definition: attributes.h:46
bool contains(const QString &name) const
Checks if the container contains name.
Definition: attributes.h:187
bool isEmpty() const
Checks if the container is empty.
Definition: attributes.h:178
const QString & name(int id) const
Gets the name of the attribute at id.
Definition: attributes.h:207
int indexOf(const QString &name) const
Returns the index position of name in the container.
Definition: attributes.h:184
int size() const
Gets the number of attributes in the container.
Definition: attributes.h:175
void setValue(int id, const Value &value)
Sets the value at id.
Definition: attributes.h:221
const Value & value(int id) const
Gets the value of the attribute at id.
Definition: attributes.h:213
void replace(int id, QString newName, Value newValue)
Replaces the item at index position id with newName and newValue.
Definition: attributes.h:190
Attributes()
Constructor.
Definition: attributes.h:48
bool empty() const
Checks if the container is empty.
Definition: attributes.h:181
const std::vector< Value > & values() const
Gets the values of all attributes.
Definition: attributes.h:210
~Attributes()
Destructor.
Definition: attributes.h:51
Definition: abstractgraph.h:29
A container of labeled values.
Definition: attributes.h:39
void resize(int size)
Resizes the container to the specified number of elements.
Definition: attributes.h:163
void push_back(QString name, Value value)
Appends the attribute name with the value value.
Definition: attributes.h:197