67 lines
1.3 KiB
C
Raw Normal View History

2020-11-27 11:33:55 +01:00
#pragma once
2018-01-28 15:34:55 +01:00
//
// FILE: Troolean.h
// AUTHOR: Rob Tillaart
2022-12-02 14:12:22 +01:00
// VERSION: 0.1.7
2020-11-27 11:33:55 +01: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 15:34:55 +01:00
// Kleene and Priest logics
2021-01-29 12:31:58 +01:00
2018-01-28 15:34:55 +01:00
#include "Arduino.h"
#include "Printable.h"
2022-12-02 14:12:22 +01:00
#define TROOLEAN_LIB_VERSION (F("0.1.7"))
2021-01-29 12:31:58 +01:00
2022-11-26 16:50:57 +01:00
// VALUE MEANING
// 0 = false
// -1 = unknown
// other = true
2021-12-29 13:05:17 +01:00
#define unknown -1
2021-01-29 12:31:58 +01:00
2018-01-28 15:34:55 +01:00
class Troolean: public Printable
{
public:
Troolean();
2022-11-26 16:50:57 +01:00
Troolean(const int8_t); // 0 = false, -1 = unknown anything else = true
2018-01-28 15:34:55 +01:00
Troolean(const Troolean&);
2022-12-02 14:12:22 +01:00
// PRINTING
2018-01-28 15:34:55 +01:00
size_t printTo(Print&) const;
2022-12-02 14:12:22 +01:00
// EQUALITIES
2018-01-28 15:34:55 +01:00
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;
2022-12-02 14:12:22 +01:00
// NEGATE
Troolean operator ! (); // not, negate
2018-01-28 15:34:55 +01:00
2022-12-02 14:12:22 +01:00
// LOGICAL OPERATORS
2018-01-28 15:34:55 +01:00
Troolean operator && (const Troolean&);
Troolean operator && (const bool&);
Troolean operator || (const Troolean&);
Troolean operator || (const bool&);
2022-12-02 14:12:22 +01:00
bool isTrue();
bool isFalse();
bool isUnknown();
2018-01-28 15:34:55 +01:00
2021-12-29 13:05:17 +01:00
2018-01-28 15:34:55 +01:00
private:
int8_t _value;
};
2021-12-29 13:05:17 +01:00
2022-11-26 16:50:57 +01:00
// -- END OF FILE --
2021-12-29 13:05:17 +01:00