24#include <core/exceptions/system.h>
25#include <fvutils/fileformat/fvfile.h>
26#include <netinet/in.h>
28#include <utils/misc/strndup.h>
96 comment_ = strdup(
"");
125 for (bi_ = blocks_.begin(); bi_ != blocks_.end(); ++bi_) {
136#if BYTE_ORDER_ == BIG_ENDIAN_
142 comment_ = strdup(
"");
197 comment_ = strndup(comment, FVFF_COMMENT_SIZE);
198 strncpy(header_->
comment, comment, FVFF_COMMENT_SIZE - 1);
209 owns_blocks_ = owns_blocks;
218 return blocks_.size();
227 blocks_.push_back(block);
245 FILE *f = fopen(file_name,
"w");
249 "Could not open rectlut file "
253 header_->
num_blocks = (
unsigned int)blocks_.size();
255 gettimeofday(&t, NULL);
274 for (bi_ = blocks_.begin(); bi_ != blocks_.end(); ++bi_) {
277 if (fwrite((*bi_)->block_memptr(), (*bi_)->block_size(), 1, f) != 1) {
292 FILE *f = fopen(file_name,
"r");
296 "Could not open rectlut file "
310 throw Exception(
"Unknown magic in fvff file (read: 0x%04x req: 0x%04x)",
315 if (header_->
version != version_) {
317 throw Exception(
"Unsupported version of fvff file (read: %u req: %u)",
323#
if BYTE_ORDER_ == BIG_ENDIAN_
330 throw Exception(
"FVFile header cannot be translated for endianess by now");
334 comment_ = strndup(header_->
comment, FVFF_COMMENT_SIZE);
348 throw FileReadException(file_name, errno,
"Reading content specific header failed");
353 for (
unsigned int b = 0; b < header_->
num_blocks && !feof(f); ++b) {
356 if (fread(&bh,
sizeof(bh), 1, f) != 1) {
360 "Could not read block info header while there should be one");
362 void *spec_header = NULL;
376 throw FileReadException(file_name, errno,
"Could not read content specific block header");
392 blocks_.push_back(block);
408 f = fopen(filename,
"r");
412 throw FileReadException(filename, errno,
"Could not read magic token from file");
416 throw FileReadException(filename, errno,
"Could not read magic token from file");
File could not be opened.
Base class for exceptions in Fawkes.
System ran out of memory and desired operation could not be fulfilled.
FireVision File Format data block.
void * data_ptr() const
Get data pointer.
unsigned int version()
Get the version of the file.
virtual void read(const char *file_name)
Read file.
void * _spec_header
Content specific header.
unsigned int magic_token()
Get the magic token of the file.
FireVisionDataFile(unsigned short int magic_token, unsigned short int version)
Constructor.
virtual void clear()
Clear internal storage.
size_t num_blocks()
Get the number of available info blocks.
bool is_little_endian()
Check if data is encoded as little endian.
size_t _spec_header_size
Size in bytes of _spec_header.
static unsigned short int read_magic_token(const char *filename)
Get magic token from file.
void set_comment(const char *comment)
Set comment.
virtual void add_block(FireVisionDataFileBlock *block)
Add a block.
std::list< FireVisionDataFileBlock * > BlockList
List of FireVision data file blocks.
const char * get_comment() const
Get comment.
static bool has_magic_token(const char *filename, unsigned short int magic_token)
Check if file has a certain magic token.
bool is_big_endian()
Check if data is encoded as big endian.
virtual void write(const char *file_name)
Write file.
void set_owns_blocks(bool owns_blocks)
Lets the file take over the ownership and give up the ownership of the blocks, respectively.
BlockList & blocks()
Get blocks.
virtual ~FireVisionDataFile()
Destructor.
Fawkes library namespace.