FormatTraits
FormatTraits
Section titled “FormatTraits”#include <sbio/formats/format_traits.hh>template<typename T, typename IO, typename EPolicy>concept FormatTraitsDefined in src/lib/sbio/formats/format_traits.hh:322
The FormatTraits concept defines a conforming data-format implementation.
A struct implementing the following constraints is both necessary and sufficient to serve as a data-format implementation for the rest of the generic sbio infrastructure.
There are a number of additional concepts which can be used to test for optional APIs and features of a data-format implementation.
The concept is subdivided into a number of sub-concepts for various pieces of the overall API. A conforming struct will look something like the following:
struct ImplementsFormatTraits { // HasBoundedDataDimensions // ------------------------ static constexpr std::size_t HeaderSize { 0 }; static constexpr std::uint16_t MaxRank { 1 }; static constexpr std::uint16_t MaxNameSize { 1 };
// HasCountableDataUnits // --------------------- using DataUnit = void; using StepIdxType = std::size_t; static constexpr StepIdxType ExhaustedSentinel { static_cast<StepIdxType>(-1) };
// CanFindAndConfigureStreams // -------------------------- struct DataSourceParameters {}; static constexpr StreamPartitioningStrategy PartitioningStrategy { StreamPartitioningStrategy::SubDivide }; enum Roles { }; static constexpr std::size_t RoleCount { 0 }; enum class DataAccessPtn : std::uint8_t { }; static constexpr std::size_t DataAccessPtnCount { 0 }; struct StreamParameters {};
template <typename DS> static bool make_stream_brokers(DS& ds, const DataSourceParameters& ds_params, StreamParameters& cfg);
// CanAllocateStorage // ------------------ using BrokerBufferRequirements = TypeList<>; static AllocationRequest<T> get_allocation_request(StreamParameters& cfg); static std::size_t max_batch_count(StreamParameters& cfg);
// HasDataRequest // -------------- struct DataRequest { };
// HasStreamState // -------------- struct MetadataInventory { }; struct DiscoveryState { };
template <class StorageViewT> static auto capacity(const StorageViewT& storage, const DiscoveryState& state);
template <class StorageViewT> static auto current_buffer(StorageViewT& storage, const DiscoveryState& state);
// CanOpenStreams // -------------- template <IOTraits IO> static IOStatus open_streams(Stream<IO, T>* streams, const StreamParameters& cfg);
// CanDiscoverMetadata // ------------------------------------------- template <IOTraits IO, class StorageViewT> static IOStatus discover_metadata(Stream<IO, T>* streams, StorageViewT& storage, MetadataInventory& inv);
// After discovery of metadata, the inventory interface below allows // building topologies and groups. bool entry_matches(std::size_t entry_no, const char* name_query, DataAccessPtn ptn) const; std::pair<const char*, std::uint32_t> metadata_for(std::size_t entry_no) const; std::size_t MetadataInventory::num_entries() const;
// CanIndexStreams [[ OPTIONAL ]] // --------------- template <IOTraits IO, class StorageViewT> static IOStatus index_stream(Stream<IO, T>* streams, StorageViewT& storage, DiscoveryState& stream_state, const StreamParameters& cfg);
// CanFetchStreamData // ------------------ template <IOTraits IO, class StorageViewT> static IOStatus fetch_step(Stream<IO, T>* streams, StorageViewT& storage, DiscoveryState& stream_state, const StreamParameters& cfg, StepIdxType step_idx, DataAccessPtn ptn);
// CanResolveData && CanFillBuffer // ------------------------------- static inline DataResult resolve_data(void* buf, const MetadataInventory& inv, const DataRequest& req); static std::size_t get_payload_size(void* buf);
template <class StorageViewT> static DataResult get_data_in_buffer(StorageViewT& storage, const MetadataInventory& inv, const DataRequest& req, DataAccessPtn ptn, std::size_t batch_idx); };