Device interface library for multiple platforms including Mbed.

Dependents:   DeepCover Embedded Security in IoT MaximInterface MAXREFDES155#

Maxim Interface is a library framework focused on providing flexible and expressive hardware interfaces. Both communication interfaces such as I2C and 1-Wire and device interfaces such as DS18B20 are supported. Modern C++ concepts are used extensively while keeping compatibility with C++98/C++03 and requiring no external dependencies. The embedded-friendly design does not depend on exceptions or RTTI.

The full version of the project is hosted on GitLab: https://gitlab.com/iabenz/MaximInterface

Revision:
5:a8c83a2e6fa4
Parent:
0:f77ad7f72d04
--- a/Utilities/system_error.cpp	Fri Jan 19 10:25:02 2018 -0600
+++ b/Utilities/system_error.cpp	Wed Jan 23 13:11:04 2019 -0600
@@ -35,6 +35,8 @@
 
 namespace MaximInterface {
 
+using std::string;
+
 error_condition error_category::default_error_condition(int code) const {
   return error_condition(code, *this);
 }
@@ -53,11 +55,42 @@
   public:
     virtual const char * name() const { return "system"; }
 
-    virtual std::string message(int condition) const {
+    virtual string message(int condition) const {
       return defaultErrorMessage(condition);
     }
   } instance;
   return instance;
 }
 
-} // namespace MaximInterface
\ No newline at end of file
+static string formatWhat(const error_code & ec) {
+  return string(ec.category().name()) + ' ' + ec.message();
+}
+
+template <typename T>
+static string formatWhat(const error_code & ec, const T & what_arg) {
+  return string(what_arg) + ": " + formatWhat(ec);
+}
+
+system_error::system_error(const error_code & ec)
+    : runtime_error(formatWhat(ec)), code_(ec) {}
+
+system_error::system_error(const error_code & ec, const string & what_arg)
+    : runtime_error(formatWhat(ec, what_arg)), code_(ec) {}
+    
+system_error::system_error(const error_code & ec, const char * what_arg)
+    : runtime_error(formatWhat(ec, what_arg)), code_(ec) {}
+
+system_error::system_error(int ev, const error_category & ecat)
+    : runtime_error(formatWhat(error_code(ev, ecat))), code_(ev, ecat) {}
+
+system_error::system_error(int ev, const error_category & ecat,
+                           const string & what_arg)
+    : runtime_error(formatWhat(error_code(ev, ecat), what_arg)),
+      code_(ev, ecat) {}
+      
+system_error::system_error(int ev, const error_category & ecat,
+                           const char * what_arg)
+    : runtime_error(formatWhat(error_code(ev, ecat), what_arg)),
+      code_(ev, ecat) {}
+
+} // namespace MaximInterface