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

# /Users/fpy/titan-1-5-MBARI/Mers/Utils/Containers/ObjectArray.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 "ObjectArray.h"
    00015 #include <assert.h>
    00016 #include <stdio.h>
    00017
    00019
    00020 using namespace Mers::Utils::Containers;
    00021 using Mers::Utils::Lang::BaseModelObject;
    00022 using std::ostream;
    00023 using std::cerr;
    00024 using std::endl;
    00025
    00027 // Construction/Destruction
    00029
    00030 ObjectArray::ObjectArray(bool myOwnershipStatus)
    00031 : DynamicArray(DynamicArray::oObjectArray, myOwnershipStatus)
    00032 {
    00033
    00034 }
    00035
    00037
    00038 ObjectArray::ObjectArray(ObjectArray const &other)
    00039 : DynamicArray(other)
    00040 {
    00041         assert(other.getDynamicArrayType() == DynamicArray::oObjectArray);
    00042         if(FAILED(copy(other))){
    00043 #ifndef EMBEDDED
    00044                 cerr << "Unable to copy while constructing a new ObjectArray: " << endl << other << endl;
    00045 #else
    00046                 fprintf(stderr, "Error, failed to copy the ObjectArray while constructing a new one\n");
    00047 #endif
    00048         }
    00049 }
    00050
    00052
    00053 ObjectArray::ObjectArray(ObjectArray const * other)
    00054 : DynamicArray(*other)
    00055 {
    00056         assert(other->getDynamicArrayType() == DynamicArray::oObjectArray);
    00057         if(FAILED(copy(*other))){
    00058 #ifndef EMBEDDED
    00059                 cerr << "Unable to copy while constructing a new ObjectArray: " << endl << other << endl;
    00060 #else
    00061                 fprintf(stderr, "Error, failed to copy the ObjectArray while constructing a new one\n");
    00062 #endif
    00063         }
    00064 }
    00065
    00067
    00068 ObjectArray::~ObjectArray()
    00069 {
    00070         destroy();
    00071 }
    00072
    00074
    00075 int ObjectArray::pushBack(BaseModelObject * data)
    00076 {
    00077         return DynamicArray::pushBack((void *)data);
    00078 }
    00079
    00081
    00082 BaseModelObject * ObjectArray::popBack()
    00083 {
    00084         return (BaseModelObject *) DynamicArray::popBack();
    00085 }
    00086
    00088
    00089 BaseModelObject * & ObjectArray::operator[](int elementIndex)
    00090 {
    00091         return (BaseModelObject * &) DynamicArray::operator [](elementIndex);
    00092 }
    00093
    00095
    00096 BaseModelObject * & ObjectArray::operator[](unsigned int elementIndex)
    00097 {
    00098         return (BaseModelObject * &) DynamicArray::operator [](elementIndex);
    00099 }
    00100
    00102
    00103 BaseModelObject const * &
    00104 ObjectArray::operator[](int elementIndex) const
    00105 {
    00106         return (BaseModelObject const * &) DynamicArray::operator [](elementIndex);
    00107 }
    00108
    00110
    00111 BaseModelObject const * &
    00112 ObjectArray::operator[](unsigned int elementIndex) const
    00113 {
    00114         return (BaseModelObject const * &) DynamicArray::operator [](elementIndex);
    00115 }
    00116
    00118
    00119 ObjectArray const &
    00120 ObjectArray::operator =(ObjectArray const &other)
    00121 {
    00122         return (ObjectArray const &) DynamicArray::operator =(other);
    00123 }
    00124
    00126
    00127 ObjectArray const &
    00128 ObjectArray::operator +=(ObjectArray const &other)
    00129 {
    00130         return (ObjectArray const &) DynamicArray::operator +=(other);
    00131 }
    00132
    00134
    00135 ObjectArray const &
    00136 ObjectArray::operator +=(BaseModelObject const &data)
    00137 {
    00138         return (ObjectArray const &) DynamicArray::operator +=((void const *)&data);
    00139 }
    00140
    00142
    00143 bool ObjectArray::operator ==(ObjectArray const &other) const
    00144 {
    00145         return DynamicArray::operator ==(other);
    00146 }
    00147
    00149
    00150 bool ObjectArray::operator !=(ObjectArray const &other) const
    00151 {
    00152         return !DynamicArray::operator ==(other);
    00153 }
    00154
    00156
    00157 #ifndef EMBEDDED
    00158
    00159 void ObjectArray::printElement(ostream &out, void const * element) const
    00160 {
    00161         ((BaseModelObject *) element)->print(out);
    00162 }
    00163
    00164 #endif
    00165
    00167
    00168 void ObjectArray::deleteElement(void * element) const
    00169 {
    00170         delete (BaseModelObject *) element;
    00171 }
    00172
    00174
    00175 void * ObjectArray::newElement(void const * element) const
    00176 {
    00177         (void) element;
    00178         fprintf(stderr, "Cannot currently copy an Object Array Element\n");
    00179         return NULL;
    00180
    00181         // Probably want something like this, but...
    00182         //return ((BaseModelObject *) element)->duplicate();
    00183 }
    00184
    00186
    00187 bool ObjectArray::isEqual(void const * element1, void const * element2) const
    00188 {
    00189         // should we warn that we're just doing pointer comparisons?
    00190         return (element1 == element2);
    00191
    00192         // should there be a global ==?
    00193         //return (*(BaseModelObject *)element1) == (*(BaseModelObject *)element2);
    00194 }
    00195