00001 #include "ObjectCollection.h" 00002 00003 #include "Object.h" 00004 #include "ObjectLink.h" 00005 #include "CollectionIterator.h" 00006 00007 #include <stdio.h> 00008 00009 ObjectCollection::ObjectCollection () 00010 : First(0), Last(0), NumberOfObjects(0) { 00011 } 00012 00013 ObjectCollection::~ObjectCollection () { 00014 delete First; 00015 First = 0; 00016 delete Last; 00017 Last = 0; 00018 } 00019 00020 class Object *ObjectCollection::Get (int pAt) { 00021 if ((pAt < 1) || (pAt > this->GetLength())) return 0; 00022 ObjectLink *link; 00023 link= this->First; 00024 while (pAt > 1) { 00025 link= link->GetNext(); 00026 pAt--; 00027 } 00028 return link->GetValue(); 00029 } 00030 00031 void ObjectCollection::Put (class Object *pO) { 00032 ObjectLink *newLink= new ObjectLink(pO); 00033 if (this->IsEmpty()) 00034 this->SetFirst(newLink); 00035 else 00036 /* this->GetLast()->SetNext(newLink); */ 00037 { ObjectLink *_pa_tmp_temp_1 = this->GetLast(); 00038 _pa_tmp_temp_1->SetNext(newLink); }; 00039 this->SetLast(newLink); 00040 this->NumberOfObjects++; 00041 } 00042 00043 bool ObjectCollection::IsEmpty () { 00044 return (this->GetLength() == 0); 00045 } 00046 00047 int ObjectCollection::GetLength () { 00048 return this->NumberOfObjects; 00049 } 00050 00051 void ObjectCollection::Print () { 00052 //---- CollectionIterator Iter(this); 00053 CollectionIterator *Iter= new CollectionIterator(this); 00054 Object *anObject; 00055 00056 this->Object::Print(); 00057 fprintf(stdout, "I contain %d objects:\n", this->GetLength()); 00058 00059 anObject= Iter->GetNext(); 00060 while (anObject != 0) { 00061 fprintf(stdout, " "); 00062 anObject->Print(); 00063 anObject = Iter->GetNext(); 00064 } 00065 } 00066 00067 void ObjectCollection::SetFirst (ObjectLink *oL) { 00068 this->First = oL; 00069 } 00070 00071 ObjectLink *ObjectCollection::GetFirst () { 00072 return this->First; 00073 } 00074 00075 void ObjectCollection::SetLast (ObjectLink *oL) { 00076 this->Last = oL; 00077 } 00078 00079 ObjectLink *ObjectCollection::GetLast () { 00080 return this->Last; 00081 } 00082