Changes in / [f851015:cc38669]
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/containers/maybe
rf851015 rcc38669 8 8 // 9 9 // Author : Andrew Beach 10 // Created On : Wed May 2 414:43:00 201710 // Created On : Wed May 25 14:43:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr May 25 16:36:00 201712 // Last Modified On : Wed Apr 25 16:58:00 2017 13 13 // Update Count : 1 14 14 // … … 41 41 42 42 forall(otype T) 43 maybe(T) ?=?(maybe(T) * this, maybe(T) other);44 45 forall(otype T)46 43 bool ?!=?(maybe(T) this, zero_t); 47 44 … … 58 55 T get(maybe(T) * this); 59 56 60 forall(otype T)61 void set(maybe(T) * this, T value);62 63 forall(otype T)64 void set_none(maybe(T) * this);65 66 57 #endif // MAYBE_H -
src/libcfa/containers/maybe.c
rf851015 rcc38669 8 8 // 9 9 // Author : Andrew Beach 10 // Created On : Wed May 2 415:40:00 201710 // Created On : Wed May 25 15:40:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr May 25 15:24:00 201712 // Last Modified On : Wed May 25 17:00:00 2017 13 13 // Update Count : 1 14 14 // … … 26 26 void ?{}(maybe(T) * this, T value) { 27 27 this->has_value = true; 28 (&this->value){value};28 this->value = value; 29 29 } 30 30 … … 33 33 this->has_value = other.has_value; 34 34 if (other.has_value) { 35 (&this->value){other.value}; 36 } 37 } 38 39 forall(otype T) 40 maybe(T) ?=?(maybe(T) * this, maybe(T) that) { 41 if (this->has_value & that.has_value) { 42 this->value = that.value; 43 } else if (this->has_value) { 44 ^(&this->value){}; 45 this->has_value = false; 46 } else if (that.has_value) { 47 this->has_value = true; 48 (&this->value){that.value}; 35 this->value = other.value; 49 36 } 50 37 } … … 59 46 forall(otype T) 60 47 bool ?!=?(maybe(T) this, zero_t) { 61 return this.has_value;48 return !this.has_value; 62 49 } 63 50 … … 82 69 return this->value; 83 70 } 84 85 forall(otype T)86 void set(maybe(T) * this, T value) {87 if (this->has_value) {88 this->value = value;89 } else {90 this->has_value = true;91 (&this->value){value};92 }93 }94 95 forall(otype T)96 void set_none(maybe(T) * this) {97 if (this->has_value) {98 this->has_value = false;99 ^(&this->value){};100 }101 } -
src/libcfa/containers/result
rf851015 rcc38669 8 8 // 9 9 // Author : Andrew Beach 10 // Created On : Wed May 2 414:45:00 201710 // Created On : Wed May 25 14:45:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr May 25 16:39:00 201712 // Last Modified On : Wed May 25 16:57:00 2017 13 13 // Update Count : 1 14 14 // … … 50 50 51 51 forall(otype T, otype E) 52 result(T, E) ?=?(result(T, E) * this, result(T, E) other);53 54 forall(otype T, otype E)55 52 bool ?!=?(result(T, E) this, zero_t); 56 53 … … 70 67 E get_error(result(T, E) * this); 71 68 72 forall(otype T, otype E)73 void set(result(T, E) * this, T value);74 75 forall(otype T, otype E)76 void set_error(result(T, E) * this, E error);77 78 69 #endif // RESULT_H -
src/libcfa/containers/result.c
rf851015 rcc38669 8 8 // 9 9 // Author : Andrew Beach 10 // Created On : Wed May 2 415:40:00 201710 // Created On : Wed May 25 15:40:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr May 25 15:27:00 201712 // Last Modified On : Wed May 25 17:02:00 2017 13 13 // Update Count : 1 14 14 // … … 27 27 void ?{}(result(T, E) * this, one_t, T value) { 28 28 this->has_value = true; 29 (&this->value){value};29 this->value = value; 30 30 } 31 31 … … 33 33 void ?{}(result(T, E) * this, zero_t, E error) { 34 34 this->has_value = false; 35 (&this->error){error};35 this->error = error; 36 36 } 37 37 … … 40 40 this->has_value = other.has_value; 41 41 if (other.has_value) { 42 (&this->value){other.value};42 this->value = other.value; 43 43 } else { 44 (&this->error){other.error}; 45 } 46 } 47 48 forall(otype T, otype E) 49 result(T, E) ?=?(result(T, E) * this, result(T, E) that) { 50 if (this->has_value & that.has_value) { 51 this->value = that.value; 52 } else if (this->has_value) { 53 ^(&this->value){}; 54 this->has_value = false; 55 (&this->error){that.error}; 56 } else if (that.has_value) { 57 ^(&this->error){}; 58 this->has_value = true; 59 (&this->value){that.value}; 60 } else { 61 this->error = that.error; 44 this->error = other.error; 62 45 } 63 46 } … … 103 86 return this->error; 104 87 } 105 106 forall(otype T, otype E)107 void set(result(T, E) * this, T value) {108 if (this->has_value) {109 this->value = value;110 } else {111 ^(&this->error){};112 this->has_value = true;113 (&this->value){value};114 }115 }116 117 forall(otype T, otype E)118 void set_error(result(T, E) * this, E error) {119 if (this->has_value) {120 ^(&this->value){};121 this->has_value = false;122 (&this->error){error};123 } else {124 this->error = error;125 }126 } -
tools/cfa.nanorc
rf851015 rcc38669 12 12 color green "\<(float|double|bool|char|int|short|long|sizeof|enum|void|auto)\>" 13 13 color green "\<(static|const|struct|union|typedef|extern|(un)?signed|inline)\>" 14 color green "\<((s?size)| one|zero|((u_?)?int(8|16|32|64|ptr)))_t\>"14 color green "\<((s?size)|((u_?)?int(8|16|32|64|ptr)))_t\>" 15 15 16 16 # Declarations … … 39 39 40 40 # Values 41 # Booleans42 color blue "\<(true|false)\>"43 41 # Characters 44 42 color brightmagenta "'([^'\]|(\\")|(\\['abfnrtv\\]))'"
Note: See TracChangeset
for help on using the changeset viewer.