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

Core::SequenceableCollection Class Reference

#include <SequenceableCollection.h>

Inheritance diagram for Core::SequenceableCollection:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual Objectany (void)
 Answer any item from the collection.
virtual Objectat (int index) const abstract
virtual void put (int index, Object *obj) abstract
virtual long size (void) const abstract
 Answer how many elements the collection includes.
virtual Objectfirst (void)
virtual Objectlast (void)
virtual void replace (long start, long stop, const SequenceableCollection *collection)
virtual void replace (long start, long stop, const SequenceableCollection *collection, long startIndex)
virtual void replaceAll (Object *element, Object *replacement)
virtual void replaceAll (Object *element, Object *replacement, long startIndex, long stopIndex)
virtual long indexOf (Object *element) const
 Finds first index of element in a collection.
virtual long lastIndexOf (Object *element) const
 Finds last index of element in a collection.
virtual long nextIndexOf (Object *element, long startIndex, long stopIndex) const
virtual long prevIndexOf (Object *element, long startIndex, long stopIndex) const
virtual long indexOfSubCollection (SequenceableCollection *coll) const
virtual long indexOfSubCollection (SequenceableCollection *coll, long startIndex) const
virtual void changeSize (long newSize) abstract
virtual void grow (void)
virtual void growToAtLeast (long items)
virtual ArrayasArray (void)
virtual ByteArrayasByteArray (void)
virtual StringasString (void)
virtual ReadStreamreadStream (void)
virtual ReadAppendStreamreadAppendStream (void)
virtual WriteStreamwriteStream (void)
virtual Objectcopy (void) abstract
virtual Objectcopy (long from, long to)
 Returns a new collection with the same items as the specified portion of this collection.
virtual SequenceableCollectioncopyReplace (long from, long to, SequenceableCollection *replacement)
virtual SequenceableCollectionoperator+ (SequenceableCollection &collection)
virtual Objectremove (Object *)
virtual bool includesSubcollection (SequenceableCollection *coll) const
virtual bool isSequenceable (void) const
virtual bool startsWith (SequenceableCollection *coll) const
virtual bool endsWith (SequenceableCollection *coll) const

Protected Member Functions

virtual ObjectprivNextForIterator (CollectionIterator *iter) const

Member Function Documentation

Object * SequenceableCollection::any void   )  [virtual]
 

Answer any item from the collection.

Reimplemented from Core::Collection.

Reimplemented in Core::Array.

Definition at line 35 of file SequenceableCollection.cc.

References first().

00036 {
00037     return first();
00038 }

Array * SequenceableCollection::asArray void   )  [virtual]
 

Reimplemented from Core::Collection.

Reimplemented in Core::Array.

Definition at line 172 of file SequenceableCollection.cc.

References at(), Core::Array::put(), and size().

Referenced by Core::String::asArrayOfSubstringsSeparatedBy().

00173 {
00174     Array *newArray = new Array(size());
00175     for (long i = 0; i < size(); i++) {
00176         newArray->put(i, at(i));
00177     }
00178     return newArray;
00179 }

ByteArray * SequenceableCollection::asByteArray void   )  [virtual]
 

Reimplemented in Core::ByteArray.

Definition at line 181 of file SequenceableCollection.cc.

References nil, and Core::Object::shouldNotImplement().

00182 {
00183     shouldNotImplement(new String(__PRETTY_FUNCTION__));
00184     return nil;
00185 }

String * SequenceableCollection::asString void   )  [virtual]
 

Reimplemented in Core::ByteArray, and Core::String.

Definition at line 187 of file SequenceableCollection.cc.

References nil, and Core::Object::shouldNotImplement().

00188 {
00189     shouldNotImplement(new String(__PRETTY_FUNCTION__));
00190     return nil;
00191 }

virtual Object* Core::SequenceableCollection::at int  index  )  const [virtual]
 

Reimplemented in Core::Array, Core::ByteArray, Core::OrderedCollection, and Core::String.

Referenced by asArray(), first(), indexOfSubCollection(), last(), Core::ReadStream::next(), Core::ExternalReadStream::next(), nextIndexOf(), Core::Stream::nextPutAll(), Core::ExternalStream::pastEnd(), prevIndexOf(), OS::Process::privateExecuteJob(), privNextForIterator(), and replace().

virtual void Core::SequenceableCollection::changeSize long  newSize  )  [virtual]
 

Reimplemented in Core::Array, Core::ByteArray, Core::OrderedCollection, and Core::String.

Referenced by grow(), and growToAtLeast().

Object * SequenceableCollection::copy long  from,
long  to
[virtual]
 

Returns a new collection with the same items as the specified portion of this collection.

  • from - the first item of this collection, that will be copied
  • to - the item behind the last item of this collection, that will be copied. If to <= from, no items will be copied and the returned collection will zero length.

Reimplemented in Core::Array, Core::ByteArray, and Core::String.

Definition at line 213 of file SequenceableCollection.cc.

References Core::Collection::copyEmpty(), and replace().

00214 {
00215     SequenceableCollection *newColl;
00216     int newSize = to - from;
00217 
00218     newColl = (SequenceableCollection *) copyEmpty(newSize);
00219     newColl->replace(0, newSize, this, from);
00220     return newColl;
00221 }

virtual Object* Core::SequenceableCollection::copy void   )  [virtual]
 

Reimplemented from Core::Collection.

Reimplemented in Core::Array, Core::ByteArray, Core::OrderedCollection, and Core::String.

Referenced by Core::WriteStream::contents(), Core::PositionableStream::contents(), Core::InternalStream::contents(), Core::String::copy(), Core::OrderedCollection::copy(), Core::ByteArray::copy(), Core::Array::copy(), and Core::InternalStream::upToEnd().

SequenceableCollection * SequenceableCollection::copyReplace long  from,
long  to,
SequenceableCollection replacement
[virtual]
 

Definition at line 223 of file SequenceableCollection.cc.

References Core::Collection::copyEmpty(), replace(), and size().

Referenced by Core::String::concatenateWith(), Core::String::operator+(), operator+(), and Tools::HierarchicalConfigurationReader::readLine().

00225 {
00226     SequenceableCollection *newCollection;
00227     long newSize;
00228     long endReplacement;
00229 
00230     newSize = size() - (to - from) + replacement->size();
00231     endReplacement = from + replacement->size();
00232     newCollection = (SequenceableCollection *) copyEmpty(newSize);
00233     newCollection->replace(0, from, this, 0);
00234     newCollection->replace(from, endReplacement, replacement, 0);
00235     newCollection->replace(endReplacement, newSize, this, to);
00236     return newCollection;
00237 }

bool SequenceableCollection::endsWith SequenceableCollection coll  )  const [virtual]
 

Reimplemented in Core::String.

Definition at line 267 of file SequenceableCollection.cc.

References indexOfSubCollection(), Core::Collection::isEmpty(), and size().

Referenced by Core::String::endsWith().

00268 {
00269     int start = size() - coll->size();
00270     if (start < 0) return false;
00271     return indexOfSubCollection(coll, start) >= 0 || coll->isEmpty();
00272 }

Object * SequenceableCollection::first void   )  [virtual]
 

Reimplemented in Core::OrderedCollection.

Definition at line 40 of file SequenceableCollection.cc.

References at(), and Core::Collection::emptyCheck().

Referenced by any(), Tools::Filename::constructString(), Tools::Filename::isAbsolute(), Core::Object::printOn(), and Tools::HierarchicalConfigurationReader::readLine().

00041 {
00042     emptyCheck();
00043     return at(0);
00044 }

void SequenceableCollection::grow void   )  [virtual]
 

Reimplemented in Core::OrderedCollection.

Definition at line 160 of file SequenceableCollection.cc.

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

00161 {
00162     changeSize(size() + growSize());
00163 }

void SequenceableCollection::growToAtLeast long  items  )  [virtual]
 

Definition at line 165 of file SequenceableCollection.cc.

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

Referenced by Core::InternalStream::nextPutAll(), and Core::InternalStream::pastEndPut().

00166 {
00167     if (items < size()) return;
00168     changeSize(items + growSize());
00169 }

bool SequenceableCollection::includesSubcollection SequenceableCollection coll  )  const [virtual]
 

Reimplemented in Core::String.

Definition at line 252 of file SequenceableCollection.cc.

References indexOfSubCollection(), and Core::Collection::isEmpty().

Referenced by Core::String::includesSubcollection().

00253 {
00254     return indexOfSubCollection(coll) >= 0 || coll->isEmpty();
00255 }

long SequenceableCollection::indexOf Object element  )  const [virtual]
 

Finds first index of element in a collection.

If none found returns -1.

Reimplemented in Core::String.

Definition at line 91 of file SequenceableCollection.cc.

References nextIndexOf(), and size().

Referenced by Core::String::indexOf().

00092 {
00093     long index;
00094 
00095     index = nextIndexOf(element, 0, size());
00096     if (index < 0 || index >= size()) index = -1;
00097     return index;
00098 }

long SequenceableCollection::indexOfSubCollection SequenceableCollection coll,
long  startIndex
const [virtual]
 

Definition at line 134 of file SequenceableCollection.cc.

References at(), nextIndexOf(), and size().

00136 {
00137     long subSize = coll->size();
00138     Object *firstElement;
00139     long len, matchIndex;
00140 
00141     if (subSize == 0) return -1;
00142     if (subSize + startIndex > size()) return -1;
00143     firstElement = coll->at(0);
00144     len = size() - subSize + 1;
00145     matchIndex = nextIndexOf(firstElement, startIndex, len);
00146     if (subSize == 1)
00147         return (matchIndex >= 0 && matchIndex < len) ? matchIndex : -1;
00148     while (matchIndex < len) {
00149         long index = 1;
00150         while (this->at(matchIndex + index)->isEqual(coll->at(index))) {
00151             index++;
00152             if (index == subSize) return matchIndex;
00153         }
00154         matchIndex = nextIndexOf(firstElement, matchIndex + 1, len);
00155     }
00156     return -1;
00157 }

long SequenceableCollection::indexOfSubCollection SequenceableCollection coll  )  const [virtual]
 

Definition at line 129 of file SequenceableCollection.cc.

Referenced by endsWith(), includesSubcollection(), and startsWith().

00130 {
00131     return indexOfSubCollection(coll, 0);
00132 }

bool SequenceableCollection::isSequenceable void   )  const [virtual]
 

Reimplemented from Core::Collection.

Definition at line 257 of file SequenceableCollection.cc.

00258 {
00259     return true;
00260 }

Object * SequenceableCollection::last void   )  [virtual]
 

Reimplemented in Core::OrderedCollection.

Definition at line 46 of file SequenceableCollection.cc.

References at(), Core::Collection::emptyCheck(), and size().

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

00047 {
00048     emptyCheck();
00049     return at(size()-1);
00050 }

long SequenceableCollection::lastIndexOf Object element  )  const [virtual]
 

Finds last index of element in a collection.

If none found returns -1.

Reimplemented in Core::String.

Definition at line 100 of file SequenceableCollection.cc.

References prevIndexOf(), and size().

Referenced by Core::String::lastIndexOf().

00101 {
00102     long index;
00103 
00104     index = prevIndexOf(element, size(), 0);
00105     if (index < 0 || index >= size()) index = -1;
00106     return index;
00107 }

long SequenceableCollection::nextIndexOf Object element,
long  startIndex,
long  stopIndex
const [virtual]
 

Reimplemented in Core::String.

Definition at line 109 of file SequenceableCollection.cc.

References at(), and Core::Object::isEqual().

Referenced by indexOf(), indexOfSubCollection(), Core::String::nextIndexOf(), and replaceAll().

00111 {
00112     for (long index = startIndex; index < stopIndex; index++) {
00113         if (at(index)->isEqual(element))
00114             return index;
00115     }
00116     return stopIndex;
00117 }

SequenceableCollection & SequenceableCollection::operator+ SequenceableCollection collection  )  [virtual]
 

Reimplemented in Core::String.

Definition at line 239 of file SequenceableCollection.cc.

References copyReplace(), and size().

00240 {
00241     return *copyReplace(size(), size(), &collection);
00242 }

long SequenceableCollection::prevIndexOf Object element,
long  startIndex,
long  stopIndex
const [virtual]
 

Reimplemented in Core::String.

Definition at line 119 of file SequenceableCollection.cc.

References at(), and Core::Object::isEqual().

Referenced by lastIndexOf(), and Core::String::prevIndexOf().

00121 {
00122     for (long index = startIndex - 1; index >= stopIndex; index--) {
00123         if (at(index)->isEqual(element))
00124             return index;
00125     }
00126     return stopIndex - 1;
00127 }

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

Reimplemented from Core::Collection.

Reimplemented in Core::Array, and Core::OrderedCollection.

Definition at line 275 of file SequenceableCollection.cc.

References at(), nil, Core::CollectionIterator::position(), and size().

00276 {
00277     long index = iter->position();
00278     for (; index < size(); index += 1) {
00279         Object *item = at(index);
00280         if (item != nil) {
00281             iter->position(index);
00282             return item;
00283         }
00284     }
00285     iter->position(index);
00286     return nil;
00287 }

virtual void Core::SequenceableCollection::put int  index,
Object obj
[virtual]
 

Reimplemented in Core::Array, Core::ByteArray, Core::OrderedCollection, and Core::String.

Referenced by Core::Stream::next(), Core::PositionableStream::next(), Core::WriteStream::nextPut(), Core::ExternalWriteStream::nextPut(), Core::InternalStream::pastEndPut(), replace(), and replaceAll().

ReadAppendStream * SequenceableCollection::readAppendStream void   )  [virtual]
 

Definition at line 198 of file SequenceableCollection.cc.

00199 {
00200     return new ReadAppendStream(this);
00201 }

ReadStream * SequenceableCollection::readStream void   )  [virtual]
 

Definition at line 193 of file SequenceableCollection.cc.

Referenced by Tools::Filename::components(), Tools::ConfigurationReader::onString(), and Core::InternalEncodedStreamFactory::readStream().

00194 {
00195     return new ReadStream(this);
00196 }

Object * SequenceableCollection::remove Object  )  [virtual]
 

Reimplemented from Core::Collection.

Reimplemented in Core::OrderedCollection.

Definition at line 245 of file SequenceableCollection.cc.

References nil, and Core::Object::shouldNotImplement().

00246 {
00247     shouldNotImplement(new String(__PRETTY_FUNCTION__));
00248     return nil;
00249 }

void SequenceableCollection::replace long  start,
long  stop,
const SequenceableCollection collection,
long  startIndex
[virtual]
 

Reimplemented in Core::ByteArray.

Definition at line 61 of file SequenceableCollection.cc.

References at(), and put().

00064 {
00065     long repOff = repStart - start;
00066     if (this == replacement && repStart < start) {
00067         /* Replacement would be overwritten, copy in reverse order. */
00068         for (long i = stop - 1; i >= start; i--)
00069             put(i, replacement->at(repOff + i));
00070     } else {
00071         for (long i = start; i < stop; i++)
00072             put(i, replacement->at(repOff + i));
00073     }
00074 }

void SequenceableCollection::replace long  start,
long  stop,
const SequenceableCollection collection
[virtual]
 

Reimplemented in Core::ByteArray.

Definition at line 52 of file SequenceableCollection.cc.

References Core::Object::error(), and size().

Referenced by Core::OrderedCollection::changeSize(), copy(), copyReplace(), Core::PositionableStream::next(), Core::InternalStream::nextPutAll(), and Core::ByteArray::replace().

00054 {
00055     if (collection->size() != stop - start)
00056         error(new String("Size of replacement doesn\'t match."),
00057               new String(__PRETTY_FUNCTION__));
00058     replace(start, stop, collection, 0);
00059 }

void SequenceableCollection::replaceAll Object element,
Object replacement,
long  startIndex,
long  stopIndex
[virtual]
 

Definition at line 81 of file SequenceableCollection.cc.

References nextIndexOf(), and put().

00083 {
00084     long index = startIndex - 1;
00085 
00086     while ((index = nextIndexOf(element, index+1, stopIndex)) < stopIndex) {
00087         put(index, replacement);
00088     }
00089 }

void SequenceableCollection::replaceAll Object element,
Object replacement
[virtual]
 

Definition at line 76 of file SequenceableCollection.cc.

References size().

Referenced by Tools::HierarchicalConfigurationReader::parseLine(), and Tools::ConfigurationReader::readLine().

00077 {
00078     replaceAll(element, replacement, 0, size());
00079 }

virtual long Core::SequenceableCollection::size void   )  const [virtual]
 

Answer how many elements the collection includes.

Reimplemented from Core::Collection.

Reimplemented in Core::Array, Core::ByteArray, Core::OrderedCollection, and Core::String.

Referenced by asArray(), copyReplace(), endsWith(), Core::ExternalWriteStream::flush(), grow(), growToAtLeast(), indexOf(), indexOfSubCollection(), Core::PositionableStream::initialize(), last(), lastIndexOf(), Core::Stream::nextPutAll(), Core::InternalStream::nextPutAll(), operator+(), Core::InternalStream::pastEndPut(), OS::Process::privateExecuteJob(), privNextForIterator(), replace(), replaceAll(), and Core::SearchTreeNode::valueAt().

bool SequenceableCollection::startsWith SequenceableCollection coll  )  const [virtual]
 

Reimplemented in Core::String.

Definition at line 262 of file SequenceableCollection.cc.

References indexOfSubCollection(), and Core::Collection::isEmpty().

Referenced by Core::String::startsWith().

00263 {
00264     return indexOfSubCollection(coll) == 0 || coll->isEmpty();
00265 }

WriteStream * SequenceableCollection::writeStream void   )  [virtual]
 

Definition at line 203 of file SequenceableCollection.cc.

Referenced by Core::InternalEncodedStreamFactory::writeStream().

00204 {
00205     return new WriteStream(this);
00206 }


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