Changeset 21995bc for src


Ignore:
Timestamp:
May 18, 2016, 11:42:10 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
6e3ae00
Parents:
bf1ee05
Message:

added test for copies and assignment

Location:
src/examples/wrapper/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/examples/wrapper/src/main.c

    rbf1ee05 r21995bc  
    11#include "pointer.h"
     2
     3wrapper_t make_copy(wrapper_t copy)
     4{
     5        return copy;
     6}
    27
    38int main(int argc, char const *argv[])
    49{
    510        wrapper_t p = wrap(6);
     11
     12        sout | endl | "test started" | endl;
     13
     14        wrapper_t p2 = p;
     15
     16        clear(&p);
     17
     18        p = p2;
     19
     20        wrapper_t p3 = make_copy(p2);
     21
     22        sout | endl | "test ended" | endl;
     23
    624        return 0;
    725}
  • src/examples/wrapper/src/pointer.h

    rbf1ee05 r21995bc  
    5353void ?{}(wrapper_t* this)
    5454{
    55         sout | "Constructing empty ref pointer" | endl;
     55        sout | "Constructing empty ref pointer" | endl | endl;
    5656        this->ptr = NULL;
    5757}
     
    6262        this->ptr = rhs.ptr;
    6363        this->ptr->count++;
     64        sout | "Reference is " | this->ptr->count | endl | endl;
    6465}
    6566
     
    7071                sout | "Destroying ref pointer" | endl;
    7172                this->ptr->count--;
    72                 sout | "Reference is " | (int)this->ptr->count | endl;
     73                sout | "Reference is " | this->ptr->count | endl | endl;
    7374                if(!this->ptr->count) delete(this->ptr);
    7475        }
    7576        else
    7677        {
    77                 sout | "Destroying empty ref pointer" | endl;
     78                sout | "Destroying empty ref pointer" | endl | endl;
    7879        }
     80}
     81
     82wrapper_t ?=?(wrapper_t* this, wrapper_t rhs)
     83{
     84        sout | "Setting ref pointer" | endl;
     85        if(this->ptr)
     86        {
     87                this->ptr->count--;
     88                sout | "Reference is " | this->ptr->count | endl | endl;
     89                if(!this->ptr->count) delete(this->ptr);
     90        }
     91        this->ptr = rhs.ptr;
     92        this->ptr->count++;
     93        sout | "Reference is " | this->ptr->count | endl | endl;
    7994}
    8095
     
    8499        this->ptr->count++;
    85100        sout | "Setting ref pointer" | endl;
    86         sout | "Reference is " | this->ptr->count | endl;
     101        sout | "Reference is " | this->ptr->count | endl | endl;
    87102}
     103
     104void clear(wrapper_t* this)
     105{
     106        sout | "Clearing ref pointer" | endl;
     107        this->ptr->count--;
     108        sout | "Reference is " | this->ptr->count | endl | endl;
     109        if(!this->ptr->count) delete(this->ptr);
     110        this->ptr = NULL;
     111}
     112
    88113
    89114wrapper_t wrap(int val)
Note: See TracChangeset for help on using the changeset viewer.