Class BaseTable

Inheritance Relationships

Base Type

  • public std::enable_shared_from_this< BaseTable >

Derived Types

Class Documentation

class BaseTable : public std::enable_shared_from_this<BaseTable>

Base class for all tables.

Tables have two largely distinct purposes:

  • They serve as factories for records, allocating their field data in blocks.

  • They carry additional information (such as the schema) that should be shared by multiple records.

It’s mostly a matter of convenience that we use the same class to serve both needs.

Tables do not actually maintain a list of all the records they have allocated - but those records hold a pointer back to the table. This allows the work of holding and iterating over records to be delegated to templated container classes (such as CatalogT) while allowing tables to be polymorphic, non-template classes. In some sense, then, it may make more sense to think of a table as a combination factory and “container header”.

Tables are always created in shared_ptrs (a requirement of enable_shared_from_this). BaseTable provides a make static member function to create a new table, and most derived table classes should do the same.

Each table class should be associated with a particular record class (1-to-1). Each table instance may be associated with many record instances.

Subclassed by lsst::afw::detection::PeakTable, lsst::afw::table::ExposureTable, lsst::afw::table::SimpleTable

Public Types

typedef BaseRecord Record

The associated record class.

typedef BaseColumnView ColumnView

The associated ColumnView class.

typedef CatalogT<Record> Catalog

Template of CatalogT used to hold records of the associated type.

typedef CatalogT<Record const> ConstCatalog

Template of CatalogT used to hold const records of the associated type.

Public Functions

std::shared_ptr<daf::base::PropertyList> getMetadata() const

Return the flexible metadata associated with the table. May be null.

void setMetadata(std::shared_ptr<daf::base::PropertyList> const &metadata)

Set the flexible metadata associated with the table. May be null.

std::shared_ptr<daf::base::PropertyList> popMetadata()

Return the metadata and set the internal metadata to a null pointer.

std::shared_ptr<BaseTable> clone() const

Return a polymorphic deep copy of the table.

Derived classes should reimplement by static-casting the output of _clone to a pointer-to-derived to simulate covariant return types.

Cloning a table does not clone its associated records; the new table produced by clone() does not have any associated records.

std::shared_ptr<BaseRecord> makeRecord()

Default-construct an associated record.

Derived classes should reimplement by static-casting the output of _makeRecord to the appropriate BaseRecord subclass to simulate covariant return types.

std::shared_ptr<BaseRecord> copyRecord(BaseRecord const &input)

Deep-copy a record, requiring that it have the same schema as this table.

Regardless of the type or associated table of the input record, the type of the output record will be the type associated with this table and the record instance will be associated with this table.

Allowing derived-class records to be constructed from base-class records could be considered a form of type-slicing, but because we already demand that all records be constructable from nothing but a table, this isn’t anything new.

Derived classes should reimplement by static-casting the output of BaseTable::copyRecord to the appropriate BaseRecord subclass.

This is implemented using makeRecord and calling record.assign on the results; override those to change the behavior.

std::shared_ptr<BaseRecord> copyRecord(BaseRecord const &input, SchemaMapper const &mapper)

Deep-copy a record, using a mapper to relate two schemas.

Deep-copy a record, requiring that it have the same schema as this table.

Regardless of the type or associated table of the input record, the type of the output record will be the type associated with this table and the record instance will be associated with this table.

Allowing derived-class records to be constructed from base-class records could be considered a form of type-slicing, but because we already demand that all records be constructable from nothing but a table, this isn’t anything new.

Derived classes should reimplement by static-casting the output of BaseTable::copyRecord to the appropriate BaseRecord subclass.

This is implemented using makeRecord and calling record.assign on the results; override those to change the behavior.

Schema getSchema() const

Return the table’s schema.

void preallocate(std::size_t nRecords)

Allocate contiguous space for new records in advance.

If a contiguous memory block for at least n additional records has already been allocated, this is a no-op. If not, a new block will be allocated, and any remaining space on the old block will go to waste; this ensures the new records will be allocated contiguously. Note that “wasted” memory is not leaked; it will be deallocated along with any records created from that block when those records go out of scope.

Note that unlike std::vector::reserve, this does not factor in existing records in any way; nRecords refers to a number of new records to reserve space for.

std::size_t getBufferSize() const

Return the number of additional records space has been already been allocated for.

Unlike std::vector::capacity, this does not factor in existing records in any way.

BaseTable &operator=(BaseTable const &other)
BaseTable &operator=(BaseTable &&other)
virtual ~BaseTable()

Public Static Functions

static std::shared_ptr<BaseTable> make(Schema const &schema)

Construct a new table.

Because BaseTable is an abstract class, this actually returns a hidden trivial subclass (which is associated with a hidden trivial subclass of BaseRecord).

Hiding concrete table and record classes in anonymous namespaces is not required, but it makes it easier to ensure instances are always created within shared_ptrs, and it eliminates some multilateral friending that would otherwise be necessary. In some cases it may also serve as a form of pimpl, keeping class implementation details out of header files.

Public Static Attributes

int nRecordsPerBlock

Number of records in each memory block.

Protected Functions

template<typename RecordT, typename ...Args>
std::shared_ptr<RecordT> constructRecord(Args&&... args)

Helper function that must be used by all _makeRecord overrides to actually construct records.

Use of this function is enforced by the fact that Record::ConstructionToken can only be created by BaseTable, and is only ever constructed inside this method.

This function expects Record subclasses to have a constructor signature of the form

Record(ConstructionToken const &, detail::RecordData &&, Args && ...);

virtual void handleAliasChange(std::string const &alias)
virtual std::shared_ptr<BaseTable> _clone() const

Clone implementation with noncovariant return types.

virtual std::shared_ptr<BaseRecord> _makeRecord()

Default-construct an associated record (protected implementation).

BaseTable(Schema const &schema)

Construct from a schema.

BaseTable(BaseTable const &other)

Copy construct.

BaseTable(BaseTable &&other)

Friends

friend lsst::afw::table::BaseTable::io::FitsWriter