opatIO-cpp 0.3.0a
Open Parametrized Array Table
Loading...
Searching...
No Matches
opat Namespace Reference

Namespaces

namespace  lattice
 Namespace for table lattice interpolation of OPAT files.
 

Classes

struct  Bounds
 Structure to hold the minimum and maximum values for a dimension. More...
 
struct  CardCatalog
 Structure to hold the catalog of tables in a DataCard. More...
 
struct  CardCatalogEntry
 Structure to hold the index information of a table in an OPAT file. More...
 
struct  CardHeader
 Structure to hold the header information of a DataCard in an OPAT file. More...
 
struct  DataCard
 Structure to hold a DataCard, which contains multiple tables. More...
 
struct  Header
 Structure to hold the header information of an OPAT file. More...
 
struct  OPAT
 Structure to hold the entire OPAT file. More...
 
struct  OPATTable
 Structure to hold the data of an OPAT table. More...
 
struct  Slice
 Structure to represent a slice of data. More...
 
struct  TableIndex
 Structure to hold the index of tables within a DataCard. More...
 
struct  TableIndexEntry
 Structure to hold the index information of a table within a DataCard. More...
 

Functions

bool is_big_endian ()
 Determines if the system is big-endian.
 
bool hasMagic (const std::string &filename)
 Checks if a file has the correct magic number for an OPAT file.
 
OPAT readOPAT (const std::string &filename)
 Reads an OPAT file and returns its contents as an OPAT structure.
 
Header readHeader (std::ifstream &file)
 Reads the header of an OPAT file.
 
CardCatalogEntry readCardCatalogEntry (std::ifstream &file, uint64_t offset, uint16_t numIndex, uint8_t hashPrecision)
 Reads a CardCatalogEntry from the file.
 
CardCatalog readCardCatalog (std::ifstream &file, const Header &header)
 Reads the CardCatalog from the file.
 
std::unordered_map< FloatIndexVector, DataCardreadDataCards (std::ifstream &file, const Header &header, const CardCatalog &cardCatalog)
 Reads all DataCards from the file.
 
DataCard readDataCard (std::ifstream &file, const CardCatalogEntry &entry)
 Reads a single DataCard from the file.
 
CardHeader readDataCardHeader (std::ifstream &file, const CardCatalogEntry &entry)
 Reads the header of a DataCard from the file.
 
TableIndex readTableIndex (std::ifstream &file, const CardCatalogEntry &entry, const CardHeader &header)
 Reads the TableIndex from a DataCard.
 
OPATTable readOPATTable (std::ifstream &file, const CardCatalogEntry &cardEntry, const TableIndexEntry &tableEntry)
 Reads an OPATTable from the file.
 
std::ostream & operator<< (std::ostream &os, const Header &header)
 
std::ostream & operator<< (std::ostream &os, const CardHeader &header)
 
std::ostream & operator<< (std::ostream &os, const CardCatalogEntry &entry)
 
std::ostream & operator<< (std::ostream &os, const CardCatalog &catalog)
 
std::ostream & operator<< (std::ostream &os, const TableIndexEntry &entry)
 
std::ostream & operator<< (std::ostream &os, const TableIndex &index)
 
std::ostream & operator<< (std::ostream &os, const OPATTable &table)
 
std::ostream & operator<< (std::ostream &os, const DataCard &card)
 
std::ostream & operator<< (std::ostream &os, const OPAT &opat)
 
std::ostream & operator<< (std::ostream &os, const Slice &slice)
 
std::ostream & operator<< (std::ostream &os, const Bounds &bounds)
 
template<typename T>
swap_bytes (T value)
 Swaps the byte order of a value.
 

Function Documentation

◆ hasMagic()

bool opat::hasMagic ( const std::string & filename)

Checks if a file has the correct magic number for an OPAT file.

This function reads the first four bytes of the file and compares them to the expected "OPAT" magic number.

Parameters
filenamePath to the file.
Returns
True if the file has the correct magic number, false otherwise.

Example:

bool isValid = opat::hasMagic("example.opat");
if (isValid) {
std::cout << "Valid OPAT file!" << std::endl;
}
bool hasMagic(const std::string &filename)
Checks if a file has the correct magic number for an OPAT file.
Definition opatIO.cpp:46

◆ is_big_endian()

bool opat::is_big_endian ( )

Determines if the system is big-endian.

This utility function checks the system's endianness by examining the byte order of a test value.

Returns
True if the system is big-endian, false otherwise.

Example:

std::cout << "System is big-endian." << std::endl;
}
bool is_big_endian()
Determines if the system is big-endian.
Definition opatIO.cpp:40

◆ operator<<() [1/11]

std::ostream & opat::operator<< ( std::ostream & os,
const Bounds & bounds )
Parameters
osOutput stream.
boundsBounds to print.
Returns
Reference to the output stream.

◆ operator<<() [2/11]

std::ostream & opat::operator<< ( std::ostream & os,
const CardCatalog & catalog )
Parameters
osOutput stream.
catalogCardCatalog to print.
Returns
Reference to the output stream.

◆ operator<<() [3/11]

std::ostream & opat::operator<< ( std::ostream & os,
const CardCatalogEntry & entry )
Parameters
osOutput stream.
entryCardCatalogEntry to print.
Returns
Reference to the output stream.

◆ operator<<() [4/11]

std::ostream & opat::operator<< ( std::ostream & os,
const CardHeader & header )
Parameters
osOutput stream.
headerCardHeader to print.
Returns
Reference to the output stream.

◆ operator<<() [5/11]

std::ostream & opat::operator<< ( std::ostream & os,
const DataCard & card )
Parameters
osOutput stream.
cardDataCard to print.
Returns
Reference to the output stream.

◆ operator<<() [6/11]

std::ostream & opat::operator<< ( std::ostream & os,
const Header & header )
Parameters
osOutput stream.
headerHeader to print.
Returns
Reference to the output stream.

◆ operator<<() [7/11]

std::ostream & opat::operator<< ( std::ostream & os,
const OPAT & opat )
Parameters
osOutput stream.
opatOPAT structure to print.
Returns
Reference to the output stream.

◆ operator<<() [8/11]

std::ostream & opat::operator<< ( std::ostream & os,
const OPATTable & table )

◆ operator<<() [9/11]

std::ostream & opat::operator<< ( std::ostream & os,
const Slice & slice )
Parameters
osOutput stream.
sliceSlice to print.
Returns
Reference to the output stream.

◆ operator<<() [10/11]

std::ostream & opat::operator<< ( std::ostream & os,
const TableIndex & index )
Parameters
osOutput stream.
indexTableIndex to print.
Returns
Reference to the output stream.

◆ operator<<() [11/11]

std::ostream & opat::operator<< ( std::ostream & os,
const TableIndexEntry & entry )
Parameters
osOutput stream.
entryTableIndexEntry to print.
Returns
Reference to the output stream.

◆ readCardCatalog()

CardCatalog opat::readCardCatalog ( std::ifstream & file,
const Header & header )

Reads the CardCatalog from the file.

This function reads all entries in the card catalog, using the header information to determine the number of entries and their locations.

Parameters
fileInput file stream.
headerThe header of the OPAT file.
Returns
A CardCatalog structure.
Exceptions
std::runtime_errorif the card catalog cannot be read or is incomplete.

Example:

std::ifstream file("example.opat", std::ios::binary);
opat::CardCatalog catalog = opat::readCardCatalog(file, header);
std::cout << catalog << std::endl;
CardCatalog readCardCatalog(std::ifstream &file, const Header &header)
Reads the CardCatalog from the file.
Definition opatIO.cpp:149
Header readHeader(std::ifstream &file)
Reads the header of an OPAT file.
Definition opatIO.cpp:109
Structure to hold the catalog of tables in a DataCard.
Definition opatIO.h:150
Structure to hold the header information of an OPAT file.
Definition opatIO.h:73

◆ readCardCatalogEntry()

CardCatalogEntry opat::readCardCatalogEntry ( std::ifstream & file,
uint64_t offset,
uint16_t numIndex,
uint8_t hashPrecision )

Reads a CardCatalogEntry from the file.

This function reads a single entry from the card catalog, including its index, byte range, and SHA-256 hash. It also performs byte-swapping for compatibility with big-endian systems.

Parameters
fileInput file stream.
offsetOffset to the entry in the file.
numIndexNumber of indices in the entry.
hashPrecisionPrecision of the hash used for validation.
Returns
A CardCatalogEntry structure.
Exceptions
std::runtime_errorif the entry cannot be read or is incomplete.

Example:

std::ifstream file("example.opat", std::ios::binary);
std::cout << entry << std::endl;
CardCatalogEntry readCardCatalogEntry(std::ifstream &file, uint64_t offset, uint16_t numIndex, uint8_t hashPrecision)
Reads a CardCatalogEntry from the file.
Definition opatIO.cpp:127
Structure to hold the index information of a table in an OPAT file.
Definition opatIO.h:130

◆ readDataCard()

DataCard opat::readDataCard ( std::ifstream & file,
const CardCatalogEntry & entry )

Reads a single DataCard from the file.

This function reads the header, table index, and table data for a single DataCard.

Parameters
fileInput file stream.
entryThe CardCatalogEntry for the DataCard.
Returns
A DataCard structure.
Exceptions
std::runtime_errorif the DataCard cannot be read or is incomplete.

Example:

std::ifstream file("example.opat", std::ios::binary);
opat::CardCatalogEntry entry = ...; // Retrieved from the catalog
opat::DataCard card = opat::readDataCard(file, entry);
DataCard readDataCard(std::ifstream &file, const CardCatalogEntry &entry)
Reads a single DataCard from the file.
Definition opatIO.cpp:173
Structure to hold a DataCard, which contains multiple tables.
Definition opatIO.h:409

◆ readDataCardHeader()

CardHeader opat::readDataCardHeader ( std::ifstream & file,
const CardCatalogEntry & entry )

Reads the header of a DataCard from the file.

This function reads the header structure of a DataCard and performs byte-swapping for compatibility with big-endian systems.

Parameters
fileInput file stream.
entryThe CardCatalogEntry for the DataCard.
Returns
A CardHeader structure.
Exceptions
std::runtime_errorif the DataCard header cannot be read or is incomplete.

Example:

std::ifstream file("example.opat", std::ios::binary);
opat::CardCatalogEntry entry = ...; // Retrieved from the catalog
CardHeader readDataCardHeader(std::ifstream &file, const CardCatalogEntry &entry)
Reads the header of a DataCard from the file.
Definition opatIO.cpp:192
Structure to hold the header information of a DataCard in an OPAT file.
Definition opatIO.h:105

◆ readDataCards()

std::unordered_map< FloatIndexVector, DataCard > opat::readDataCards ( std::ifstream & file,
const Header & header,
const CardCatalog & cardCatalog )

Reads all DataCards from the file.

This function reads all DataCards in the OPAT file, using the card catalog to locate each card and its associated data.

Parameters
fileInput file stream.
headerThe header of the OPAT file.
cardCatalogThe CardCatalog of the OPAT file.
Returns
A map of index vectors to DataCards.
Exceptions
std::runtime_errorif any DataCard cannot be read or is incomplete.

Example:

std::ifstream file("example.opat", std::ios::binary);
opat::CardCatalog catalog = opat::readCardCatalog(file, header);
auto cards = opat::readDataCards(file, header, catalog);
std::unordered_map< FloatIndexVector, DataCard > readDataCards(std::ifstream &file, const Header &header, const CardCatalog &cardCatalog)
Reads all DataCards from the file.
Definition opatIO.cpp:163

◆ readHeader()

Header opat::readHeader ( std::ifstream & file)

Reads the header of an OPAT file.

This function reads the header structure from the file and performs byte-swapping if the system is big-endian.

Parameters
fileInput file stream positioned at the start of the header.
Returns
A Header structure containing the file's metadata.
Exceptions
std::runtime_errorif the header cannot be read or is incomplete.

Example:

std::ifstream file("example.opat", std::ios::binary);
header.print();
void print() const
Prints the header information to the console.
Definition opatIO.cpp:257

◆ readOPAT()

OPAT opat::readOPAT ( const std::string & filename)

Reads an OPAT file and returns its contents as an OPAT structure.

This function validates the file's magic number, reads the header, card catalog, and all data cards, and constructs an OPAT object representing the file's contents.

Parameters
filenamePath to the OPAT file.
Returns
An OPAT structure containing the file's data.
Exceptions
std::runtime_errorif the file cannot be opened, is invalid, or has an incorrect magic number.

Example:

OPAT file = opat::readOPAT("example.opat");
std::cout << file.header << std::endl;
OPAT readOPAT(const std::string &filename)
Reads an OPAT file and returns its contents as an OPAT structure.
Definition opatIO.cpp:76
Structure to hold the entire OPAT file.
Definition opatIO.h:502
Header header
Header of the OPAT file.
Definition opatIO.h:503

◆ readOPATTable()

OPATTable opat::readOPATTable ( std::ifstream & file,
const CardCatalogEntry & cardEntry,
const TableIndexEntry & tableEntry )

Reads an OPATTable from the file.

This function reads the row values, column values, and data for a single table within a DataCard.

Parameters
fileInput file stream.
cardEntryThe CardCatalogEntry for the DataCard.
tableEntryThe TableIndexEntry for the table.
Returns
An OPATTable structure.
Exceptions
std::runtime_errorif the table cannot be read or is incomplete.

Example:

std::ifstream file("example.opat", std::ios::binary);
opat::CardCatalogEntry cardEntry = ...; // Retrieved from the catalog
opat::TableIndexEntry tableEntry = ...; // Retrieved from the table index
opat::OPATTable table = opat::readOPATTable(file, cardEntry, tableEntry);
OPATTable readOPATTable(std::ifstream &file, const CardCatalogEntry &cardEntry, const TableIndexEntry &tableEntry)
Reads an OPATTable from the file.
Definition opatIO.cpp:231
Structure to hold the data of an OPAT table.
Definition opatIO.h:259
Structure to hold the index information of a table within a DataCard.
Definition opatIO.h:168

◆ readTableIndex()

TableIndex opat::readTableIndex ( std::ifstream & file,
const CardCatalogEntry & entry,
const CardHeader & header )

Reads the TableIndex from a DataCard.

This function reads the table index of a DataCard, which maps table tags to their metadata and locations within the card.

Parameters
fileInput file stream.
entryThe CardCatalogEntry for the DataCard.
headerThe CardHeader of the DataCard.
Returns
A TableIndex structure.
Exceptions
std::runtime_errorif the TableIndex cannot be read or is incomplete.

Example:

std::ifstream file("example.opat", std::ios::binary);
opat::CardCatalogEntry entry = ...; // Retrieved from the catalog
opat::TableIndex index = opat::readTableIndex(file, entry, header);
TableIndex readTableIndex(std::ifstream &file, const CardCatalogEntry &entry, const CardHeader &header)
Reads the TableIndex from a DataCard.
Definition opatIO.cpp:209
Structure to hold the index of tables within a DataCard.
Definition opatIO.h:194

◆ swap_bytes()

template<typename T>
T opat::swap_bytes ( T value)

Swaps the byte order of a value.

This function is useful for handling endianness when reading binary files. It ensures compatibility across systems with different byte orders.

Template Parameters
TThe type of the value (must be trivially copyable).
Parameters
valueThe value to swap.
Returns
The value with its byte order reversed.

Example:

uint16_t value = 0x1234;
uint16_t swapped = opat::swap_bytes(value);
T swap_bytes(T value)
Swaps the byte order of a value.
Definition opatIO.h:826