casacore
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
casacore::SimpleColumnarFile Class Reference

Class that provides binary table I/O. More...

#include <SimpleColumnarFile.h>

Public Member Functions

 SimpleColumnarFile () noexcept=default
 
 SimpleColumnarFile (const SimpleColumnarFile &rhs)=delete
 
 SimpleColumnarFile (SimpleColumnarFile &&rhs) noexcept
 
 ~SimpleColumnarFile () noexcept=default
 
SimpleColumnarFileoperator= (SimpleColumnarFile &&rhs)
 
void Read (uint64_t row, uint64_t column_offset, std::complex< float > *data, uint64_t n)
 
void Read (uint64_t row, uint64_t column_offset, float *data, uint64_t n)
 
void Read (uint64_t row, uint64_t column_offset, double *data, uint64_t n)
 
void Read (uint64_t row, uint64_t column_offset, int32_t *data, uint64_t n)
 
void Read (uint64_t row, uint64_t column_offset, bool *data, uint64_t n)
 
void Write (uint64_t row, uint64_t column_offset, const std::complex< float > *data, uint64_t n)
 
void Write (uint64_t row, uint64_t column_offset, const std::complex< double > *data, uint64_t n)
 
void Write (uint64_t row, uint64_t column_offset, const float *data, uint64_t n)
 
void Write (uint64_t row, uint64_t column_offset, const double *data, uint64_t n)
 
void Write (uint64_t row, uint64_t column_offset, const int32_t *data, uint64_t n)
 
void Write (uint64_t row, uint64_t column_offset, const bool *data, uint64_t n)
 
void SetStride (uint64_t new_stride)
 Set the number of bytes per row for this file.
 
void AddRows (uint64_t n_rows)
 Adds a given number of rows to the back of the file.
 
void Close ()
 Close the file.
 
void DeleteRow ()
 Deletes the last row.
 
const std::string & Filename () const
 
bool IsOpen () const
 
uint64_t NRows () const
 Total number of rows stored in this file.
 
void ReadHeader (unsigned char *data)
 Read an optional extra header to the file.
 
uint64_t Stride () const
 Total number of bytes in one row.
 
void WriteHeader (const unsigned char *data)
 Write an optional extra header to the file.
 

Static Public Member Functions

static SimpleColumnarFile CreateNew (const std::string &filename, uint64_t header_size, uint64_t stride)
 
static SimpleColumnarFile OpenExisting (const std::string &filename, size_t header_size)
 

Private Member Functions

 SimpleColumnarFile (const std::string &filename, uint64_t header_size, uint64_t stride)
 Create or overwrite a new columnar file on disk.
 
 SimpleColumnarFile (const std::string &filename, size_t header_size)
 Open an existing columnar file.
 
template<typename ValueType >
void ReadImplementation (uint64_t row, uint64_t column_offset, ValueType *data, uint64_t n)
 
template<typename ValueType >
void WriteImplementation (uint64_t row, uint64_t column_offset, const ValueType *data, uint64_t n)
 
- Private Member Functions inherited from casacore::RowBasedFile
 RowBasedFile ()=default
 
 RowBasedFile (const RowBasedFile &rhs)=delete
 
 RowBasedFile (RowBasedFile &&rhs) noexcept
 
 RowBasedFile (const std::string &filename, uint64_t header_size, uint64_t stride)
 Create or overwrite a new columnar file on disk.
 
 RowBasedFile (const std::string &filename, size_t header_size)
 Open an existing columnar file.
 
 ~RowBasedFile () noexcept
 
RowBasedFileoperator= (RowBasedFile &&rhs)
 
void Close ()
 Close the file.
 
void Truncate (uint64_t n_rows)
 
void Seek (off_t pos, int seek_direction)
 
void ReadData (unsigned char *data, uint64_t size)
 
void WriteData (const unsigned char *data, uint64_t size)
 
bool IsOpen () const
 
uint64_t DataLocation () const
 Offset of the first row in the file.
 
const std::string & Filename () const
 
uint64_t HeaderSize () const
 Number of bytes reserved for an optional header.
 
void WriteHeader (const unsigned char *data)
 Write an optional extra header to the file.
 
void ReadHeader (unsigned char *data)
 Read an optional extra header to the file.
 
uint64_t NRows () const
 Total number of rows stored in this file.
 
void SetNRows (uint64_t new_n_rows)
 
uint64_t Stride () const
 Total number of bytes in one row.
 
void SetStride (uint64_t new_stride)
 Set the number of bytes per row for this file.
 
void AddRows (uint64_t n_rows)
 Adds a given number of rows to the back of the file.
 
void DeleteRow ()
 Deletes the last row.
 

Private Attributes

std::vector< unsigned char > packed_buffer_
 This buffer is used temporarily for (un)packing booleans.
 

Detailed Description

Class that provides binary table I/O.

It is similar to BufferedColumnarFile, but is a simple implementation to demonstrate the interface and to test the base class RowBasedFile. For documentation, see BufferedColumnarFile.

This class writes the data in a cell directly to file when Write() is called, and always reads it back when Read() is called.

Definition at line 24 of file SimpleColumnarFile.h.

Constructor & Destructor Documentation

◆ SimpleColumnarFile() [1/5]

casacore::SimpleColumnarFile::SimpleColumnarFile ( )
defaultnoexcept

Referenced by CreateNew(), and OpenExisting().

◆ SimpleColumnarFile() [2/5]

casacore::SimpleColumnarFile::SimpleColumnarFile ( const SimpleColumnarFile rhs)
delete

◆ SimpleColumnarFile() [3/5]

casacore::SimpleColumnarFile::SimpleColumnarFile ( SimpleColumnarFile &&  rhs)
inlinenoexcept

Definition at line 39 of file SimpleColumnarFile.h.

◆ ~SimpleColumnarFile()

casacore::SimpleColumnarFile::~SimpleColumnarFile ( )
defaultnoexcept

◆ SimpleColumnarFile() [4/5]

casacore::SimpleColumnarFile::SimpleColumnarFile ( const std::string &  filename,
uint64_t  header_size,
uint64_t  stride 
)
inlineprivate

Create or overwrite a new columnar file on disk.

Definition at line 125 of file SimpleColumnarFile.h.

◆ SimpleColumnarFile() [5/5]

casacore::SimpleColumnarFile::SimpleColumnarFile ( const std::string &  filename,
size_t  header_size 
)
inlineprivate

Open an existing columnar file.

Definition at line 131 of file SimpleColumnarFile.h.

References packed_buffer_, and Stride().

Member Function Documentation

◆ AddRows()

void casacore::RowBasedFile::AddRows ( uint64_t  n_rows)
inline

Adds a given number of rows to the back of the file.

Definition at line 232 of file RowBasedFile.h.

◆ Close()

void casacore::RowBasedFile::Close ( )
inline

Close the file.

After closing, all calls to I/O functions cause undefined behaviour, until the class is assigned to a new instance.

Truncate failed, still try to close the file to prevent a dangling open file, before throwing the exception.

Definition at line 126 of file RowBasedFile.h.

◆ CreateNew()

static SimpleColumnarFile casacore::SimpleColumnarFile::CreateNew ( const std::string &  filename,
uint64_t  header_size,
uint64_t  stride 
)
inlinestatic

Definition at line 50 of file SimpleColumnarFile.h.

References SimpleColumnarFile().

◆ DeleteRow()

void casacore::RowBasedFile::DeleteRow ( )
inline

Deletes the last row.

Definition at line 237 of file RowBasedFile.h.

◆ Filename()

const std::string & casacore::RowBasedFile::Filename ( ) const
inline

Definition at line 178 of file RowBasedFile.h.

◆ IsOpen()

bool casacore::RowBasedFile::IsOpen ( ) const
inline

Definition at line 172 of file RowBasedFile.h.

◆ NRows()

uint64_t casacore::RowBasedFile::NRows ( ) const
inline

Total number of rows stored in this file.

Definition at line 203 of file RowBasedFile.h.

Referenced by Read(), ReadImplementation(), Write(), and WriteImplementation().

◆ OpenExisting()

static SimpleColumnarFile casacore::SimpleColumnarFile::OpenExisting ( const std::string &  filename,
size_t  header_size 
)
inlinestatic

Definition at line 55 of file SimpleColumnarFile.h.

References SimpleColumnarFile().

◆ operator=()

SimpleColumnarFile & casacore::SimpleColumnarFile::operator= ( SimpleColumnarFile &&  rhs)
inline

Definition at line 44 of file SimpleColumnarFile.h.

References casacore::RowBasedFile::operator=(), and packed_buffer_.

◆ Read() [1/5]

void casacore::SimpleColumnarFile::Read ( uint64_t  row,
uint64_t  column_offset,
bool *  data,
uint64_t  n 
)
inline

◆ Read() [2/5]

void casacore::SimpleColumnarFile::Read ( uint64_t  row,
uint64_t  column_offset,
double *  data,
uint64_t  n 
)
inline

Definition at line 67 of file SimpleColumnarFile.h.

References ReadImplementation().

◆ Read() [3/5]

void casacore::SimpleColumnarFile::Read ( uint64_t  row,
uint64_t  column_offset,
float *  data,
uint64_t  n 
)
inline

Definition at line 64 of file SimpleColumnarFile.h.

References ReadImplementation().

◆ Read() [4/5]

void casacore::SimpleColumnarFile::Read ( uint64_t  row,
uint64_t  column_offset,
int32_t *  data,
uint64_t  n 
)
inline

Definition at line 70 of file SimpleColumnarFile.h.

References ReadImplementation().

◆ Read() [5/5]

void casacore::SimpleColumnarFile::Read ( uint64_t  row,
uint64_t  column_offset,
std::complex< float > *  data,
uint64_t  n 
)
inline

Definition at line 60 of file SimpleColumnarFile.h.

References ReadImplementation().

◆ ReadHeader()

void casacore::RowBasedFile::ReadHeader ( unsigned char *  data)
inline

Read an optional extra header to the file.

See also
WriteHeader().

Definition at line 196 of file RowBasedFile.h.

◆ ReadImplementation()

template<typename ValueType >
void casacore::SimpleColumnarFile::ReadImplementation ( uint64_t  row,
uint64_t  column_offset,
ValueType *  data,
uint64_t  n 
)
inlineprivate

◆ SetStride()

void casacore::SimpleColumnarFile::SetStride ( uint64_t  new_stride)
inline

Set the number of bytes per row for this file.

This changes the format of the file, and because of this the file is emptied.

Definition at line 118 of file SimpleColumnarFile.h.

References packed_buffer_, and casacore::RowBasedFile::SetStride().

◆ Stride()

uint64_t casacore::RowBasedFile::Stride ( ) const
inline

Total number of bytes in one row.

This value is also stored in the file, and is read from the file in OpenExisting().

Definition at line 214 of file RowBasedFile.h.

Referenced by Read(), ReadImplementation(), SimpleColumnarFile(), Write(), and WriteImplementation().

◆ Write() [1/6]

void casacore::SimpleColumnarFile::Write ( uint64_t  row,
uint64_t  column_offset,
const bool *  data,
uint64_t  n 
)
inline

◆ Write() [2/6]

void casacore::SimpleColumnarFile::Write ( uint64_t  row,
uint64_t  column_offset,
const double *  data,
uint64_t  n 
)
inline

Definition at line 96 of file SimpleColumnarFile.h.

References WriteImplementation().

◆ Write() [3/6]

void casacore::SimpleColumnarFile::Write ( uint64_t  row,
uint64_t  column_offset,
const float *  data,
uint64_t  n 
)
inline

Definition at line 92 of file SimpleColumnarFile.h.

References WriteImplementation().

◆ Write() [4/6]

void casacore::SimpleColumnarFile::Write ( uint64_t  row,
uint64_t  column_offset,
const int32_t *  data,
uint64_t  n 
)
inline

Definition at line 100 of file SimpleColumnarFile.h.

References WriteImplementation().

◆ Write() [5/6]

void casacore::SimpleColumnarFile::Write ( uint64_t  row,
uint64_t  column_offset,
const std::complex< double > *  data,
uint64_t  n 
)
inline

Definition at line 88 of file SimpleColumnarFile.h.

References WriteImplementation().

◆ Write() [6/6]

void casacore::SimpleColumnarFile::Write ( uint64_t  row,
uint64_t  column_offset,
const std::complex< float > *  data,
uint64_t  n 
)
inline

Definition at line 84 of file SimpleColumnarFile.h.

References WriteImplementation().

◆ WriteHeader()

void casacore::RowBasedFile::WriteHeader ( const unsigned char *  data)
inline

Write an optional extra header to the file.

When creating the file, the requested space is saved to store this header.

Parameters
dataAn array equal to the size of the header given in the CreateNew() and OpenExisting() calls.

Definition at line 189 of file RowBasedFile.h.

◆ WriteImplementation()

template<typename ValueType >
void casacore::SimpleColumnarFile::WriteImplementation ( uint64_t  row,
uint64_t  column_offset,
const ValueType *  data,
uint64_t  n 
)
inlineprivate

Member Data Documentation

◆ packed_buffer_

std::vector<unsigned char> casacore::SimpleColumnarFile::packed_buffer_
private

This buffer is used temporarily for (un)packing booleans.

Storing it as a member avoids memory allocations.

Definition at line 162 of file SimpleColumnarFile.h.

Referenced by operator=(), Read(), SetStride(), SimpleColumnarFile(), and Write().


The documentation for this class was generated from the following file: