GY-63_MS5611/libraries/Troolean/Troolean.h

69 lines
1.5 KiB
C
Raw Normal View History

2020-11-27 05:33:55 -05:00
#pragma once
2018-01-28 09:34:55 -05:00
//
// FILE: Troolean.h
// AUTHOR: Rob Tillaart
2021-12-29 07:05:17 -05:00
// VERSION: 0.1.5
2020-11-27 05:33:55 -05:00
// PURPOSE: Arduino Library for a three state logic datatype supporting {true false unknown}
// URL: https://github.com/RobTillaart/Troolean
// https://en.wikipedia.org/wiki/Three-valued_logic
2018-01-28 09:34:55 -05:00
// Kleene and Priest logics
2021-01-29 06:31:58 -05:00
2018-01-28 09:34:55 -05:00
#include "Arduino.h"
#include "Printable.h"
2021-12-29 07:05:17 -05:00
#define TROOLEAN_LIB_VERSION (F("0.1.5"))
2021-01-29 06:31:58 -05:00
// 0 = false, -1 = unknown anything else = true
2021-12-29 07:05:17 -05:00
#define unknown -1
2021-01-29 06:31:58 -05:00
2018-01-28 09:34:55 -05:00
class Troolean: public Printable
{
public:
Troolean();
2020-11-27 05:33:55 -05:00
Troolean(const int8_t); // 0 = false, -1 = unknown anything else = true
2018-01-28 09:34:55 -05:00
Troolean(const Troolean&);
size_t printTo(Print&) const;
bool operator == (const Troolean&);
bool operator == (const bool&);
bool operator == (const int&);
bool operator != (const Troolean&);
bool operator != (const bool&);
bool operator != (const int&);
operator bool() const;
Troolean operator ! (); // negation
Troolean operator && (const Troolean&);
Troolean operator && (const bool&);
Troolean operator || (const Troolean&);
Troolean operator || (const bool&);
// faster than ==
inline bool isTrue() { return _value == 1; };
inline bool isFalse() { return _value == 0; };
inline bool isUnknown() { return _value == -1; };
// ideas
// Troolean operator &&=
// Troolean operator ||=
2020-11-27 05:33:55 -05:00
//
// bool toBool(); // returns random true/false if unknown....
2018-01-28 09:34:55 -05:00
// extend with dontcare ? ==> four state logic ? Foolean?
2021-12-29 07:05:17 -05:00
2018-01-28 09:34:55 -05:00
private:
int8_t _value;
};
2021-12-29 07:05:17 -05:00
2020-11-27 05:33:55 -05:00
// -- END OF FILE --
2021-12-29 07:05:17 -05:00