forked from RobTillaart/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTroolean.h
More file actions
67 lines (51 loc) · 1.41 KB
/
Copy pathTroolean.h
File metadata and controls
67 lines (51 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// FILE: Troolean.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: class for Troolean math
// URL: https://en.wikipedia.org/wiki/Three-valued_logic
// Kleene and Priest logics
//
// HISTORY:
// see Troolean.cpp file
//
#ifndef TROOLEAN_H
#define TROOLEAN_H
#include "Arduino.h"
#include "Printable.h"
#define TROOLEAN_LIB_VERSION (F("0.1.1"))
// TODO:rvdt enum values in a separate type....
#define unknown -1
class Troolean: public Printable
{
public:
Troolean();
Troolean(const int8_t);
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
// bool toBool(); // returns random true/false if unknown....
// Troolean operator &&=
// Troolean operator ||=
// extend with dontcare ? ==> four state logic ? Foolean?
private:
int8_t _value;
};
#endif
// END OF FILE