add configBitstreamParser an base class for all bitstream file parser

This commit is contained in:
Gwenhael Goavec-Merou 2019-10-05 10:27:35 +02:00
parent ea44d71a65
commit d3da23149c
2 changed files with 57 additions and 0 deletions

28
configBitstreamParser.cpp Normal file
View File

@ -0,0 +1,28 @@
#include <iostream>
#include <stdint.h>
#include <strings.h>
#include "configBitstreamParser.hpp"
using namespace std;
ConfigBitstreamParser::ConfigBitstreamParser(string filename, int mode):
_filename(filename), _bit_length(0),
_file_size(0), _fd(filename,
ifstream::in | (ios_base::openmode)mode), _bit_data()
{
if (!_fd.is_open()) {
cerr << "Error: fail to open " << _filename << endl;
throw std::exception();
}
_fd.seekg(0, _fd.end);
_file_size = _fd.tellg();
_fd.seekg(0, _fd.beg);
_bit_data.reserve(_file_size);
}
ConfigBitstreamParser::~ConfigBitstreamParser()
{
_fd.close();
}

29
configBitstreamParser.hpp Normal file
View File

@ -0,0 +1,29 @@
#ifndef CONFIGBITSTREAMPARSER_H
#define CONFIGBITSTREAMPARSER_H
#include <iostream>
#include <fstream>
#include <stdint.h>
class ConfigBitstreamParser {
public:
ConfigBitstreamParser(std::string filename, int mode = ASCII_MODE);
~ConfigBitstreamParser();
virtual int parse() = 0;
uint8_t *getData() {return (uint8_t*)_bit_data.c_str();}
int getLength() {return _bit_length;}
enum {
ASCII_MODE = 0,
BIN_MODE = std::ifstream::binary
};
protected:
std::string _filename;
int _bit_length;
int _file_size;
std::ifstream _fd;
std::string _bit_data;
};
#endif