Changeset 200fcb3 for examples/wrapper
- Timestamp:
- Dec 12, 2018, 9:16:12 AM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 5ebb1368
- Parents:
- 3d99498
- Location:
- examples/wrapper/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/wrapper/src/main.c
r3d99498 r200fcb3 1 1 #include "pointer.h" 2 2 3 wrapper_t make_copy(wrapper_t copy) 4 { 3 wrapper_t make_copy(wrapper_t copy) { 5 4 return copy; 6 5 } 7 6 8 int main(int argc, char const *argv[]) 9 { 7 int main(int argc, char const *argv[]) { 10 8 wrapper_t p = wrap(6); 11 12 sout | endl | "test started" | endl; 13 9 sout | nl | "test started"; 14 10 wrapper_t p2 = p; 15 16 11 clear(&p); 17 18 12 p = p2; 19 20 13 wrapper_t p3 = make_copy(p2); 21 22 sout | endl | "test ended" | endl; 23 14 sout | nl | "test ended"; 24 15 return 0; 25 16 } -
examples/wrapper/src/pointer.h
r3d99498 r200fcb3 34 34 void ?{}(content_t* this) 35 35 { 36 sout | "Constructing content" | endl;36 sout | "Constructing content"; 37 37 this->count = 0; 38 38 } … … 40 40 void ^?{}(content_t* this) 41 41 { 42 sout | "Destroying content" | endl;42 sout | "Destroying content"; 43 43 } 44 44 … … 53 53 void ?{}(wrapper_t* this) 54 54 { 55 sout | "Constructing empty ref pointer" | endl | endl;55 sout | "Constructing empty ref pointer" | nl; 56 56 this->ptr = NULL; 57 57 } … … 59 59 void ?{}(wrapper_t* this, wrapper_t rhs) 60 60 { 61 sout | "Constructing ref pointer from copy" | endl;61 sout | "Constructing ref pointer from copy"; 62 62 this->ptr = rhs.ptr; 63 63 this->ptr->count++; 64 sout | "Reference is " | this->ptr->count | endl | endl;64 sout | "Reference is " | this->ptr->count | nl; 65 65 } 66 66 … … 69 69 if(this->ptr) 70 70 { 71 sout | "Destroying ref pointer" | endl;71 sout | "Destroying ref pointer"; 72 72 this->ptr->count--; 73 sout | "Reference is " | this->ptr->count | endl | endl;73 sout | "Reference is " | this->ptr->count | nl; 74 74 if(!this->ptr->count) delete(this->ptr); 75 75 } 76 76 else 77 77 { 78 sout | "Destroying empty ref pointer" | endl | endl;78 sout | "Destroying empty ref pointer" | nl; 79 79 } 80 80 } … … 82 82 wrapper_t ?=?(wrapper_t* this, wrapper_t rhs) 83 83 { 84 sout | "Setting ref pointer" | endl;84 sout | "Setting ref pointer"; 85 85 if(this->ptr) 86 86 { 87 87 this->ptr->count--; 88 sout | "Reference is " | this->ptr->count | endl | endl;88 sout | "Reference is " | this->ptr->count | nl; 89 89 if(!this->ptr->count) delete(this->ptr); 90 90 } 91 91 this->ptr = rhs.ptr; 92 92 this->ptr->count++; 93 sout | "Reference is " | this->ptr->count | endl | endl;93 sout | "Reference is " | this->ptr->count | nl; 94 94 } 95 95 … … 98 98 this->ptr = c; 99 99 this->ptr->count++; 100 sout | "Setting ref pointer" | endl;101 sout | "Reference is " | this->ptr->count | endl | endl;100 sout | "Setting ref pointer"; 101 sout | "Reference is " | this->ptr->count | nl; 102 102 } 103 103 104 104 void clear(wrapper_t* this) 105 105 { 106 sout | "Clearing ref pointer" | endl;106 sout | "Clearing ref pointer"; 107 107 this->ptr->count--; 108 sout | "Reference is " | this->ptr->count | endl | endl;108 sout | "Reference is " | this->ptr->count | nl; 109 109 if(!this->ptr->count) delete(this->ptr); 110 110 this->ptr = NULL;
Note: See TracChangeset
for help on using the changeset viewer.