summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pexception.cpp
diff options
context:
space:
mode:
author couriersud <couriersud@gmx.org>2019-02-18 20:21:53 +0100
committer couriersud <couriersud@gmx.org>2019-02-18 20:22:16 +0100
commit6207d7d2d3262718c78c143681a4c609a7e72452 (patch)
tree8488a45aa1d11c2649940886f5cc60ce170153ad /src/lib/netlist/plib/pexception.cpp
parentccd5479997afeddedd133fe2baaac47247ef41da (diff)
netlist: tick off some issues clang-tidy highlights. (nw)
Diffstat (limited to 'src/lib/netlist/plib/pexception.cpp')
-rw-r--r--src/lib/netlist/plib/pexception.cpp155
1 files changed, 84 insertions, 71 deletions
diff --git a/src/lib/netlist/plib/pexception.cpp b/src/lib/netlist/plib/pexception.cpp
index d26fc8fd12e..93f1c24c08c 100644
--- a/src/lib/netlist/plib/pexception.cpp
+++ b/src/lib/netlist/plib/pexception.cpp
@@ -9,6 +9,7 @@
#include "pfmtlog.h"
#include <cfenv>
+#include <iostream>
#if (defined(__x86_64__) || defined(__i386__)) && defined(__linux__)
#define HAS_FEENABLE_EXCEPT (1)
@@ -17,101 +18,113 @@
#endif
namespace plib {
-//============================================================
-// Exceptions
-//============================================================
-pexception::pexception(const pstring &text)
-: m_text(text)
-{
-}
+ //============================================================
+ // terminate
+ //============================================================
+ void terminate(pstring msg) noexcept
+ {
+ std::cerr << msg.c_str() << "\n";
+ std::terminate();
+ }
-file_e::file_e(const pstring &fmt, const pstring &filename)
- : pexception(pfmt(fmt)(filename))
-{
-}
+ //============================================================
+ // Exceptions
+ //============================================================
-file_open_e::file_open_e(const pstring &filename)
- : file_e("File open failed: {}", filename)
-{
-}
+ pexception::pexception(const pstring &text)
+ : m_text(text)
+ {
+ }
-file_read_e::file_read_e(const pstring &filename)
- : file_e("File read failed: {}", filename)
-{
-}
+ file_e::file_e(const pstring &fmt, const pstring &filename)
+ : pexception(pfmt(fmt)(filename))
+ {
+ }
-file_write_e::file_write_e(const pstring &filename)
- : file_e("File write failed: {}", filename)
-{
-}
+ file_open_e::file_open_e(const pstring &filename)
+ : file_e("File open failed: {}", filename)
+ {
+ }
-null_argument_e::null_argument_e(const pstring &argument)
- : pexception(pfmt("Null argument passed: {}")(argument))
-{
-}
+ file_read_e::file_read_e(const pstring &filename)
+ : file_e("File read failed: {}", filename)
+ {
+ }
-out_of_mem_e::out_of_mem_e(const pstring &location)
- : pexception(pfmt("Out of memory: {}")(location))
-{
-}
+ file_write_e::file_write_e(const pstring &filename)
+ : file_e("File write failed: {}", filename)
+ {
+ }
-fpexception_e::fpexception_e(const pstring &text)
- : pexception(pfmt("Out of memory: {}")(text))
-{
-}
+ null_argument_e::null_argument_e(const pstring &argument)
+ : pexception(pfmt("Null argument passed: {}")(argument))
+ {
+ }
-bool fpsignalenabler::m_enable = false;
+ out_of_mem_e::out_of_mem_e(const pstring &location)
+ : pexception(pfmt("Out of memory: {}")(location))
+ {
+ }
-fpsignalenabler::fpsignalenabler(unsigned fpexceptions)
-{
-#if HAS_FEENABLE_EXCEPT
- if (m_enable)
+
+ fpexception_e::fpexception_e(const pstring &text)
+ : pexception(pfmt("Out of memory: {}")(text))
{
- int b = 0;
- if (fpexceptions & plib::FP_INEXACT) b = b | FE_INEXACT;
- if (fpexceptions & plib::FP_DIVBYZERO) b = b | FE_DIVBYZERO;
- if (fpexceptions & plib::FP_UNDERFLOW) b = b | FE_UNDERFLOW;
- if (fpexceptions & plib::FP_OVERFLOW) b = b | FE_OVERFLOW;
- if (fpexceptions & plib::FP_INVALID) b = b | FE_INVALID;
- m_last_enabled = feenableexcept(b);
}
-#else
- m_last_enabled = 0;
-#endif
-}
-fpsignalenabler::~fpsignalenabler()
-{
-#if HAS_FEENABLE_EXCEPT
- if (m_enable)
+ bool fpsignalenabler::m_enable = false;
+
+ fpsignalenabler::fpsignalenabler(unsigned fpexceptions)
{
- fedisableexcept(FE_ALL_EXCEPT); // Enable all floating point exceptions but FE_INEXACT
- feenableexcept(m_last_enabled); // Enable all floating point exceptions but FE_INEXACT
+ #if HAS_FEENABLE_EXCEPT
+ if (m_enable)
+ {
+ int b = 0;
+ if (fpexceptions & plib::FP_INEXACT) b = b | FE_INEXACT;
+ if (fpexceptions & plib::FP_DIVBYZERO) b = b | FE_DIVBYZERO;
+ if (fpexceptions & plib::FP_UNDERFLOW) b = b | FE_UNDERFLOW;
+ if (fpexceptions & plib::FP_OVERFLOW) b = b | FE_OVERFLOW;
+ if (fpexceptions & plib::FP_INVALID) b = b | FE_INVALID;
+ m_last_enabled = feenableexcept(b);
+ }
+ #else
+ m_last_enabled = 0;
+ #endif
+ }
+
+
+ fpsignalenabler::~fpsignalenabler()
+ {
+ #if HAS_FEENABLE_EXCEPT
+ if (m_enable)
+ {
+ fedisableexcept(FE_ALL_EXCEPT); // Enable all floating point exceptions but FE_INEXACT
+ feenableexcept(m_last_enabled); // Enable all floating point exceptions but FE_INEXACT
+ }
+ #endif
+ }
+
+ bool fpsignalenabler::supported()
+ {
+ return true;
+ }
+
+ bool fpsignalenabler::global_enable(bool enable)
+ {
+ bool old = m_enable;
+ m_enable = enable;
+ return old;
}
-#endif
-}
-
-bool fpsignalenabler::supported()
-{
- return true;
-}
-
-bool fpsignalenabler::global_enable(bool enable)
-{
- bool old = m_enable;
- m_enable = enable;
- return old;
-}
} // namespace plib