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:
11:3f3bf6bf5e6c
Parent:
8:5ea891c7d1a1
--- a/MaximInterfaceCore/FlagSet.hpp	Mon Sep 30 09:39:32 2019 -0500
+++ b/MaximInterfaceCore/FlagSet.hpp	Tue Dec 03 10:52:28 2019 -0600
@@ -58,10 +58,10 @@
 
     operator bool() const { return flagSet->test(flag); }
 
-    bool operator~() const { return !*this; }
+    bool operator~() const { return !(*this); }
 
     reference & flip() {
-      *this = !*this;
+      flagSet->flip(flag);
       return *this;
     }
 
@@ -131,7 +131,7 @@
     return *this;
   }
 
-  FlagSet operator~() const { return ~bits; }
+  FlagSet operator~() const { return FlagSet(*this).flip(); }
 
   FlagSet & set() {
     bits.set();
@@ -143,7 +143,7 @@
     if (value) {
       bits |= rawFlag;
     } else {
-      bits &= ~rawFlag;
+      bits &= static_cast<unsigned long>(~rawFlag);
     }
     return *this;
   }
@@ -179,16 +179,22 @@
 
   /// @}
 
-private:
-  std::bitset<flagBits> bits;
-
   template <typename CharT, typename Traits>
   friend std::basic_ostream<CharT, Traits> &
-  operator<<(std::basic_ostream<CharT, Traits> & os, const FlagSet & x);
+  operator<<(std::basic_ostream<CharT, Traits> & os, const FlagSet & x) {
+    os << x.bits;
+    return os;
+  }
 
   template <typename CharT, class Traits>
   friend std::basic_istream<CharT, Traits> &
-  operator>>(std::basic_istream<CharT, Traits> & is, FlagSet & x);
+  operator>>(std::basic_istream<CharT, Traits> & is, FlagSet & x) {
+    is >> x.bits;
+    return is;
+  }
+
+private:
+  std::bitset<flagBits> bits;
 };
 
 template <typename Flag, size_t flagBits>
@@ -209,22 +215,6 @@
   return FlagSet<Flag, flagBits>(lhs) ^= rhs;
 }
 
-template <typename CharT, typename Traits, typename Flag, size_t flagBits>
-std::basic_ostream<CharT, Traits> &
-operator<<(std::basic_ostream<CharT, Traits> & os,
-           const FlagSet<Flag, flagBits> & x) {
-  os << x.bits;
-  return os;
-}
-
-template <typename CharT, class Traits, typename Flag, size_t flagBits>
-std::basic_istream<CharT, Traits> &
-operator>>(std::basic_istream<CharT, Traits> & is,
-           FlagSet<Flag, flagBits> & x) {
-  is >> x.bits;
-  return is;
-}
-
 } // namespace MaximInterfaceCore
 
 #endif