Ignore:
Timestamp:
May 25, 2017, 3:39:02 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
4163409, 8712514
Parents:
7f612112 (diff), f851015 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg2:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/containers/maybe.c

    r7f612112 r1eeab94  
    88//
    99// Author           : Andrew Beach
    10 // Created On       : Wed May 25 15:40:00 2017
     10// Created On       : Wed May 24 15:40:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed May 25 17:00:00 2017
     12// Last Modified On : Thr May 25 15:24:00 2017
    1313// Update Count     : 1
    1414//
     
    2626void ?{}(maybe(T) * this, T value) {
    2727        this->has_value = true;
    28         this->value = value;
     28        (&this->value){value};
    2929}
    3030
     
    3333        this->has_value = other.has_value;
    3434        if (other.has_value) {
    35                 this->value = other.value;
     35                (&this->value){other.value};
     36        }
     37}
     38
     39forall(otype T)
     40maybe(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};
    3649        }
    3750}
     
    4659forall(otype T)
    4760bool ?!=?(maybe(T) this, zero_t) {
    48         return !this.has_value;
     61        return this.has_value;
    4962}
    5063
     
    6982        return this->value;
    7083}
     84
     85forall(otype T)
     86void 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
     95forall(otype T)
     96void set_none(maybe(T) * this) {
     97        if (this->has_value) {
     98                this->has_value = false;
     99                ^(&this->value){};
     100        }
     101}
Note: See TracChangeset for help on using the changeset viewer.