libgta 1.2.1 Read and Write Generic Tagged Array (GTA) files

Examples written in C++: Stream-based input/output
/* This file is in the public domain. */
#include <iostream>
#include <fstream>
#include <exception>
#include <limits>
#include <vector>
#include <gta/gta.hpp>
/* This example transforms an input GTA into an output GTA.
* It reads, manipulates and writes the array elements one at a time; the array
* data does not have to fit into memory. */
int main(void)
{
try {
/* Initialize input */
std::ifstream instream("input.gta", std::ios::in | std::ios::binary);
gta::header inheader;
gta::io_state instate;
/* Initialize output */
std::ofstream outstream("output.gta", std::ios::out | std::ios::binary);
gta::header outheader;
gta::io_state outstate;
/* Copy the GTA header */
inheader.read_from(instream);
outheader = inheader;
outheader.write_to(outstream);
/* Copy the array data */
if (inheader.element_size() > std::numeric_limits<size_t>::max()) {
throw std::exception();
}
std::vector<char> element(inheader.element_size());
for (uintmax_t i = 0; i < inheader.elements(); i++) {
inheader.read_elements(instate, instream, 1, &(element[0]));
/* ... manipulate the element ... */
outheader.write_elements(outstate, outstream, 1, &(element[0]));
}
}
catch (std::exception &e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}
gta::header
The GTA header.
Definition: gta.hpp:702
gta::header::elements
uintmax_t elements() const
Get the total number of elements in the array.
Definition: gta.hpp:1052
gta::header::read_elements
void read_elements(io_state &state, custom_io &io, uintmax_t n, void *buf) const
Read array elements.
Definition: gta.hpp:1766
gta::header::element_size
uintmax_t element_size() const
Get the element size.
Definition: gta.hpp:955
gta::header::write_elements
void write_elements(io_state &state, custom_io &io, uintmax_t n, const void *buf) const
Write array elements.
Definition: gta.hpp:1839
gta::header::write_to
void write_to(custom_io &io) const
Write a header.
Definition: gta.hpp:876
gta::header::read_from
void read_from(custom_io &io)
Read a header.
Definition: gta.hpp:819
gta::io_state
State for element-based input and output.
Definition: gta.hpp:636
gta.hpp
The libgta C++ interface.