LSST Applications g034a557a3c+dd8dd8f11d,g0afe43252f+b86e4b8053,g11f7dcd041+017865fdd3,g1cd03abf6b+8446defddb,g1ce3e0751c+f991eae79d,g28da252d5a+ca8a1a9fb3,g2bbee38e9b+b6588ad223,g2bc492864f+b6588ad223,g2cdde0e794+8523d0dbb4,g347aa1857d+b6588ad223,g35bb328faa+b86e4b8053,g3a166c0a6a+b6588ad223,g461a3dce89+b86e4b8053,g52b1c1532d+b86e4b8053,g7f3b0d46df+ad13c1b82d,g80478fca09+f29c5d6c70,g858d7b2824+293f439f82,g8cd86fa7b1+af721d2595,g965a9036f2+293f439f82,g979bb04a14+51ed57f74c,g9ddcbc5298+f24b38b85a,gae0086650b+b86e4b8053,gbb886bcc26+b97e247655,gc28159a63d+b6588ad223,gc30aee3386+a2f0f6cab9,gcaf7e4fdec+293f439f82,gcd45df26be+293f439f82,gcdd4ae20e8+70b5def7e6,gce08ada175+da9c58a417,gcf0d15dbbd+70b5def7e6,gdaeeff99f8+006e14e809,gdbce86181e+6a170ce272,ge3d4d395c2+224150c836,ge5f7162a3a+bb2241c923,ge6cb8fbbf7+d119aed356,ge79ae78c31+b6588ad223,gf048a9a2f4+40ffced2b8,gf0baf85859+b4cca3d10f,w.2024.30
LSST Data Management Base Package
Loading...
Searching...
No Matches
SchemaImpl.h
Go to the documentation of this file.
1// -*- lsst-c++ -*-
2#ifndef AFW_TABLE_DETAIL_SchemaImpl_h_INCLUDED
3#define AFW_TABLE_DETAIL_SchemaImpl_h_INCLUDED
4
5#include <vector>
6#include <algorithm>
7#include <map>
8#include <variant>
9
10namespace lsst {
11namespace afw {
12namespace table {
13
14class Schema;
15class SubSchema;
16
21template <typename T>
28
29namespace detail {
30
31class Access;
32
46private:
49 template <typename ...E>
50 static std::variant<SchemaItem<E>...> makeItemVariantType(TypeList<E...>);
51public:
52 static int const VERSION = 3;
53
55 using ItemVariant = decltype(makeItemVariantType(FieldTypes{}));
64
66 std::size_t getRecordSize() const { return _recordSize; }
67
69 std::size_t getFieldCount() const { return _names.size(); }
70
72 std::size_t getFlagFieldCount() const { return _flags.size(); }
73
75 std::size_t getNonFlagFieldCount() const { return _offsets.size(); }
76
78 template <typename T>
79 SchemaItem<T> find(std::string const& name) const;
80
82 template <typename T>
83 SchemaItem<T> find(Key<T> const& key) const;
84
86 SchemaItem<Flag> find(Key<Flag> const& key) const;
87
89 template <typename F>
90 decltype(auto) findAndApply(std::string const& name, F&& func) const {
91 auto iter = _names.find(name);
92 if (iter == _names.end()) {
94 (boost::format("Field with name '%s' not found") % name).str());
95 }
96 return std::visit(std::forward<F>(func), _items[iter->second]);
97 }
98
101
104
105 template <typename T>
106 int contains(SchemaItem<T> const& item, int flags) const;
107
109 template <typename T>
110 Key<T> addField(Field<T> const& field, bool doReplace = false);
111
113 Key<Flag> addField(Field<Flag> const& field, bool doReplace = false);
114
116 template <typename T>
117 Key<Array<T> > addField(Field<Array<T> > const& field, bool doReplace = false);
118
120 Key<std::string> addField(Field<std::string> const& field, bool doReplace = false);
121
123 template <typename T>
124 void replaceField(Key<T> const& key, Field<T> const& field);
125
133 ItemContainer const& getItems() const { return _items; }
134
136 SchemaImpl() : _recordSize(0), _lastFlagField(0), _lastFlagBit(0), _items(), _initFlag(false) {}
137
138private:
139 friend class detail::Access;
140
141 template <typename T>
142 Key<T> addFieldImpl(std::size_t elementSize, std::size_t elementCount, Field<T> const& field, bool doReplace);
143
144 std::size_t _recordSize; // Size of a record in bytes.
145 std::size_t _lastFlagField; // Offset of the last flag field in bytes.
146 std::size_t _lastFlagBit; // Bit of the last flag field.
147 ItemContainer _items; // Vector of variants of SchemaItem<T>.
148 NameMap _names; // Field name to vector-index map.
149 OffsetMap _offsets; // Offset to vector-index map for regular fields.
150 FlagMap _flags; // Offset to vector-index map for flags.
151 bool _initFlag; // Indicates if record is valid
152};
153} // namespace detail
154} // namespace table
155} // namespace afw
156} // namespace lsst
157
158#endif // !AFW_TABLE_DETAIL_SchemaImpl_h_INCLUDED
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
std::string prefix
Tag types used to declare specialized field types.
Definition misc.h:31
A private implementation class to hide the messy details of Schema.
Definition SchemaImpl.h:45
std::set< std::string > getNames(bool topOnly) const
Return a set of field names (used to implement Schema::getNames).
Definition Schema.cc:251
SchemaImpl()
Default constructor.
Definition SchemaImpl.h:136
Key< T > addField(Field< T > const &field, bool doReplace=false)
Add a field to the schema (used to implement Schema::addField).
Definition Schema.cc:314
int contains(SchemaItem< T > const &item, int flags) const
Definition Schema.cc:225
decltype(auto) findAndApply(std::string const &name, F &&func) const
Find an item by name and run the given functor on it.
Definition SchemaImpl.h:90
std::size_t getRecordSize() const
The size of a record in bytes.
Definition SchemaImpl.h:66
void replaceField(Key< T > const &key, Field< T > const &field)
Replace the Field in an existing SchemaItem without changing the Key.
Definition Schema.cc:193
std::size_t getFlagFieldCount() const
The number of Flag fields.
Definition SchemaImpl.h:72
std::size_t getNonFlagFieldCount() const
The number of non-Flag fields.
Definition SchemaImpl.h:75
SchemaItem< T > find(std::string const &name) const
Find an item by name (used to implement Schema::find).
Definition Schema.cc:92
ItemContainer const & getItems() const
Return the vector of SchemaItem variants.
Definition SchemaImpl.h:133
std::size_t getFieldCount() const
The total number of fields.
Definition SchemaImpl.h:69
decltype(makeItemVariantType(FieldTypes{})) ItemVariant
A Boost.Variant type that can hold any one of the allowed SchemaItem types.
Definition SchemaImpl.h:55
Reports attempts to access elements using an invalid key.
Definition Runtime.h:151
T end(T... args)
T find(T... args)
T size(T... args)
A description of a field in a table.
Definition Field.h:24
A simple pair-like struct for mapping a Field (name and description) with a Key (used for actual data...
Definition SchemaImpl.h:22
SchemaItem(Key< T > const &key_, Field< T > const &field_)
Definition SchemaImpl.h:26