361 lines
6.6 KiB
C
361 lines
6.6 KiB
C
|
#pragma once
|
||
|
#include <string>
|
||
|
#include <fstream>
|
||
|
#include <vector>
|
||
|
#include <map>
|
||
|
#include <list>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
#define BIN_VECTOR 1
|
||
|
#define BIN_CHAIN 3
|
||
|
|
||
|
class BPBinary
|
||
|
{
|
||
|
|
||
|
public:
|
||
|
struct BHeader {
|
||
|
unsigned int id;
|
||
|
unsigned int datasize;
|
||
|
};
|
||
|
|
||
|
struct FixedHeader
|
||
|
{
|
||
|
BHeader* header;
|
||
|
string description_of_content;
|
||
|
explicit FixedHeader() {
|
||
|
header = new BHeader;
|
||
|
}
|
||
|
~FixedHeader()
|
||
|
{
|
||
|
if (header)delete header;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct Version {
|
||
|
BHeader* header;
|
||
|
int major;
|
||
|
int minor;
|
||
|
explicit Version() {
|
||
|
header = new BHeader;
|
||
|
}
|
||
|
~Version() {
|
||
|
if (header)delete header;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct BFilePath {
|
||
|
BHeader* header;
|
||
|
string path;
|
||
|
explicit BFilePath() {
|
||
|
header = new BHeader;
|
||
|
}
|
||
|
~BFilePath()
|
||
|
{
|
||
|
if (header)delete header;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct Root {
|
||
|
BHeader* header;
|
||
|
FixedHeader* fixed_header;
|
||
|
Version* version;
|
||
|
BFilePath* file_path;
|
||
|
explicit Root() {
|
||
|
header = new BHeader;
|
||
|
fixed_header = new FixedHeader;
|
||
|
version = new Version;
|
||
|
file_path = new BFilePath;
|
||
|
}
|
||
|
~Root()
|
||
|
{
|
||
|
if (header)delete header;
|
||
|
if (fixed_header)delete fixed_header;
|
||
|
if (version)delete version;
|
||
|
if (file_path)delete file_path;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct B210Session {
|
||
|
BHeader* header;
|
||
|
char* pdata;
|
||
|
explicit B210Session() {
|
||
|
header = new BHeader;
|
||
|
pdata = nullptr;
|
||
|
}
|
||
|
~B210Session() {
|
||
|
if (header)delete header;
|
||
|
if (pdata)delete[] pdata;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
enum DBT {
|
||
|
VECTOR = 1,
|
||
|
CHAIN=3,
|
||
|
UNDEFINED=4
|
||
|
};
|
||
|
|
||
|
struct DataBlockType {
|
||
|
BHeader* header;
|
||
|
DBT btype;
|
||
|
explicit DataBlockType() {
|
||
|
header = new BHeader;
|
||
|
}
|
||
|
~DataBlockType() {
|
||
|
if (header)delete header;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct B2121Session {
|
||
|
BHeader* header;
|
||
|
unsigned int ivalue;
|
||
|
explicit B2121Session() {
|
||
|
header = new BHeader;
|
||
|
}
|
||
|
~B2121Session() {
|
||
|
if (header)delete header;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct B2122Session {
|
||
|
BHeader* header;
|
||
|
unsigned int ivalue;
|
||
|
explicit B2122Session() {
|
||
|
header = new BHeader;
|
||
|
}
|
||
|
~B2122Session() {
|
||
|
if (header)delete header;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct B2123Session {
|
||
|
BHeader* header;
|
||
|
unsigned int ivalue;
|
||
|
explicit B2123Session() {
|
||
|
header = new BHeader;
|
||
|
}
|
||
|
~B2123Session() {
|
||
|
if (header)delete header;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct VectorPoint {
|
||
|
float x1;
|
||
|
float y1;
|
||
|
float x2;
|
||
|
float y2;
|
||
|
VectorPoint() {}
|
||
|
VectorPoint(float _x1, float _y1, float _x2, float _y2)
|
||
|
:x1(_x1)
|
||
|
,y1(_y1)
|
||
|
,x2(_x2)
|
||
|
,y2(_y2)
|
||
|
{}
|
||
|
};
|
||
|
|
||
|
struct BPoint {
|
||
|
float x;
|
||
|
float y;
|
||
|
BPoint() {}
|
||
|
BPoint(float _x, float _y)
|
||
|
:x(_x)
|
||
|
,y(_y)
|
||
|
{}
|
||
|
};
|
||
|
|
||
|
struct ChainPoint {
|
||
|
unsigned int num_of_point;
|
||
|
//BPoint* points;
|
||
|
//ChainPoint* pnext;
|
||
|
std::vector<BPoint*> points;
|
||
|
|
||
|
ChainPoint() {
|
||
|
num_of_point = 0;
|
||
|
//points = NULL;
|
||
|
//pnext = NULL;
|
||
|
}
|
||
|
~ChainPoint() {
|
||
|
for (size_t i = 0; i < points.size();++i) {
|
||
|
delete points[i];
|
||
|
points[i] = NULL;
|
||
|
}
|
||
|
points.clear();
|
||
|
//delete[] points;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct Coordinates {
|
||
|
BHeader* header;
|
||
|
std::vector<void*> point_indexs;
|
||
|
explicit Coordinates() {
|
||
|
header = new BHeader;
|
||
|
}
|
||
|
|
||
|
~Coordinates() {
|
||
|
if (header)delete header;
|
||
|
for (size_t i = 0; i < point_indexs.size(); ++i) {
|
||
|
delete point_indexs[i];
|
||
|
point_indexs[i] = NULL;
|
||
|
}
|
||
|
point_indexs.clear();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct DataBlock {
|
||
|
BHeader* header;
|
||
|
DataBlockType* data_block_type;
|
||
|
B2121Session* b2121;
|
||
|
B2122Session* b2122;
|
||
|
B2123Session* b2123;
|
||
|
Coordinates* coordinates;
|
||
|
explicit DataBlock() {
|
||
|
header = new BHeader;
|
||
|
data_block_type = nullptr;
|
||
|
b2121=nullptr;
|
||
|
b2122 = nullptr;
|
||
|
b2123 = nullptr;
|
||
|
coordinates = nullptr;
|
||
|
}
|
||
|
|
||
|
~DataBlock() {
|
||
|
if (header)delete header;
|
||
|
if (data_block_type!=nullptr)delete data_block_type;
|
||
|
if (b2121 != nullptr)delete b2121;
|
||
|
if (b2122 != nullptr)delete b2122;
|
||
|
if (b2123 != nullptr)delete b2123;
|
||
|
if (coordinates != nullptr)delete coordinates;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct BinDataBlock {
|
||
|
unsigned char type;
|
||
|
std::vector<void*> point_indexs;
|
||
|
unsigned int byteCount;
|
||
|
explicit BinDataBlock() {
|
||
|
byteCount = 0;
|
||
|
}
|
||
|
void Copy(BinDataBlock* db)
|
||
|
{
|
||
|
if (!db)return;
|
||
|
db->type = type;
|
||
|
db->byteCount = byteCount;
|
||
|
for (size_t i = 0; i < point_indexs.size(); ++i) {
|
||
|
if (type == VECTOR) {
|
||
|
VectorPoint* point = (VectorPoint*)point_indexs[i];
|
||
|
BPBinary::VectorPoint* pvp = new BPBinary::VectorPoint();
|
||
|
pvp->x1 = point->x1;
|
||
|
pvp->x2 = point->x2;
|
||
|
pvp->y1 = point->y1;
|
||
|
pvp->y2 = point->y2;
|
||
|
db->point_indexs.push_back(pvp);
|
||
|
}
|
||
|
else if (type == CHAIN)
|
||
|
{
|
||
|
ChainPoint* temppoint = (ChainPoint*)point_indexs[i];
|
||
|
BPBinary::ChainPoint* cpoint = new BPBinary::ChainPoint();
|
||
|
cpoint->num_of_point = temppoint->num_of_point;
|
||
|
for (unsigned int chainPointIndex = 0; chainPointIndex < temppoint->num_of_point; ++chainPointIndex) {
|
||
|
BPBinary::BPoint* btemppoint = temppoint->points[chainPointIndex];
|
||
|
BPBinary::BPoint* bpoint = new BPBinary::BPoint();
|
||
|
bpoint->x = btemppoint->x;
|
||
|
bpoint->y = btemppoint->y;
|
||
|
cpoint->points.push_back(bpoint);
|
||
|
}
|
||
|
db->point_indexs.push_back(cpoint);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
~BinDataBlock() {
|
||
|
for (size_t i = 0; i < point_indexs.size();++i) {
|
||
|
if (type== VECTOR) {
|
||
|
VectorPoint* point = (VectorPoint*)point_indexs[i];
|
||
|
delete point;
|
||
|
}
|
||
|
else if (type == CHAIN)
|
||
|
{
|
||
|
ChainPoint* point = (ChainPoint*)point_indexs[i];
|
||
|
delete point;
|
||
|
}else delete point_indexs[i];
|
||
|
point_indexs[i] = NULL;
|
||
|
}
|
||
|
point_indexs.clear();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct Layer {
|
||
|
BHeader* header;
|
||
|
B210Session* b210;
|
||
|
|
||
|
vector<DataBlock*> data_blocks;
|
||
|
explicit Layer() {
|
||
|
header = new BHeader;
|
||
|
b210 = nullptr;
|
||
|
}
|
||
|
~Layer() {
|
||
|
if (header)delete header;
|
||
|
if (b210!=nullptr)delete b210;
|
||
|
for (size_t i = 0; i < data_blocks.size(); ++i) {
|
||
|
delete data_blocks[i];
|
||
|
data_blocks[i] = NULL;
|
||
|
}
|
||
|
data_blocks.clear();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct Layers
|
||
|
{
|
||
|
BHeader* header;
|
||
|
vector<Layer*> layers;
|
||
|
explicit Layers() {
|
||
|
header = new BHeader;
|
||
|
}
|
||
|
~Layers() {
|
||
|
if (header)delete header;
|
||
|
for (size_t i = 0; i < layers.size(); ++i) {
|
||
|
delete layers[i];
|
||
|
layers[i] = NULL;
|
||
|
}
|
||
|
layers.clear();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
public:
|
||
|
struct BFileInfo
|
||
|
{
|
||
|
string file_name;
|
||
|
string file_path;
|
||
|
};
|
||
|
|
||
|
|
||
|
public:
|
||
|
BPBinary(BFileInfo info);
|
||
|
~BPBinary();
|
||
|
bool LoadFile();
|
||
|
BFileInfo GetBFileInfo() {
|
||
|
return m_file_info;
|
||
|
}
|
||
|
DataBlock* GetDataBlock(unsigned int index) {
|
||
|
return m_data_block_map[index];
|
||
|
}
|
||
|
|
||
|
|
||
|
private:
|
||
|
void ReadRoot(ifstream& dataSteam);
|
||
|
void ReadLayers(ifstream& dataSteam);
|
||
|
void ReadLayer(ifstream& dataSteam, Layer* layer);
|
||
|
void ReadDataBlock(ifstream& dataSteam, DataBlock* datablock);
|
||
|
void ReadChains(ifstream& dataSteam, ChainPoint* chainPoint);
|
||
|
|
||
|
public:
|
||
|
Root* m_root;
|
||
|
Layers* m_layers;
|
||
|
|
||
|
|
||
|
private:
|
||
|
BFileInfo m_file_info;
|
||
|
map<unsigned int, DataBlock*> m_data_block_map;
|
||
|
};
|
||
|
|