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

Committer:
IanBenzMaxim
Date:
Fri May 29 16:19:22 2020 -0500
Revision:
12:7eb41621ba22
Parent:
11:3f3bf6bf5e6c
Updated to version 2.2.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 7:9cd16581b578 1 /*******************************************************************************
IanBenzMaxim 8:5ea891c7d1a1 2 * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
IanBenzMaxim 7:9cd16581b578 3 *
IanBenzMaxim 7:9cd16581b578 4 * Permission is hereby granted, free of charge, to any person obtaining a
IanBenzMaxim 7:9cd16581b578 5 * copy of this software and associated documentation files (the "Software"),
IanBenzMaxim 7:9cd16581b578 6 * to deal in the Software without restriction, including without limitation
IanBenzMaxim 7:9cd16581b578 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
IanBenzMaxim 7:9cd16581b578 8 * and/or sell copies of the Software, and to permit persons to whom the
IanBenzMaxim 7:9cd16581b578 9 * Software is furnished to do so, subject to the following conditions:
IanBenzMaxim 7:9cd16581b578 10 *
IanBenzMaxim 7:9cd16581b578 11 * The above copyright notice and this permission notice shall be included
IanBenzMaxim 7:9cd16581b578 12 * in all copies or substantial portions of the Software.
IanBenzMaxim 7:9cd16581b578 13 *
IanBenzMaxim 7:9cd16581b578 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
IanBenzMaxim 7:9cd16581b578 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
IanBenzMaxim 7:9cd16581b578 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IanBenzMaxim 7:9cd16581b578 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
IanBenzMaxim 7:9cd16581b578 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
IanBenzMaxim 7:9cd16581b578 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
IanBenzMaxim 7:9cd16581b578 20 * OTHER DEALINGS IN THE SOFTWARE.
IanBenzMaxim 7:9cd16581b578 21 *
IanBenzMaxim 7:9cd16581b578 22 * Except as contained in this notice, the name of Maxim Integrated
IanBenzMaxim 7:9cd16581b578 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
IanBenzMaxim 7:9cd16581b578 24 * Products, Inc. Branding Policy.
IanBenzMaxim 7:9cd16581b578 25 *
IanBenzMaxim 7:9cd16581b578 26 * The mere transfer of this software does not imply any licenses
IanBenzMaxim 7:9cd16581b578 27 * of trade secrets, proprietary technology, copyrights, patents,
IanBenzMaxim 7:9cd16581b578 28 * trademarks, maskwork rights, or any other form of intellectual
IanBenzMaxim 7:9cd16581b578 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
IanBenzMaxim 7:9cd16581b578 30 * ownership rights.
IanBenzMaxim 7:9cd16581b578 31 *******************************************************************************/
IanBenzMaxim 7:9cd16581b578 32
IanBenzMaxim 7:9cd16581b578 33 #include "Error.hpp"
IanBenzMaxim 7:9cd16581b578 34 #include "system_error.hpp"
IanBenzMaxim 7:9cd16581b578 35
IanBenzMaxim 7:9cd16581b578 36 namespace MaximInterfaceCore {
IanBenzMaxim 7:9cd16581b578 37
IanBenzMaxim 7:9cd16581b578 38 using std::string;
IanBenzMaxim 7:9cd16581b578 39
IanBenzMaxim 7:9cd16581b578 40 error_condition error_category::default_error_condition(int code) const {
IanBenzMaxim 7:9cd16581b578 41 return error_condition(code, *this);
IanBenzMaxim 7:9cd16581b578 42 }
IanBenzMaxim 7:9cd16581b578 43
IanBenzMaxim 7:9cd16581b578 44 bool error_category::equivalent(int code,
IanBenzMaxim 7:9cd16581b578 45 const error_condition & condition) const {
IanBenzMaxim 7:9cd16581b578 46 return default_error_condition(code) == condition;
IanBenzMaxim 7:9cd16581b578 47 }
IanBenzMaxim 7:9cd16581b578 48
IanBenzMaxim 7:9cd16581b578 49 bool error_category::equivalent(const error_code & code, int condition) const {
IanBenzMaxim 7:9cd16581b578 50 return *this == code.category() && code.value() == condition;
IanBenzMaxim 7:9cd16581b578 51 }
IanBenzMaxim 7:9cd16581b578 52
IanBenzMaxim 7:9cd16581b578 53 const error_category & system_category() {
IanBenzMaxim 7:9cd16581b578 54 static class : public error_category {
IanBenzMaxim 7:9cd16581b578 55 public:
IanBenzMaxim 7:9cd16581b578 56 virtual const char * name() const { return "system"; }
IanBenzMaxim 7:9cd16581b578 57
IanBenzMaxim 7:9cd16581b578 58 virtual string message(int condition) const {
IanBenzMaxim 7:9cd16581b578 59 return defaultErrorMessage(condition);
IanBenzMaxim 7:9cd16581b578 60 }
IanBenzMaxim 7:9cd16581b578 61 } instance;
IanBenzMaxim 7:9cd16581b578 62 return instance;
IanBenzMaxim 7:9cd16581b578 63 }
IanBenzMaxim 7:9cd16581b578 64
IanBenzMaxim 11:3f3bf6bf5e6c 65 static string formatWhat(const error_code & ec, string what_arg = string()) {
IanBenzMaxim 11:3f3bf6bf5e6c 66 if (!what_arg.empty()) {
IanBenzMaxim 11:3f3bf6bf5e6c 67 what_arg += ": ";
IanBenzMaxim 11:3f3bf6bf5e6c 68 }
IanBenzMaxim 11:3f3bf6bf5e6c 69 what_arg += ec.message();
IanBenzMaxim 11:3f3bf6bf5e6c 70 return what_arg;
IanBenzMaxim 7:9cd16581b578 71 }
IanBenzMaxim 7:9cd16581b578 72
IanBenzMaxim 7:9cd16581b578 73 system_error::system_error(const error_code & ec)
IanBenzMaxim 7:9cd16581b578 74 : runtime_error(formatWhat(ec)), code_(ec) {}
IanBenzMaxim 7:9cd16581b578 75
IanBenzMaxim 7:9cd16581b578 76 system_error::system_error(const error_code & ec, const string & what_arg)
IanBenzMaxim 7:9cd16581b578 77 : runtime_error(formatWhat(ec, what_arg)), code_(ec) {}
IanBenzMaxim 7:9cd16581b578 78
IanBenzMaxim 7:9cd16581b578 79 system_error::system_error(const error_code & ec, const char * what_arg)
IanBenzMaxim 7:9cd16581b578 80 : runtime_error(formatWhat(ec, what_arg)), code_(ec) {}
IanBenzMaxim 7:9cd16581b578 81
IanBenzMaxim 7:9cd16581b578 82 system_error::system_error(int ev, const error_category & ecat)
IanBenzMaxim 7:9cd16581b578 83 : runtime_error(formatWhat(error_code(ev, ecat))), code_(ev, ecat) {}
IanBenzMaxim 7:9cd16581b578 84
IanBenzMaxim 7:9cd16581b578 85 system_error::system_error(int ev, const error_category & ecat,
IanBenzMaxim 7:9cd16581b578 86 const string & what_arg)
IanBenzMaxim 7:9cd16581b578 87 : runtime_error(formatWhat(error_code(ev, ecat), what_arg)),
IanBenzMaxim 7:9cd16581b578 88 code_(ev, ecat) {}
IanBenzMaxim 7:9cd16581b578 89
IanBenzMaxim 7:9cd16581b578 90 system_error::system_error(int ev, const error_category & ecat,
IanBenzMaxim 7:9cd16581b578 91 const char * what_arg)
IanBenzMaxim 7:9cd16581b578 92 : runtime_error(formatWhat(error_code(ev, ecat), what_arg)),
IanBenzMaxim 7:9cd16581b578 93 code_(ev, ecat) {}
IanBenzMaxim 7:9cd16581b578 94
IanBenzMaxim 7:9cd16581b578 95 } // namespace MaximInterfaceCore