37 #ifndef H_OGF_BASIC_TYPES_ARG_LIST_H
38 #define H_OGF_BASIC_TYPES_ARG_LIST_H
45 #include <type_traits>
82 argval_(rhs.argval_), argname_(rhs.argname_) {
90 argval_ = rhs.argval_;
91 argname_ = rhs.argname_;
100 return argname_.size();
112 for(
index_t i=0; i<nb_args(); ++i) {
113 if(ith_arg_name(i) !=
"arg#" + String::to_string(i)) {
130 return (find_arg_index(name) !=
index_t(-1));
149 argval_.erase(argval_.begin()+index);
150 argname_.erase(argname_.begin()+index);
180 !argval_[i].get_value(result) &&
181 !get_name(argval_[i], result)
183 arg_type_error(i,
typeid(T).name());
223 index_t i = find_arg_index(name);
236 index_t i = find_arg_index(name);
250 return argval_[i].meta_type();
261 argval_.push_back(
Any());
262 argname_.push_back(name);
263 return *(argval_.rbegin());
273 return create_arg(
"arg#" + String::to_string(nb_args()));
284 const std::string& name,
const T& value
287 argval_.push_back(
Any());
288 argname_.push_back(name);
289 argval_.rbegin()->set_value(value);
299 const std::string& name,
const char* value
301 create_arg<std::string>(name, value);
311 const std::string& name,
const Any& value
314 argval_.push_back(value);
315 argname_.push_back(name);
328 const std::string& name,
const T& value
330 index_t i = find_arg_index(name);
332 create_arg(name, value);
334 argval_[i].set_value(value);
346 void set_arg(
const std::string& name,
const char* value) {
347 set_arg<std::string>(name, value);
360 index_t i = find_arg_index(name);
362 create_arg(name, value);
377 argval_[i].set_value(value);
387 set_ith_arg<std::string>(i, value);
396 std::string
get_arg(
const std::string& name)
const {
397 index_t i = find_arg_index(name);
399 return argval_[i].as_string();
412 template <
class T> T
get_arg(
const std::string& name)
const {
413 index_t i = find_arg_index(name);
417 !argval_[i].get_value(result) &&
418 !get_name(argval_[i], result)
420 arg_type_error(i,
typeid(T).name());
432 index_t i = find_arg_index(name);
434 return argval_[i].meta_type();
468 void serialize(std::ostream& out)
const;
477 index_t i,
const std::string& expected_typeid_name
492 template <
class T>
static bool get_name(
const Any& argval, T& name) {
493 if(!std::is_base_of<NameBase, T>::value) {
497 if(!get_object_name(argval, name_prop)) {
A class to hold a value of arbitrary type.
#define geo_debug_assert(x)
Verifies that a condition is met.
Vector with aligned memory allocation.
A class that stores a variable of arbitrary type.
bool get_value(T &value) const
Gets the stored value.
Represents a list of name-value pairs.
MetaType * get_arg_type(const std::string &name) const
Gets the type of an argument.
void append(const ArgList &rhs, bool overwrite=true)
Appends all the arguments from an ArgList to this one.
void set_ith_arg(index_t i, const char *value)
Sets an argument by index.
ArgList()
ArgList constructor.
void create_arg(const std::string &name, const Any &value)
Creates an argument from an Any.
ArgList(const ArgList &rhs)
ArgList copy-constructor.
void create_arg(const std::string &name, const char *value)
Creates an argument from a string litteral.
void clear()
Removes all the arguments from this ArgList.
const Any & ith_arg_value(index_t i) const
Gets argument value by index, stored as an Any.
void delete_ith_arg(index_t index)
Deletes an argument by index.
Any & create_arg(const std::string &name)
Creates an uninitialized argument.
void set_ith_arg(index_t i, const T &value)
Sets an argument by index.
Any & create_unnamed_arg()
Creates an uninitialized unnamed argument.
bool has_arg(const std::string &name) const
Tests whether an argument of a given name exists in this ArgList.
void set_arg(const std::string &name, const char *value)
Sets an argument from a string litteral.
void arg_type_error(index_t i, const std::string &expected_typeid_name) const
Displays an error message for invalid argument type.
static bool get_name(const Any &argval, T &name)
Converts a pointer to Object into a string using its name attribute if target type is a xxxName.
void append_ith_arg(const ArgList &rhs, index_t i, bool overwrite=true)
Appends an argument from an ArgList to this one.
const std::string & ith_arg_name(index_t i) const
Gets argument name by index.
void set_arg(const std::string &name, const Any &value)
Sets an argument from an Any.
Any & arg_value(const std::string &name)
Gets argument value by name, stored as an Any.
T ith_arg_value(index_t i) const
Gets argument value by index.
static bool get_object_name(const Any &object, Any &name)
Gets the name of an object.
void create_arg(const std::string &name, const T &value)
Creates an argument.
MetaType * ith_arg_type(index_t i) const
Gets the type of an argument by index.
T get_arg(const std::string &name) const
Gets an argument by name.
std::string get_arg(const std::string &name) const
Gets a string representation of an argument.
bool has_unnamed_args() const
Tests whether this ArgList has unnamed args.
void set_arg(const std::string &name, const T &value)
Sets an argument.
const Any & arg_value(const std::string &name) const
Gets argument value by name, stored as an Any.
index_t nb_args() const
Gets the number of arguments.
ArgList & operator=(const ArgList &rhs)
ArgList assignment operator.
Any & ith_arg_value(index_t i)
Gets argument value by index, stored as an Any.
index_t find_arg_index(const std::string &name) const
Finds argument index by name.
Base class for all Names in Graphite (GrobName ...).
Types and functions for memory manipulation.
geo_index_t index_t
The type for storing and manipulating indices.
Global Graphite namespace.
std::ostream & operator<<(std::ostream &out, const ArgList &args)
Prints an ArgList into a stream.
Definitions common to all include files in the gom library.
Functions for string manipulation.