Changeset bf1ee05
- Timestamp:
- May 17, 2016, 6:34:14 PM (9 years ago)
- 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:
- 21995bc
- Parents:
- 19de7b70
- Location:
- src/examples/wrapper/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/wrapper/src/main.c
r19de7b70 rbf1ee05 3 3 int main(int argc, char const *argv[]) 4 4 { 5 wrapper_t p ;5 wrapper_t p = wrap(6); 6 6 return 0; 7 7 } -
src/examples/wrapper/src/pointer.h
r19de7b70 rbf1ee05 38 38 } 39 39 40 void ?{}(content_t* this)41 {42 sout | "Constructing content" | endl;43 this->count = 0;44 }45 46 40 void ^?{}(content_t* this) 47 41 { … … 57 51 }; 58 52 59 wrapper_t wrap(int val)53 void ?{}(wrapper_t* this) 60 54 { 61 wrapper_t w; 62 content_t* c = malloc; 63 c{}; 64 c->value = val; 65 reset(&w, c); 66 return w; 55 sout | "Constructing empty ref pointer" | endl; 56 this->ptr = NULL; 67 57 } 68 58 69 void ?{}(wrapper_t* this )59 void ?{}(wrapper_t* this, wrapper_t rhs) 70 60 { 71 this->ptr = new(); 61 sout | "Constructing ref pointer from copy" | endl; 62 this->ptr = rhs.ptr; 72 63 this->ptr->count++; 73 sout | "Constructing empty ref pointer" | endl;74 64 } 75 65 76 66 void ^?{}(wrapper_t* this) 77 67 { 68 if(this->ptr) 78 69 { 70 sout | "Destroying ref pointer" | endl; 79 71 this->ptr->count--; 72 sout | "Reference is " | (int)this->ptr->count | endl; 80 73 if(!this->ptr->count) delete(this->ptr); 81 sout | "Destroying ref pointer" | endl;82 sout | "Reference is " | this->ptr->count | endl;83 74 } 84 75 else … … 91 82 { 92 83 this->ptr = c; 84 this->ptr->count++; 93 85 sout | "Setting ref pointer" | endl; 94 86 sout | "Reference is " | this->ptr->count | endl; 95 87 } 88 89 wrapper_t wrap(int val) 90 { 91 wrapper_t w; 92 content_t* c = malloc(); 93 c{}; 94 c->value = val; 95 set(&w, c); 96 return w; 97 }
Note: See TracChangeset
for help on using the changeset viewer.