CFields
CFields();
Creates an empty field selection. Add field indices with operator<<, or use all() to request all fields.
SDK support
Row descriptors, field selections, row concepts, and supporting typed-table declarations.
#include <mc/database/CTable_.h>Use CField, CFields, and CRow32 or CRow64 to describe row data. Cosmic schemas normally generate these descriptors for you.
Unique, Optional, and Hash are field flags. A hashed field stores its index representation instead of a recoverable original value.
The support templates are listed for completeness; applications normally access tables through CDatabase and CTable<R>.
template<class V, size_t I, uint64_t G = 0> struct CFieldusing type = V;
static constexpr size_t Index = I;
static constexpr uint64_t Flags = G;
class CFieldsCFields();
Creates an empty field selection. Add field indices with operator<<, or use all() to request all fields.
CFields& operator<<(size_t index);
Adds a field index to the selection and grows the mask if necessary. Repeated additions leave the field selected.
bool operator[](size_t i) const;
Tests the stored selection mask at a valid index. Check isAll() separately for the all-fields marker; that marker does not populate the mask.
size_t size() const;
Returns the length of the selection mask, not the number of selected fields. The all-fields marker can have an empty mask.
static CFields all();
Creates the special selection meaning every field. It is interpreted by table retrieval rather than expanded into individual indices.
bool isAll() const;
Reports whether the selection is the special all-fields marker.
template<size_t I> struct CFieldsCreate_template<class T> static bool create(const T& t, CFields& f);
Adds the field indices from a tuple starting at compile-time position I to an existing selection. This supports generated row fields() helpers.
template<class F> struct CFieldGetType_template<size_t J, uint64_t G> struct CFieldGetType_<CField<cstr, J, G>>template<size_t J, uint64_t G> struct CFieldGetType_<CField<cvar, J, G>>using RowId = RI;
using RowSet = CHashSet<RowId>;
using RowVector = CVector<RowId>;
static const uint64_t Unique = 0x01;
static const uint64_t Optional = 0x02;
static const uint64_t Hash = 0x04;
Creates a row from a field count or existing value vector. Slot zero holds the row ID; a new count-based row starts with ID zero and requires room for that slot.
void setRowId(RowId rowId) noexcept;
Sets the row’s stored ID without changing any database record. IDs used for update or erase must identify an existing row.
RowId rowId() const noexcept;
Returns the row ID in slot zero. Zero denotes a new or unassigned row.
Returns the backing field vector by reference. Changes affect this row immediately, but still require table insertion/update and commit to reach the database.
operator cvec&() noexcept;
operator const cvec&() const noexcept;
template<class F> decltype(auto) get();
Directly reads the requested field type. The field must be loaded, present, and have the matching stored type; use safeGet() for checked access.
template<class F> decltype(auto) safeGet();
Reads a field through checked conversion, except cvar fields which are returned directly. Missing or incompatible typed fields raise CError.
template<class F> decltype(auto) has() const;
Reports whether a field slot is non-Null. It does not prove the row exists in a table or that an unloaded field is absent on disk.
template<class F, class T> void set(T&& x);
Assigns a value to a field slot in this row. It does not stage a database update by itself.
template<class V, size_t J, uint64_t G> void erase(CField<V, J, G> f);
Sets the selected field slot to Null in this row. The row still needs a table update and commit to persist the change.
friend std::ostream& operator<<(std::ostream& ostr, const CRow& r);
void init_(cvec&& v) noexcept;
Replaces the complete field vector by moving the supplied values. This is the row-adapter hook used by table retrieval.
template<class... Args> static CFields fields();
Builds a field selection from the supplied field-descriptor template arguments. Use it to avoid reading unneeded columns.
struct CMultiIndexValue__template<class T> struct CMultiIndexValue_ : public CMultiIndexValue__using type = T;
chash h;
T v;
Combines the hash of equality-constrained fields with the ordered component of a composite index. The value-taking constructor expects the three-element representation produced by conversion to cvar.
bool operator<(const CMultiIndexValue_& x) const;
Orders composite-index values by their equality-key hash first and their ordered component second. This groups equal composite keys for range traversal.
bool operator<=(const CMultiIndexValue_& x) const;
Orders composite-index values by their equality-key hash first and their ordered component second. This groups equal composite keys for range traversal.
bool operator>(const CMultiIndexValue_& x) const;
Orders composite-index values by their equality-key hash first and their ordered component second. This groups equal composite keys for range traversal.
bool operator==(const CMultiIndexValue_& x) const;
operator cvar() const;
Returns the two words of the equality-key hash followed by the ordered component as a three-element vector.
template<class T> struct CTableIndexType_using type = std::conditional_t< std::same_as<T, uint32_t> || std::same_as<T, int32_t> || std::same_as<T, uint64_t> || std::same_as<T, int64_t> || std::same_as<T, float> || std::same_as<T, double>, T, cvar>;
template<CCField F> struct CTableFieldValueType_template<CCRowId RI, class T> class CTableIndex_template<CCRowId RI> class CTableIndex_<RI, cvar>template<CCRowId RI, class T> class CTableIndex_<RI, CMultiIndexValue_<T>>template<CCRowId RI> class CTableIndex_<RI, CMultiIndexValue_<cvar>>using value_type = T;
using value_type = chash;
using value_type = CMultiIndexValue_<T>;
using value_type = CMultiIndexValue_<uint64_t>;
using RowId = RI;
using RowSet = CHashSet<RowId>;
using RowVector = CVector<RowId>;
using QueryFunc_ = std::function<bool(RowId rowId, cvec& r)>;
using UpdateMap = CHashMap<RowId, RowId>;
CTableIndex_() noexcept;
Creates an uninitialized index adapter. Generated table construction calls init() before using its operations.
~CTableIndex_();
void init(CTable_<RowId>* t, size_t indexId, uint64_t flags) noexcept;
Attaches the adapter to a borrowed table and an assigned index ID with field flags. The table must outlive the adapter.
void insert(RowId rowId, T x) noexcept;
void insert(RowId rowId, const cstr& x) noexcept;
void insert(RowId rowId, const cvar& x) noexcept;
void insert(RowId rowId, value_type x) noexcept;
Stages an index entry for a row. It is prepared and published with the table’s commit sequence.
template<CCRow R> bool get(const CFields& fs, T value, R& row) noexcept;
template<CCRow R> bool get(const CFields& fs, const cvar& v, R& row) noexcept;
template<CCRow R> bool get(const CFields& fs, const chash& h, T value, R& row) noexcept;
template<CCRow R> bool get(const CFields& fs, const chash& h, const cvar& value, R& row) noexcept;
Looks up an equal indexed value and fills the first matching row, returning false when none exists. The field selection controls which row fields are loaded.
bool has(T value);
bool has(const cvar& value);
bool has(const chash& h, T value);
bool has(const chash& h, const cvar& value);
Tests for an equal indexed value without returning a row.
void query(const CFields& fs, T start, T end, QueryFunc_ f);
void query(const CFields& fs, value_type start, value_type end, QueryFunc_ f);
void query(const CFields& fs, const chash& h, T start, T end, QueryFunc_ f);
void query(const CFields& fs, const chash& h, const cvar& start, const cvar& end, QueryFunc_ f);
Visits an indexed value interval, including equal endpoint matches. A callback returning false stops traversal; compound-index overloads additionally select an equality-key group.
void setQuery(T start, T end, RowSet& rs);
void setQuery(value_type start, value_type end, RowSet&);
void setQuery(const chash& h, T start, T end, RowSet& rs);
void setQuery(value_type start, value_type end, RowSet& rs);
void setQuery(const chash& h, const cvar& start, const cvar& end, RowSet& rs);
Adds matching row IDs to an existing result set without clearing it.
void vectorQuery(T start, T end, RowVector& rs);
void vectorQuery(value_type start, value_type end, RowVector&);
void vectorQuery(const chash& h, T start, T end, RowVector& rs);
void vectorQuery(value_type start, value_type end, RowVector& rs);
Appends matching row IDs to an existing result vector without clearing it.
void traverseForward(const CFields& fs, QueryFunc_ f);
void traverseForward(const CFields& fs, QueryFunc_ f, const chash& h);
Visits rows in forward index order, optionally within a composite-key group. Return false from the callback to stop.
void traverseBackward(const CFields& fs, QueryFunc_ f);
void traverseBackward(const CFields& fs, QueryFunc_ f, const chash& h);
Visits rows in reverse index order, optionally within a composite-key group. Return false from the callback to stop.
void prepare();
Validates and orders staged index values before commit. Floating-point NaN is rejected as an index value.
void commit(const UpdateMap& updateMap, RowId startRowId);
Publishes prepared entries using the table’s row-ID allocation and update map. This is part of the coordinated table commit, not a standalone index transaction.
void clear() noexcept;
Discards staged index entries. Already committed table entries remain unchanged.
void insert_(RowId rowId, const chash& h) noexcept;
Stages a hashed index key using the supplied row offset. This supports index specializations for nonnumeric field types.
template<CCRowId RI> class CTableData_using RowId = RI;
using RowSet = CHashSet<RowId>;
using RowVector = CVector<RowId>;
using QueryFunc_ = std::function<bool(RowId rowId, cvec& r)>;
using UpdateMap = CHashMap<RowId, RowId>;
CTableData_(CTable_<RowId>* x);
Creates staging state for a borrowed table. The table must remain alive throughout use of this adapter.
void dump();
Writes the underlying table’s diagnostic contents.
RowId getCommitRowId_();
Reserves the persistent row-ID range needed for staged data. Used during the coordinated, locked table commit.
bool get_(const CFields& fs, RowId rowId, cvec& r);
void get_(const RowSet& rs, QueryFunc_ f);
void get_(const RowVector& rs, QueryFunc_ f);
Retrieves committed row data by ID or an ID collection. Callback forms stop when the callback returns false; use the table adapter for typed rows.
bool getResolved_(const CFields& fs, RowId rowId, cvec& r);
void getResolved_(const RowSet& rs, QueryFunc_ f);
void getResolved_(const RowVector& rs, QueryFunc_ f);
Retrieves row data while resolving update mappings. This is a table-integration helper rather than a separate user transaction API.
void query_(size_t indexId, uint32_t start, uint32_t end, QueryFunc_ f);
Visits the specified internal index range with row IDs and values. Return false from the callback to stop traversal.
void setQuery_(size_t indexId, uint32_t start, uint32_t end, RowSet& rs);
Adds row IDs from an internal index range to the supplied set.
void vectorQuery_(size_t indexId, uint32_t start, uint32_t end, RowVector& rs);
Appends row IDs from an internal index range to the supplied vector.
void traverseForward_(size_t indexId, QueryFunc_ f);
void traverseForward_(const CFields& fs, QueryFunc_ f);
Traverses committed rows or the specified index in forward order. Callback rows are valid for the duration of the call.
void traverseBackward_(size_t indexId, QueryFunc_ f);
void traverseBackward_(const CFields& fs, QueryFunc_ f);
Traverses committed rows or the specified index in reverse order. Return false from the callback to stop.
Adds a copied or moved row vector to this handle’s staging buffer. It does not publish the row to persistent table data.
void commit_(RowId startRowId) noexcept;
Commits staged row data starting at the allocated persistent row ID. Table adapters coordinate this with index commits.
void rollback_(RowId rowId) noexcept;
Rolls back a reserved commit range after commit preparation fails. The table’s rollback() instead discards pending work before publication.
void erase_(RowId rowId) noexcept;
Marks a row for deletion in the pending update map. No persistent change is made until commit.
void update_(RowId rowId, RowId newRowId) noexcept;
Maps an existing row ID to its staged replacement. Used together with insertion of the replacement row.
RowId rowId() const;
Returns the next staging offset, not a newly allocated persistent row ID.
void clear_() noexcept;
Discards staged rows and update mappings and resets the staging offset.
void reserve_(size_t numRows);
Reserves capacity for pending row vectors without changing their number.
void readLock_();
Acquires shared access to the underlying table. Pair with readUnlock_().
void writeLock_();
Acquires exclusive access to the underlying table. Pair with writeUnlock_().
void readUnlock_();
Releases a shared table lock held by the caller.
void writeUnlock_();
Releases an exclusive table lock held by the caller.
CTable_<RowId>* table();
Returns the borrowed underlying table pointer.
const UpdateMap& updateMap() const;
Returns a borrowed view of pending deletion and replacement mappings for the coordinated commit.
size_t count_() const noexcept;
Returns the committed row count of the underlying table.