- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Utils/Containers/IntegerArray.cpp

    00001
    00002 //
    00003 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00009 // Organization:        Model-based Embedded and Robotic Systems Group
    00010 //                                      Massachusetts Institute of Technology
    00011 //
    00013
    00014 #include "IntegerArray.h"
    00015 #include <assert.h>
    00016 #include <stdio.h>
    00017 #include <string.h>
    00018
    00020
    00021 using namespace Mers::Utils::Containers;
    00022 using std::ostream;
    00023 using std::cerr;
    00024 using std::endl;
    00025
    00027 // Construction/Destruction
    00029
    00030 IntegerArray::IntegerArray()
    00031 // Note that we do not "own" our "pointers" since they're just integers
    00032 : DynamicArray(DynamicArray::IntegerArray, false)
    00033 {
    00034
    00035 }
    00036
    00038
    00039 IntegerArray::IntegerArray(IntegerArray const &other)
    00040 : DynamicArray(other)
    00041 {
    00042         assert(other.getDynamicArrayType() == DynamicArray::IntegerArray);
    00043         if(FAILED(copy(other))){
    00044 #ifndef EMBEDDED
    00045                 cerr << "Unable to copy while constructing a new IntegerArray: " << endl << other << endl;
    00046 #else
    00047                 fprintf(stderr, "Error, failed to copy the IntegerArray while constructing a new one\n");
    00048 #endif
    00049         }
    00050 }
    00051
    00053
    00054 IntegerArray::IntegerArray(IntegerArray const * other)
    00055 : DynamicArray(*other)
    00056 {
    00057         assert(other->getDynamicArrayType() == DynamicArray::IntegerArray);
    00058         if(FAILED(copy(*other))){
    00059 #ifndef EMBEDDED
    00060                 cerr << "Unable to copy while constructing a new IntegerArray: " << endl << other << endl;
    00061 #else
    00062                 fprintf(stderr, "Error, failed to copy the IntegerArray while constructing a new one\n");
    00063 #endif
    00064         }
    00065 }
    00066
    00068
    00069 IntegerArray::~IntegerArray()
    00070 {
    00071         makeEmpty();
    00072 }
    00073
    00075
    00076 int IntegerArray::pushBack(int data)
    00077 {
    00078         return DynamicArray::pushBack((void *)data);
    00079 }
    00080
    00082
    00083 int IntegerArray::popBack()
    00084 {
    00085         return (int) DynamicArray::popBack();
    00086 }
    00087
    00089
    00090 void IntegerArray::setArrayTo(int value)
    00091 {
    00092         void ** trace = array;
    00093         unsigned int x;
    00094
    00095         for(x = 0; x < mSize; x++){
    00096                 *(trace++) = (void *) value;
    00097         }
    00098 }
    00099
    00101
    00102 void IntegerArray::setArrayToZero()
    00103 {
    00104         if(mSize > 0)
    00105                 memset(array, 0, sizeof(void *) * mSize);
    00106 }
    00107
    00109
    00110 int & IntegerArray::operator[](int elementIndex)
    00111 {
    00112         return (int &) DynamicArray::operator [](elementIndex);
    00113 }
    00114
    00116
    00117 int & IntegerArray::operator[](unsigned int elementIndex)
    00118 {
    00119         return (int &) DynamicArray::operator [](elementIndex);
    00120 }
    00121
    00123
    00124 int &
    00125 IntegerArray::operator[](int elementIndex) const
    00126 {
    00127         return (int &) DynamicArray::operator [](elementIndex);
    00128 }
    00129
    00131
    00132 int &
    00133 IntegerArray::operator[](unsigned int elementIndex) const
    00134 {
    00135         return (int &) DynamicArray::operator [](elementIndex);
    00136 }
    00137
    00139
    00140 IntegerArray const &
    00141 IntegerArray::operator =(IntegerArray const &other)
    00142 {
    00143         return (IntegerArray const &) DynamicArray::operator =(other);
    00144 }
    00145
    00147
    00148 IntegerArray const &
    00149 IntegerArray::operator +=(IntegerArray const &other)
    00150 {
    00151         return (IntegerArray const &) DynamicArray::operator +=(other);
    00152 }
    00153
    00155
    00156 IntegerArray const &
    00157 IntegerArray::operator +=(int data)
    00158 {
    00159         return (IntegerArray const &) DynamicArray::operator +=((void const *)data);
    00160 }
    00161
    00163
    00164 #ifndef EMBEDDED
    00165
    00166 void IntegerArray::print(ostream &out) const
    00167 {
    00168         printArray(out, ", ", false);
    00169 }
    00170
    00171 void IntegerArray::printElement(ostream &out, void const * element) const
    00172 {
    00173         out << ((int) element);
    00174 }
    00175
    00176 #endif
    00177
    00179
    00180 void IntegerArray::deleteElement(void * element) const
    00181 {
    00182         // don't need to delete an int
    00183         (void) element;
    00184 }
    00185
    00187
    00188 void * IntegerArray::newElement(void const * element) const
    00189 {
    00190         int t = (int)element;
    00191         return (void *)t;
    00192 }
    00193
    00195
    00196 bool IntegerArray::isEqual(void const * element1, void const * element2) const
    00197 {
    00198         return ((int)element1) == ((int)element2);
    00199 }
    00200