Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Core::OrderedCollection Class Reference

#include <OrderedCollection.h>

Inheritance diagram for Core::OrderedCollection:

Inheritance graph
[legend]
Collaboration diagram for Core::OrderedCollection:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 OrderedCollection (int size=5)
virtual ~OrderedCollection (void)
 OrderedCollection (const OrderedCollection &origin)
virtual StringclassName (void) const
 Answer receiver class name.
virtual Objectat (int index) const
virtual void put (int index, Object *obj)
virtual long capacity (void) const
 Answer how many elements can be stored in the collection.
virtual long size (void) const
 Answer how many elements the collection includes.
virtual Objectfirst (void)
virtual Objectlast (void)
virtual void add (Object *)
virtual void addFirst (Object *)
virtual void addLast (Object *)
virtual void changeSize (long newSize)
virtual OrderedCollectionasOrderedCollection (void)
virtual Objectcopy (void)
virtual Objectcopy (int from, int to)
virtual ObjectcopyEmpty (long size)
virtual Objectremove (Object *)
virtual ObjectremoveFirst (void)
virtual ObjectremoveLast (void)

Static Public Member Functions

static OrderedCollectionwith (Object *object)
static OrderedCollectionwith (Object *obj1, Object *obj2)
static OrderedCollectionwith (Object *obj1, Object *obj2, Object *obj3)
static OrderedCollectionwith (Object *obj1, Object *obj2, Object *obj3, Object *obj4)
static OrderedCollectionwithAll (Collection *coll)

Protected Member Functions

virtual ObjectprivNextForIterator (CollectionIterator *iter) const
virtual void changeCapacity (int newCapacity)
virtual void grow (void)
virtual void increaseCapacity (void)
virtual void makeRoomAtFirst (void)
virtual void makeRoomAtLast (void)
virtual void removeIndex (int index)

Protected Attributes

Arraycontent
int firstIndex
int lastIndex

Constructor & Destructor Documentation

OrderedCollection::OrderedCollection int  size = 5  ) 
 

Definition at line 29 of file OrderedCollection.cc.

References content, firstIndex, and lastIndex.

Referenced by copy(), copyEmpty(), with(), and withAll().

00030 {
00031     content = new Array(size);
00032     firstIndex = 0;
00033     lastIndex = -1;
00034 }

OrderedCollection::~OrderedCollection void   )  [virtual]
 

Definition at line 36 of file OrderedCollection.cc.

References content.

00037 {
00038     delete content;
00039 }

OrderedCollection::OrderedCollection const OrderedCollection origin  ) 
 

Definition at line 42 of file OrderedCollection.cc.

References content, Core::Array::copy(), firstIndex, and lastIndex.

00043 {
00044     firstIndex = origin.firstIndex;
00045     lastIndex = origin.lastIndex;
00046     content = (Array *) origin.content->copy();
00047 }


Member Function Documentation

void OrderedCollection::add Object  )  [virtual]
 

Reimplemented from Core::Collection.

Definition at line 143 of file OrderedCollection.cc.

References addLast().

Referenced by Tools::CommandLineParser::addArgument(), Core::String::asArrayOfSubstringsSeparatedBy(), Tools::Filename::components(), Tools::Filename::directoryContents(), Tools::Filename::privFilesMatchingAccessList(), with(), and withAll().

00144 {
00145     addLast(object);
00146 }

void OrderedCollection::addFirst Object  )  [virtual]
 

Definition at line 148 of file OrderedCollection.cc.

References content, firstIndex, makeRoomAtFirst(), and Core::Array::put().

Referenced by Tools::HierarchicalConfigurationReader::pushConfiguration().

00149 {
00150     if (firstIndex == 0) makeRoomAtFirst();
00151     firstIndex--;
00152     content->put(firstIndex, object);
00153 }

void OrderedCollection::addLast Object  )  [virtual]
 

Definition at line 155 of file OrderedCollection.cc.

References capacity(), content, lastIndex, makeRoomAtLast(), and Core::Array::put().

Referenced by add(), Core::Collection::asOrderedCollection(), and OS::SharedQueue::nextPut().

00156 {
00157     lastIndex++;
00158     if (lastIndex == capacity()) makeRoomAtLast();
00159     content->put(lastIndex, object);
00160 }

OrderedCollection * OrderedCollection::asOrderedCollection void   )  [virtual]
 

Reimplemented from Core::Collection.

Definition at line 172 of file OrderedCollection.cc.

00173 {
00174     return this;
00175 }

Object * OrderedCollection::at int  index  )  const [virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 100 of file OrderedCollection.cc.

References Core::Array::at(), content, firstIndex, lastIndex, and Core::GenericException::raiseFrom().

Referenced by Tools::Filename::privFilesMatchingAccessList(), and Tools::CommandLineParser::process().

00101 {
00102     if (index < 0 || index + firstIndex > lastIndex) {
00103         SubscriptOutOfBoundsError *ex;
00104         ex = new SubscriptOutOfBoundsError(__PRETTY_FUNCTION__, index);
00105         ex->raiseFrom(this);
00106     }
00107     return content->at(index + firstIndex);
00108 }

long OrderedCollection::capacity void   )  const [virtual]
 

Answer how many elements can be stored in the collection.

Reimplemented from Core::Collection.

Definition at line 120 of file OrderedCollection.cc.

References content, and Core::Array::size().

Referenced by addLast(), makeRoomAtFirst(), and privNextForIterator().

00121 {
00122     return content->size();
00123 }

void OrderedCollection::changeCapacity int  newCapacity  )  [protected, virtual]
 

Definition at line 234 of file OrderedCollection.cc.

References Core::Array::at(), content, firstIndex, lastIndex, and Core::Array::put().

Referenced by increaseCapacity().

00235 {
00236     Array *oldContent;
00237 
00238     oldContent = content;
00239     content = new Array(newCapacity);
00240     for (int i = firstIndex; i < lastIndex; i++) {
00241         content->put(i, oldContent->at(i));
00242     }
00243     delete oldContent;
00244 }

void OrderedCollection::changeSize long  newSize  )  [virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 162 of file OrderedCollection.cc.

References content, Core::SequenceableCollection::replace(), and size().

00163 {
00164     Array *oldContent = content;
00165     content = new Array(newSize);
00166     long length = size();
00167     content->replace(0, (length < newSize) ? length : newSize, oldContent);
00168     delete oldContent;
00169 }

String * OrderedCollection::className void   )  const [virtual]
 

Answer receiver class name.

Because there isn't any standard way to obtain class name this method comes to place.

Every class should rewrite this method but many didn't (yet).

Reimplemented from Core::Collection.

Definition at line 50 of file OrderedCollection.cc.

00051 {
00052     return new String("OrderedCollection");
00053 }

virtual Object* Core::OrderedCollection::copy int  from,
int  to
[inline, virtual]
 

Definition at line 80 of file OrderedCollection.h.

References Core::SequenceableCollection::copy().

00081       { return SequenceableCollection::copy(from, to); }

Object * OrderedCollection::copy void   )  [virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 178 of file OrderedCollection.cc.

References OrderedCollection().

00179 {
00180     return new OrderedCollection(*this);
00181 }

Object * OrderedCollection::copyEmpty long  size  )  [virtual]
 

Reimplemented from Core::Collection.

Definition at line 183 of file OrderedCollection.cc.

References OrderedCollection().

00184 {
00185     return new OrderedCollection(size);
00186 }

Object * OrderedCollection::first void   )  [virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 130 of file OrderedCollection.cc.

References Core::Array::at(), content, Core::Collection::emptyCheck(), and firstIndex.

Referenced by Tools::Filename::baseDirectoryForList(), and OS::SharedQueue::peek().

00131 {
00132     emptyCheck();
00133     return content->at(firstIndex);
00134 }

void OrderedCollection::grow void   )  [protected, virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 246 of file OrderedCollection.cc.

References increaseCapacity().

00247 {
00248     increaseCapacity();
00249 }

void OrderedCollection::increaseCapacity void   )  [protected, virtual]
 

Definition at line 251 of file OrderedCollection.cc.

References changeCapacity(), Core::Collection::growSize(), and size().

Referenced by grow(), makeRoomAtFirst(), and makeRoomAtLast().

00252 {
00253     changeCapacity(size() + growSize());
00254 }

Object * OrderedCollection::last void   )  [virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 136 of file OrderedCollection.cc.

References Core::Array::at(), content, Core::Collection::emptyCheck(), and lastIndex.

00137 {
00138     emptyCheck();
00139     return content->at(lastIndex);
00140 }

void OrderedCollection::makeRoomAtFirst void   )  [protected, virtual]
 

Definition at line 256 of file OrderedCollection.cc.

References Core::Array::at(), capacity(), content, firstIndex, increaseCapacity(), lastIndex, nil, and Core::Array::put().

Referenced by addFirst().

00257 {
00258     int delta;
00259 
00260     delta = capacity() - lastIndex - 1;
00261     if (delta <= 0) {
00262         /* There is no room left */
00263         increaseCapacity();
00264         if (firstIndex == 0) makeRoomAtFirst();
00265         return;
00266     }
00267     for (int i = lastIndex; i >= firstIndex; i--) {
00268         content->put(i + delta, content->at(i));
00269     }
00270     for (int i = firstIndex; i < firstIndex + delta; i++) {
00271         content->put(i, nil);
00272     }
00273     firstIndex += delta;
00274     lastIndex = capacity() - 1;
00275 }

void OrderedCollection::makeRoomAtLast void   )  [protected, virtual]
 

Definition at line 277 of file OrderedCollection.cc.

References Core::Array::at(), content, firstIndex, increaseCapacity(), lastIndex, nil, and Core::Array::put().

Referenced by addLast().

00278 {
00279     int delta;
00280 
00281     delta = -firstIndex;
00282     if (delta == 0) {
00283         /* There is no room left */
00284         increaseCapacity();
00285         return;
00286     }
00287     for (int i = firstIndex; i < lastIndex; i++) {
00288         content->put(i + delta, content->at(i));
00289     }
00290     for (int i = lastIndex + delta; i < lastIndex; i++) {
00291         content->put(i, nil);
00292     }
00293     firstIndex = 0;
00294     lastIndex += delta;
00295 }

Object * OrderedCollection::privNextForIterator CollectionIterator iter  )  const [protected, virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 224 of file OrderedCollection.cc.

References Core::Array::at(), capacity(), content, firstIndex, lastIndex, and nil.

00225 {
00226     if (iter->position() + firstIndex > lastIndex) {
00227         iter->position(capacity());
00228         return nil;
00229     }
00230     return content->at(iter->position() + firstIndex);
00231 }

void OrderedCollection::put int  index,
Object obj
[virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 110 of file OrderedCollection.cc.

References content, firstIndex, lastIndex, Core::Array::put(), and Core::GenericException::raiseFrom().

00111 {
00112     if (index < 0 || index + firstIndex > lastIndex) {
00113         SubscriptOutOfBoundsError *ex;
00114         ex = new SubscriptOutOfBoundsError(__PRETTY_FUNCTION__, index);
00115         ex->raiseFrom(this);
00116     }
00117     return content->put(index + firstIndex, obj);
00118 }

Object * OrderedCollection::remove Object  )  [virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 189 of file OrderedCollection.cc.

References Core::Array::at(), content, firstIndex, lastIndex, and removeIndex().

00190 {
00191     for (int i = firstIndex; i <= lastIndex; i++) {
00192         if (content->at(i)->isEqual(object)) {
00193             removeIndex(i);
00194             return object;
00195         }
00196     }
00197     (new NotFoundError(__PRETTY_FUNCTION__, object))->raiseFrom(this);
00198 }

Object * OrderedCollection::removeFirst void   )  [virtual]
 

Definition at line 200 of file OrderedCollection.cc.

References Core::Array::at(), content, Core::Collection::emptyCheck(), firstIndex, nil, and Core::Array::put().

Referenced by Tools::Filename::baseDirectoryForList(), Tools::Filename::filesMatchingAccessList(), OS::SharedQueue::next(), and Tools::HierarchicalConfigurationReader::popConfiguration().

00201 {
00202     Object *firstObject;
00203 
00204     emptyCheck();
00205     firstObject = content->at(firstIndex);
00206     content->put(firstIndex, nil);
00207     firstIndex++;
00208     return firstObject;
00209 }

void OrderedCollection::removeIndex int  index  )  [protected, virtual]
 

Definition at line 297 of file OrderedCollection.cc.

References Core::Array::at(), content, lastIndex, nil, and Core::Array::put().

Referenced by remove().

00298 {
00299     for (; index < lastIndex; index++) {
00300         content->put(index, content->at(index+1));
00301     }
00302     content->put(lastIndex, nil);
00303     lastIndex--;
00304 }

Object * OrderedCollection::removeLast void   )  [virtual]
 

Definition at line 211 of file OrderedCollection.cc.

References Core::Array::at(), content, Core::Collection::emptyCheck(), lastIndex, nil, and Core::Array::put().

00212 {
00213     Object *lastObject;
00214 
00215     emptyCheck();
00216     lastObject = content->at(lastIndex);
00217     content->put(lastIndex, nil);
00218     lastIndex--;
00219     return lastObject;
00220 }

long OrderedCollection::size void   )  const [virtual]
 

Answer how many elements the collection includes.

Reimplemented from Core::SequenceableCollection.

Definition at line 125 of file OrderedCollection.cc.

References firstIndex, and lastIndex.

Referenced by changeSize(), Tools::CommandLineParser::collectLongOptions(), Tools::CommandLineParser::collectShortOptions(), increaseCapacity(), Tools::Filename::privFilesMatchingAccessList(), Tools::CommandLineParser::process(), and OS::SharedQueue::size().

00126 {
00127     return lastIndex - firstIndex + 1;
00128 }

OrderedCollection * OrderedCollection::with Object obj1,
Object obj2,
Object obj3,
Object obj4
[static]
 

Definition at line 80 of file OrderedCollection.cc.

References add(), and OrderedCollection().

00081 {
00082     OrderedCollection *coll = new OrderedCollection(4);
00083     coll->add(obj1);
00084     coll->add(obj2);
00085     coll->add(obj3);
00086     coll->add(obj4);
00087     return coll;
00088 }

OrderedCollection * OrderedCollection::with Object obj1,
Object obj2,
Object obj3
[static]
 

Definition at line 71 of file OrderedCollection.cc.

References add(), and OrderedCollection().

00072 {
00073     OrderedCollection *coll = new OrderedCollection(3);
00074     coll->add(obj1);
00075     coll->add(obj2);
00076     coll->add(obj3);
00077     return coll;
00078 }

OrderedCollection * OrderedCollection::with Object obj1,
Object obj2
[static]
 

Definition at line 63 of file OrderedCollection.cc.

References add(), and OrderedCollection().

00064 {
00065     OrderedCollection *coll = new OrderedCollection(2);
00066     coll->add(obj1);
00067     coll->add(obj2);
00068     return coll;
00069 }

OrderedCollection * OrderedCollection::with Object object  )  [static]
 

Definition at line 56 of file OrderedCollection.cc.

References add(), and OrderedCollection().

00057 {
00058     OrderedCollection *coll = new OrderedCollection(1);
00059     coll->add(object);
00060     return coll;
00061 }

OrderedCollection * OrderedCollection::withAll Collection coll  )  [static]
 

Definition at line 90 of file OrderedCollection.cc.

References add(), and OrderedCollection().

00091 {
00092     OrderedCollection *newColl = new OrderedCollection(coll->size());
00093     for (Iterator *i = coll->iterator(); !i->finished(); i->next()) {
00094         newColl->add(i->value());
00095     }
00096     return newColl;
00097 }


Member Data Documentation

Array* Core::OrderedCollection::content [protected]
 

Definition at line 40 of file OrderedCollection.h.

Referenced by addFirst(), addLast(), at(), capacity(), changeCapacity(), changeSize(), first(), last(), makeRoomAtFirst(), makeRoomAtLast(), OrderedCollection(), privNextForIterator(), put(), remove(), removeFirst(), removeIndex(), removeLast(), and ~OrderedCollection().

int Core::OrderedCollection::firstIndex [protected]
 

Definition at line 41 of file OrderedCollection.h.

Referenced by addFirst(), at(), changeCapacity(), first(), makeRoomAtFirst(), makeRoomAtLast(), OrderedCollection(), privNextForIterator(), put(), remove(), removeFirst(), and size().

int Core::OrderedCollection::lastIndex [protected]
 

Definition at line 41 of file OrderedCollection.h.

Referenced by addLast(), at(), changeCapacity(), last(), makeRoomAtFirst(), makeRoomAtLast(), OrderedCollection(), privNextForIterator(), put(), remove(), removeIndex(), removeLast(), and size().


The documentation for this class was generated from the following files:
Generated on Mon Nov 27 09:51:47 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2