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

Core::Array Class Reference

#include <Array.h>

Inheritance diagram for Core::Array:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Array (int size=0)
virtual ~Array (void)
 Array (const Array &origin)
virtual StringclassName (void) const
 Answer receiver class name.
virtual Objectany (void)
 Answer any item from the collection.
virtual Objectat (int index) const
virtual void put (int index, Object *obj)
virtual long size (void) const
 Answer how many elements the collection includes.
virtual void add (Object *)
virtual void changeSize (long newSize)
virtual ArrayasArray (void)
virtual Objectcopy (void)
virtual Objectcopy (long from, long to)
 Returns a new collection with the same items as the specified portion of this collection.
virtual ObjectcopyEmpty (long size)

Static Public Member Functions

static Arraywith (Object *object)
static Arraywith (Object *obj1, Object *obj2)
static Arraywith (Object *obj1, Object *obj2, Object *obj3)
static Arraywith (Object *obj1, Object *obj2, Object *obj3, Object *obj4)
static ArraywithAll (Collection *coll)

Protected Member Functions

virtual ObjectprivNextForIterator (CollectionIterator *i) const

Protected Attributes

Object ** content
int tally

Constructor & Destructor Documentation

Array::Array int  size = 0  ) 
 

Definition at line 31 of file Array.cc.

References content, nil, and tally.

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

00032 {
00033     content = NULL;
00034     tally = size;
00035     if (tally > 0) {
00036         content = (Object **) GC_malloc(sizeof(Object *) * tally);
00037         for (int i = 0; i < tally; i++) {
00038             content[i] = nil;
00039         }
00040     }
00041 }

Array::~Array void   )  [virtual]
 

Definition at line 43 of file Array.cc.

References content.

00044 {
00045     if (content != NULL) {
00046         GC_free(content);
00047     }
00048 }

Array::Array const Array origin  ) 
 

Definition at line 51 of file Array.cc.

References content, and tally.

00052   : SequenceableCollection(origin)
00053 {
00054     content = NULL;
00055     tally = origin.tally;
00056     if (tally > 0) {
00057         content = (Object **) GC_malloc(sizeof(Object *) * tally);
00058         for (int i = 0; i < tally; i++) {
00059             content[i] = origin.content[i];
00060         }
00061     }
00062 }


Member Function Documentation

void Array::add Object  )  [virtual]
 

Reimplemented from Core::Collection.

Definition at line 152 of file Array.cc.

References Core::Object::shouldNotImplement().

00153 {
00154     shouldNotImplement(new String(__PRETTY_FUNCTION__));
00155 }

Object * Array::any void   )  [virtual]
 

Answer any item from the collection.

Reimplemented from Core::SequenceableCollection.

Definition at line 116 of file Array.cc.

References at(), nil, and tally.

Referenced by Core::Set::any().

00117 {
00118     long idx = 0;
00119     do {
00120         if (at(idx) != nil) return at(idx);
00121         idx++;
00122     } while (idx < tally);
00123     return nil;
00124 }

Array * Array::asArray void   )  [virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 179 of file Array.cc.

00180 {
00181     return this;
00182 }

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

Reimplemented from Core::SequenceableCollection.

Definition at line 126 of file Array.cc.

References content, Core::GenericException::raiseFrom(), and tally.

Referenced by Core::Dictionary::add(), any(), Core::OrderedCollection::at(), Core::Dictionary::at(), Core::CharacterArray::at(), Core::OrderedCollection::changeCapacity(), Core::ByteCharacterEncoder::decode(), Core::Set::findElementOrNil(), Core::Dictionary::findKey(), Core::Dictionary::findKeyOrNil(), Core::OrderedCollection::first(), Core::Set::fixCollisionsFrom(), Core::Dictionary::fixCollisionsFrom(), Core::Dictionary::includesKey(), Core::Set::isEmptyAt(), Core::OrderedCollection::last(), Core::OrderedCollection::makeRoomAtFirst(), Core::OrderedCollection::makeRoomAtLast(), Core::ByteCharacterEncoder::parseLine(), OS::Process::privateExecuteJob(), Core::Set::privAtIndex(), Core::Set::privNextForIterator(), Core::OrderedCollection::privNextForIterator(), privNextForIterator(), Core::Dictionary::put(), Core::OrderedCollection::remove(), Core::OrderedCollection::removeFirst(), Core::OrderedCollection::removeIndex(), Core::Dictionary::removeKey(), Core::OrderedCollection::removeLast(), Net::IPSocketAddress::stringToBytes(), and Core::Integer::value().

00127 {
00128     if (index < 0 || index >= tally) {
00129         SubscriptOutOfBoundsError *ex;
00130         ex = new SubscriptOutOfBoundsError(__PRETTY_FUNCTION__, index);
00131         ex->raiseFrom(this);
00132     }
00133     return content[index];
00134 }

void Array::changeSize long  newSize  )  [virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 157 of file Array.cc.

References content, nil, and tally.

Referenced by Core::CharacterArray::changeSize().

00158 {
00159     Object **oldContent = content;
00160     long oldSize = tally;
00161     long i;
00162 
00163     content = (Object **) GC_malloc(sizeof(Object *) * newSize);
00164     tally = newSize;
00165 
00166     /* Copy old content or the part that fits */
00167     for (i = 0; i < oldSize && i < tally; i++) {
00168         content[i] = oldContent[i];
00169     }
00170     /* Fill the rest with nils */
00171     for (; i < tally; i++) {
00172         content[i] = nil;
00173     }
00174 
00175     GC_free(oldContent);
00176 }

String * Array::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 65 of file Array.cc.

00066 {
00067     return new String("Array");
00068 }

virtual Object* Core::Array::copy long  from,
long  to
[inline, 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 from Core::SequenceableCollection.

Definition at line 73 of file Array.h.

References Core::SequenceableCollection::copy().

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

Object * Array::copy void   )  [virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 185 of file Array.cc.

References Array().

Referenced by Core::OrderedCollection::OrderedCollection(), and Core::Set::Set().

00186 {
00187     return new Array(*this);
00188 }

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

Reimplemented from Core::Collection.

Definition at line 190 of file Array.cc.

References Array().

00191 {
00192     return new Array(size);
00193 }

Object * Array::privNextForIterator CollectionIterator i  )  const [protected, virtual]
 

Reimplemented from Core::SequenceableCollection.

Definition at line 197 of file Array.cc.

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

00198 {
00199     return at(iter->position());
00200 }

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

Reimplemented from Core::SequenceableCollection.

Definition at line 136 of file Array.cc.

References content, Core::GenericException::raiseFrom(), and tally.

Referenced by Core::OrderedCollection::addFirst(), Core::OrderedCollection::addLast(), Core::SequenceableCollection::asArray(), Core::Collection::asArray(), Core::Set::atNewIndexPut(), Core::OrderedCollection::changeCapacity(), Core::Set::fixCollisionsFrom(), Core::Dictionary::fixCollisionsFrom(), Core::ByteCharacterEncoder::initializeAsciiEncoder(), Core::OrderedCollection::makeRoomAtFirst(), Core::OrderedCollection::makeRoomAtLast(), Core::Dictionary::noCheckAdd(), Core::ByteCharacterEncoder::parseLine(), Tools::CommandLineParser::process(), Core::OrderedCollection::put(), Core::CharacterArray::put(), Core::Set::remove(), Core::OrderedCollection::removeFirst(), Core::OrderedCollection::removeIndex(), Core::Dictionary::removeKey(), Core::OrderedCollection::removeLast(), Core::Integer::value(), with(), and withAll().

00137 {
00138     if (index < 0 || index >= tally) {
00139         SubscriptOutOfBoundsError *ex;
00140         ex = new SubscriptOutOfBoundsError(__PRETTY_FUNCTION__, index);
00141         ex->raiseFrom(this);
00142     }
00143     content[index] = obj;
00144 }

long Array::size void   )  const [virtual]
 

Answer how many elements the collection includes.

Reimplemented from Core::SequenceableCollection.

Definition at line 146 of file Array.cc.

References tally.

Referenced by Core::Set::capacity(), Core::OrderedCollection::capacity(), Core::ByteCharacterEncoder::parseLine(), Core::CharacterArray::size(), and Net::IPSocketAddress::stringToBytes().

00147 {
00148     return tally;
00149 }

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

Definition at line 95 of file Array.cc.

References Array(), and put().

00096 {
00097     Array *newArray = new Array(4);
00098     newArray->put(0, obj1);
00099     newArray->put(1, obj2);
00100     newArray->put(2, obj3);
00101     newArray->put(3, obj4);
00102     return newArray;
00103 }

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

Definition at line 86 of file Array.cc.

References Array(), and put().

00087 {
00088     Array *newArray = new Array(3);
00089     newArray->put(0, obj1);
00090     newArray->put(1, obj2);
00091     newArray->put(2, obj3);
00092     return newArray;
00093 }

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

Definition at line 78 of file Array.cc.

References Array(), and put().

00079 {
00080     Array *newArray = new Array(2);
00081     newArray->put(0, obj1);
00082     newArray->put(1, obj2);
00083     return newArray;
00084 }

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

Definition at line 71 of file Array.cc.

References Array(), and put().

00072 {
00073     Array *newArray = new Array(1);
00074     newArray->put(0, object);
00075     return newArray;
00076 }

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

Definition at line 105 of file Array.cc.

References Array(), and put().

00106 {
00107     Array *newArray = new Array(coll->size());
00108     int index = 0;
00109     for (Iterator *i = coll->iterator(); !i->finished(); i->next()) {
00110         newArray->put(index++, i->value());
00111     }
00112     return newArray;
00113 }


Member Data Documentation

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

Definition at line 37 of file Array.h.

Referenced by Array(), at(), changeSize(), put(), and ~Array().

int Core::Array::tally [protected]
 

Definition at line 38 of file Array.h.

Referenced by any(), Array(), at(), changeSize(), put(), and size().


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