From 2f84df3c47d72de48fde03cbced07d597ff33eed Mon Sep 17 00:00:00 2001 From: vsonnier Date: Fri, 8 Jun 2018 05:58:55 +0200 Subject: [PATCH] Make DataTree throw exception objects, instead of dynamically allocated ones for simplicity --- src/AppFrame.cpp | 6 +++--- src/BookmarkMgr.cpp | 6 ++---- src/demod/DemodulatorMgr.cpp | 6 ++---- src/util/DataTree.cpp | 16 ++++++++-------- src/util/DataTree.h | 2 +- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index c29efbb..0248d64 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -2485,10 +2485,10 @@ bool AppFrame::loadSession(std::string fileName) { std::cout << "Loading session file version: '" << version << "'..." << std::endl; } - catch (DataTypeMismatchException* e) { + catch (DataTypeMismatchException e) { //this is for managing the old session format NOT encoded as std:wstring, //force current version - std::cout << "Warning while Loading session file version, probably old format :'" << e->what() << "' please consider re-saving the current session..." << std::endl; + std::cout << "Warning while Loading session file version, probably old format :'" << e.what() << "' please consider re-saving the current session..." << std::endl << std::flush; version = wxString(CUBICSDR_VERSION).ToStdWstring(); } } @@ -2612,7 +2612,7 @@ bool AppFrame::loadSession(std::string fileName) { if (loadedActiveDemod || newDemod) { wxGetApp().getDemodMgr().setActiveDemodulator(loadedActiveDemod?loadedActiveDemod:newDemod, false); } - } catch (DataTypeMismatchException &e) { + } catch (DataTypeMismatchException e) { std::cout << e.what() << std::endl; return false; } diff --git a/src/BookmarkMgr.cpp b/src/BookmarkMgr.cpp index 661b9dd..a9db129 100644 --- a/src/BookmarkMgr.cpp +++ b/src/BookmarkMgr.cpp @@ -582,9 +582,8 @@ std::wstring BookmarkMgr::getSafeWstringValue(DataNode* node, const std::string& try { childNode->element()->get(decodedWString); - } catch (DataTypeMismatchException* e) { + } catch (DataTypeMismatchException e) { //2) wstring decode fail, try simple std::string - delete e; std::string decodedStdString; try { @@ -593,9 +592,8 @@ std::wstring BookmarkMgr::getSafeWstringValue(DataNode* node, const std::string& //use wxString for a clean conversion to a wstring: decodedWString = wxString(decodedStdString).ToStdWstring(); - } catch (DataTypeMismatchException* e) { + } catch (DataTypeMismatchException e) { //nothing works, return an empty string. - delete e; decodedWString = L""; } } diff --git a/src/demod/DemodulatorMgr.cpp b/src/demod/DemodulatorMgr.cpp index 80d2d9b..63ea9e3 100644 --- a/src/demod/DemodulatorMgr.cpp +++ b/src/demod/DemodulatorMgr.cpp @@ -443,9 +443,8 @@ std::wstring DemodulatorMgr::getSafeWstringValue(DataNode* node) { try { node->element()->get(decodedWString); - } catch (DataTypeMismatchException* e) { + } catch (DataTypeMismatchException e) { //2) wstring decode fail, try simple std::string - delete e; std::string decodedStdString; try { @@ -454,8 +453,7 @@ std::wstring DemodulatorMgr::getSafeWstringValue(DataNode* node) { //use wxString for a clean conversion to a wstring: decodedWString = wxString(decodedStdString).ToStdWstring(); - } catch (DataTypeMismatchException* e) { - delete e; + } catch (DataTypeMismatchException e) { //nothing works, return an empty string. decodedWString = L""; } diff --git a/src/util/DataTree.cpp b/src/util/DataTree.cpp index 850e257..3c25885 100755 --- a/src/util/DataTree.cpp +++ b/src/util/DataTree.cpp @@ -211,7 +211,7 @@ return; \ } \ } \ if (!compat) { \ - throw(new DataTypeMismatchException("Type mismatch, element type " #enumtype " is not compatible with a " #datatype)); \ + throw(DataTypeMismatchException("Type mismatch, element type " #enumtype " is not compatible with a " #datatype)); \ } \ if (sizeof(datatype) < data_size) { \ std::cout << "Warning, data type mismatch requested size for '" << #datatype << "(" << sizeof(datatype) << ")' < data size '" << data_size << "'; possible loss of data."; \ @@ -254,7 +254,7 @@ return; \ } \ } \ if (!compat) { \ - throw(new DataTypeMismatchException("Type mismatch, element type " #enumtype " is not compatible with a " #datatype)); \ + throw(DataTypeMismatchException("Type mismatch, element type " #enumtype " is not compatible with a " #datatype)); \ } \ if (data_type == DATA_FLOAT || data_type == DATA_DOUBLE) { \ if (sizeof(datatype) < data_size) { \ @@ -286,7 +286,7 @@ DataElementGetFloatingPointDef(DATA_DOUBLE, double, DATA_FLOAT, DATA_CHAR, DATA_ void DataElement::get(char **data_in) { if (data_type != DATA_VOID) - throw(new DataTypeMismatchException("Type mismatch, not a CHAR*")); + throw(DataTypeMismatchException("Type mismatch, not a CHAR*")); *data_in = new char[data_size]; memcpy(*data_in, data_val, data_size); } @@ -296,7 +296,7 @@ void DataElement::get(string &str_in) { return; if (data_type != DATA_STRING) - throw(new DataTypeMismatchException("Type mismatch, not a STRING")); + throw(DataTypeMismatchException("Type mismatch, not a STRING")); if (!str_in.empty()) // flush the string { @@ -313,7 +313,7 @@ void DataElement::get(wstring &wstr_in) { return; if (data_type != DATA_WSTRING) - throw(new DataTypeMismatchException("Type mismatch, not a WSTRING")); + throw(DataTypeMismatchException("Type mismatch, not a WSTRING")); // flush the string wstr_in.clear(); @@ -342,7 +342,7 @@ void DataElement::get(vector &strvect_in) { return; if (data_type != DATA_STR_VECTOR) - throw(new DataTypeMismatchException("Type mismatch, not a STRING VECTOR")); + throw(DataTypeMismatchException("Type mismatch, not a STRING VECTOR")); ptr = 0; @@ -358,7 +358,7 @@ void DataElement::get(std::set &strset_in) { return; if (data_type != DATA_STR_VECTOR) - throw(new DataTypeMismatchException("Type mismatch, not a STRING VECTOR/SET")); + throw(DataTypeMismatchException("Type mismatch, not a STRING VECTOR/SET")); std::vector tmp_vect; std::vector::iterator i; @@ -382,7 +382,7 @@ if (data_type != enumtype) { \ } \ } \ if (!compat) { \ - throw(new DataTypeMismatchException("Type mismatch, element type is not compatible with a " #datatype)); \ + throw(DataTypeMismatchException("Type mismatch, element type is not compatible with a " #datatype)); \ } \ if (sizeof(datatype) < unit_size) { \ std::cout << "Warning, data type mismatch for vector<" #datatype ">; " #datatype " size " << sizeof(datatype) << " is less than unit size " << unit_size << "; possible loss of data."; \ diff --git a/src/util/DataTree.h b/src/util/DataTree.h index f2f3d28..4b7c3e1 100755 --- a/src/util/DataTree.h +++ b/src/util/DataTree.h @@ -205,7 +205,7 @@ public: unsigned int getUInt() { unsigned int i_get; get(i_get); return i_get; }; long getLong() { long l_get; get(l_get); return l_get; }; unsigned long getULong() { unsigned long l_get; get(l_get); return l_get; }; - long getLongLong() { long long l_get; get(l_get); return l_get; }; + long long getLongLong() { long long l_get; get(l_get); return l_get; }; float getFloat() { float f_get; get(f_get); return f_get; }; double getDouble() { double d_get; get(d_get); return d_get; }; long double getLongDouble() { long double d_get; get(d_get); return d_get; };