Class SchemaImpl

Class Documentation

class SchemaImpl

A private implementation class to hide the messy details of Schema.

This can’t be a real pimpl class, because some of the most important functionality is in the forEach function, a templated function we can’t explicitly instantiate in a source file. But putting all the details here draws a clear line between what users should look at (Schema) and what they shouldn’t (this).

Because Schema holds SchemaImpl by shared pointer, one SchemaImpl can be shared between multiple Schemas (and SubSchemas), which implement copy-on-write by creating a new SchemaImpl if the pointer they have isn’t unique when they are modified.

Public Types

typedef boost::mpl::transform<FieldTypes, MakeItem>::type ItemTypes

An MPL sequence of all the allowed SchemaItem templates.

typedef boost::make_variant_over<ItemTypes>::type ItemVariant

A Boost.Variant type that can hold any one of the allowed SchemaItem types.

typedef std::vector<ItemVariant> ItemContainer

A std::vector whose elements can be any of the allowed SchemaItem types.

typedef std::map<std::string, int> NameMap

A map from field names to position in the vector, so we can do name lookups.

typedef std::map<int, int> OffsetMap

A map from standard field offsets to position in the vector, so we can do field lookups.

typedef std::map<std::pair<int, int>, int> FlagMap

A map from Flag field offset/bit pairs to position in the vector, so we can do Flag field lookups.

Public Functions

int getRecordSize() const

The size of a record in bytes.

int getFieldCount() const

The total number of fields.

int getFlagFieldCount() const

The number of Flag fields.

int getNonFlagFieldCount() const

The number of non-Flag fields.

template<typename T>
SchemaItem<T> find(std::string const &name) const

Find an item by name (used to implement Schema::find).

template<typename T>
SchemaItem<T> find(Key<T> const &key) const

Find an item by key (used to implement Schema::find).

SchemaItem<Flag> find(Key<Flag> const &key) const

Find an item by key (used to implement Schema::find).

template<typename F>
void findAndApply(std::string const &name, F &&func) const

Find an item by name and run the given functor on it.

std::set<std::string> getNames(bool topOnly) const

Return a set of field names (used to implement Schema::getNames).

std::set<std::string> getNames(bool topOnly, std::string const &prefix) const

Return a set of field names (used to implement SubSchema::getNames).

template<typename T>
int contains(SchemaItem<T> const &item, int flags) const
template<typename T>
Key<T> addField(Field<T> const &field, bool doReplace = false)

Add a field to the schema (used to implement Schema::addField).

Key<Flag> addField(Field<Flag> const &field, bool doReplace = false)

Add a field to the schema (used to implement Schema::addField).

template<typename T>
Key<Array<T>> addField(Field<Array<T>> const &field, bool doReplace = false)

Add a field to the schema (used to implement Schema::addField).

Key<std::string> addField(Field<std::string> const &field, bool doReplace = false)

Add a field to the schema (used to implement Schema::addField).

template<typename T>
void replaceField(Key<T> const &key, Field<T> const &field)

Replace the Field in an existing SchemaItem without changing the Key.

ItemContainer const &getItems() const

Return the vector of SchemaItem variants.

Fields are in the order they are added. That means they’re also ordered with increasing Key offsets, except for Flag fields, which are in increasing order of (offset, bit) relative to each other, but not relative to all the other fields.

SchemaImpl()

Default constructor.

Public Static Attributes

int const VERSION = 3

Friends

friend lsst::afw::table::detail::SchemaImpl::detail::Access
template<typename F>
struct VisitorWrapper : public boost::static_visitor<>

A functor-wrapper used in the implementation of Schema::forEach.

Visitor functors used with Boost.Variant (see the Boost.Variant docs) must inherit from boost::static_visitor<> to declare their return type (void, in this case). By wrapping user-supplied functors with this class, we can hide the fact that we’ve implemented SchemaImpl using Boost.Variant (because they won’t need to inherit from static_visitor themselves.

Public Functions

template<typename T>
void operator()(SchemaItem<T> const &x) const

Call the wrapped function.

void operator()(ItemVariant const &v) const

Invoke the visitation.

The call to boost::apply_visitor will call the appropriate template of operator().

This overload allows a VisitorWrapper to be applied directly on a variant object with function-call syntax, allowing us to use it on our vector of variants with std::for_each and other STL algorithms.

template<typename T>
VisitorWrapper(T &&func)

Construct the wrapper.