Class SubSchema¶
Defined in File Schema.h
Class Documentation¶
-
class
SubSchema
¶ A proxy type for name lookups in a Schema.
Elements of schema names are assumed to be separated by underscores (“a_b_c”); an incomplete lookup is one that does not resolve to a field. Not that even complete lookups can have nested names; a Point field, for instance, has “x” and “y” nested names.
This proxy object is implicitly convertible to both the appropriate Key type and the appropriate Field type, if the name is a complete one, and supports additional find() operations for nested names.
SubSchema is implemented as a proxy that essentially calls Schema::find after concatenating strings. It does not provide any performance advantage over using Schema::find directly. It is also lazy, so looking up a name prefix that does not exist within the schema is not considered an error until the proxy is used.
Some examples:
Schema schema(false); Key<int> a_i = schema.addField<int>("a_i", "integer field"); Key< Point<double> > a_p = schema.addField< Point<double> >("a_p", "point field"); assert(schema["a_i"] == a_i); SubSchema a = schema["a"]; assert(a["i"] == a_i); Field<int> f_a_i = schema["a_i"]; assert(f_a_i.getDoc() == "integer field"); assert(schema["a_i"] == "a_i"); assert(schema.find("a_p_x") == a_p.getX());
Unnamed Group
-
std::string
join
(std::string const &a, std::string const &b) const¶ Join strings using the field delimiter appropriate for this Schema.
-
std::string
join
(std::string const &a, std::string const &b, std::string const &c) const¶
-
std::string
join
(std::string const &a, std::string const &b, std::string const &c, std::string const &d) const¶
Public Functions
-
template<typename
T
>
SchemaItem<T>find
(std::string const &name) const¶ Find a nested SchemaItem by name.
-
template<typename
F
>
voidfindAndApply
(std::string const &name, F &&func) const¶ Find a nested SchemaItem by name and run a functor on it.
Names corresponding to named subfields are not accepted. The given functor must have an overloaded function call operator that accepts any SchemaItem type (the same as a functor provided to apply or Schema::forEach).
-
template<typename
F
>
voidapply
(F &&func) const¶ Run functor on the SchemaItem represented by this SubSchema
The given functor must have an overloaded function call operator that accepts any SchemaItem type (the same as a functor provided to apply or Schema::forEach).
- Exceptions
Throws
: pex::exceptions::NotFoundError if the SubSchemas prefix does not correspond to the full name of a regular field (not a named subfield).
-
std::string const &
getPrefix
() const¶ Return the prefix that defines this SubSchema relative to its parent Schema.
-
std::set<std::string>
getNames
(bool topOnly = false) const¶ Return a set of nested names that start with the SubSchema’s prefix.
Returns an instance of Python’s builtin set in Python.
-
std::string