mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-04-04 18:48:38 -04:00
load / save almost functional
This commit is contained in:
parent
faa87fcd10
commit
2c5eb4f946
@ -338,7 +338,7 @@ bool AppFrame::loadSession(std::string fileName) {
|
||||
try {
|
||||
DataNode *header = l.rootNode()->getNext("header");
|
||||
|
||||
std::string version = *header->getNext("version");
|
||||
std::string version(*header->getNext("version"));
|
||||
long long center_freq = *header->getNext("center_freq");
|
||||
long long offset = *header->getNext("offset");
|
||||
|
||||
@ -362,7 +362,7 @@ bool AppFrame::loadSession(std::string fileName) {
|
||||
float squelch_level = demod->hasAnother("squelch_level")?(float)*demod->getNext("squelch_level"):0;
|
||||
int squelch_enabled = demod->hasAnother("squelch_enabled")?(int)*demod->getNext("squelch_enabled"):0;
|
||||
int stereo = demod->hasAnother("stereo")?(int)*demod->getNext("stereo"):0;
|
||||
std::string output_device = demod->hasAnother("output_device")?*demod->getNext("output_device"):"";
|
||||
std::string output_device = demod->hasAnother("output_device")?string(*(demod->getNext("output_device"))):"";
|
||||
|
||||
std::cout << "\tFound demodulator at frequency " << freq << " type " << type << std::endl;
|
||||
std::cout << "\t\tBandwidth: " << bandwidth << std::endl;
|
||||
|
@ -33,23 +33,29 @@ using namespace std;
|
||||
|
||||
#define STRINGIFY(A) #A
|
||||
|
||||
DataElement::DataElement() {
|
||||
data_type = DATA_NULL;
|
||||
data_val = NULL;
|
||||
data_size = 0;
|
||||
unit_size = 0;
|
||||
DataElement::DataElement() : data_type(DATA_NULL), data_val(NULL), data_size(0), unit_size(0) {
|
||||
}
|
||||
|
||||
DataElement::~DataElement() {
|
||||
if (data_val)
|
||||
if (data_val) {
|
||||
delete data_val;
|
||||
data_val = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void DataElement::data_init(long data_size_in) {
|
||||
if (data_val)
|
||||
if (data_val) {
|
||||
delete data_val;
|
||||
data_val = NULL;
|
||||
}
|
||||
data_size = data_size_in;
|
||||
data_val = new char[data_size];
|
||||
if (data_size) {
|
||||
data_val = new char[data_size];
|
||||
}
|
||||
}
|
||||
|
||||
char * DataElement::getDataPointer() {
|
||||
return data_val;
|
||||
}
|
||||
|
||||
int DataElement::getDataType() {
|
||||
@ -84,6 +90,7 @@ DataElementSetNumericDef(DATA_LONGDOUBLE, long double)
|
||||
|
||||
void DataElement::set(const char *data_in, long size_in) {
|
||||
data_type = DATA_VOID;
|
||||
if (!data_size) { return; }
|
||||
data_init(size_in);
|
||||
memcpy(data_val, data_in, data_size);
|
||||
}
|
||||
@ -220,7 +227,9 @@ void DataElement::get(string &str_in) throw (DataTypeMismatchException) {
|
||||
str_in.erase(str_in.begin(), str_in.end());
|
||||
}
|
||||
|
||||
str_in.append(data_val);
|
||||
if (data_val) {
|
||||
str_in.append(data_val);
|
||||
}
|
||||
}
|
||||
|
||||
void DataElement::get(vector<string> &strvect_in) throw (DataTypeMismatchException) {
|
||||
@ -342,20 +351,23 @@ void DataElement::setSerialized(char *ser_str) {
|
||||
|
||||
/* DataNode class */
|
||||
|
||||
DataNode::DataNode() {
|
||||
ptr = 0;
|
||||
parentNode = NULL;
|
||||
DataNode::DataNode(): ptr(0), parentNode(NULL) {
|
||||
data_elem = new DataElement();
|
||||
}
|
||||
|
||||
DataNode::DataNode(const char *name_in) {
|
||||
ptr = 0;
|
||||
DataNode::DataNode(const char *name_in): ptr(0), parentNode(NULL) {
|
||||
node_name = name_in;
|
||||
parentNode = NULL;
|
||||
data_elem = new DataElement();
|
||||
}
|
||||
|
||||
DataNode::~DataNode() {
|
||||
for (vector<DataNode *>::iterator i = children.begin(); i != children.end(); i++) {
|
||||
delete *i;
|
||||
while (children.size()) {
|
||||
DataNode *del = children.back();
|
||||
children.pop_back();
|
||||
delete del;
|
||||
}
|
||||
if (data_elem) {
|
||||
delete data_elem;
|
||||
}
|
||||
}
|
||||
|
||||
@ -364,7 +376,7 @@ void DataNode::setName(const char *name_in) {
|
||||
}
|
||||
|
||||
DataElement *DataNode::element() {
|
||||
return &data_elem;
|
||||
return data_elem;
|
||||
}
|
||||
|
||||
DataNode *DataNode::newChild(const char *name_in) {
|
||||
@ -1541,7 +1553,7 @@ bool DataTree::LoadFromFile(const std::string& filename) {
|
||||
dtHeader.setSerialized(hdr_serialized);
|
||||
DataNode *header = dtHeader.rootNode();
|
||||
|
||||
string compressionType = *header->getNext("compression");
|
||||
string compressionType(*header->getNext("compression"));
|
||||
dataSize = *header->getNext("uncompressed_size");
|
||||
|
||||
bool uncompress = false;
|
||||
|
@ -131,6 +131,7 @@ public:
|
||||
~DataElement();
|
||||
|
||||
int getDataType();
|
||||
char *getDataPointer();
|
||||
long getDataSize();
|
||||
int getUnitSize();
|
||||
|
||||
@ -224,7 +225,7 @@ private:
|
||||
map<string, unsigned int, string_less> childmap_ptr;
|
||||
|
||||
string node_name;
|
||||
DataElement data_elem;
|
||||
DataElement *data_elem;
|
||||
unsigned int ptr;
|
||||
|
||||
|
||||
@ -259,7 +260,8 @@ public:
|
||||
|
||||
void findAll(const char *name_in, vector<DataNode *> &node_list_out);
|
||||
|
||||
operator string () { string s; element()->get(s); return s; }
|
||||
// operator string () { string s; element()->get(s); return s; }
|
||||
operator const char * () { if (element()->getDataType() == DATA_STRING) return element()->getDataPointer(); else return NULL; }
|
||||
operator char () { char v; element()->get(v); return v; }
|
||||
operator unsigned char () { unsigned char v; element()->get(v); return v; }
|
||||
operator int () { int v; element()->get(v); return v; }
|
||||
|
Loading…
Reference in New Issue
Block a user