boolean.hpp 937 B

12345678910111213141516171819202122232425262728293031
  1. #pragma once
  2. namespace nall {
  3. struct Boolean {
  4. static constexpr auto bits() -> uint { return 1; }
  5. using btype = bool;
  6. Boolean() : data(false) {}
  7. template<typename T> Boolean(const T& value) : data(value) {}
  8. explicit Boolean(const char* value) { data = !strcmp(value, "true"); }
  9. operator bool() const { return data; }
  10. template<typename T> auto& operator=(const T& value) { data = value; return *this; }
  11. auto flip() { return data ^= 1; }
  12. auto raise() { return data == 0 ? data = 1, true : false; }
  13. auto lower() { return data == 1 ? data = 0, true : false; }
  14. auto flip(bool value) { return data != value ? (data = value, true) : false; }
  15. auto raise(bool value) { return !data && value ? (data = value, true) : (data = value, false); }
  16. auto lower(bool value) { return data && !value ? (data = value, true) : (data = value, false); }
  17. auto serialize(serializer& s) { s(data); }
  18. private:
  19. btype data;
  20. };
  21. }