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

# /Users/fpy/titan-1-5-MBARI/Mers/Utils/Containers/DynamicArray.h

    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 #ifndef DYNAMICARRAYHEADERFILE
    00015 #define DYNAMICARRAYHEADERFILE
    00016
    00017 #include <Mers/Utils/Lang/BaseModelObject.h>
    00018 #include "Iterators.h"
    00019
    00020
    00021 namespace Mers {
    00022         namespace Utils {
    00023                 namespace Containers {
    00024
    00031                         class DynamicArray : public Mers::Utils::Lang::BaseModelObject
    00032                         {
    00033                         public:
    00048                                 enum DynamicArrayType {AssignmentArray = 0, ClauseArray = 1,
    00049                                         DomainArray = 2, ValueArray = 3, VariableArray = 4, GIEntryArray = 5,
    00050                                         IntegerArray = 6, oObjectArray = 7, oHCAAutomatonArray = 8,
    00051                                         oHCATransitionArray = 9, oMarkedAutomatonArray = 10,
    00052                                         oHCAFunctionCallArray = 11, oObjectQueue = 12, oGIStateHeap = 13,
    00053                                         oDynamicArrayTemplate = 14, DAVariableArrayArray = 15,
    00054                                         oEstimateHeap = 16, DAHBFIGImplicantHeap = 17,
    00055                                         oDynamicStackTemplate = 18
    00056                                 };
    00057
    00058                                 //-----------------------------------------
    00059                                 // Constructors
    00060                                 //-----------------------------------------
    00061
    00074                                 DynamicArray(DynamicArrayType myType, bool myOwnershipStatus,
    00075                                         BaseModelObject::ObjectType myObjectType =
    00076                                         BaseModelObject::BMDynamicArray);
    00077
    00078                                 //-----------------------------------------
    00079                                 // Destructors
    00080                                 //-----------------------------------------
    00081
    00085                                 virtual ~DynamicArray();
    00086
    00087                                 //-----------------------------------------
    00088                                 // Functions
    00089                                 //-----------------------------------------
    00090
    00099                                 static char const * dynamicArrayTypeToString(DynamicArrayType daType);
    00100
    00106                                 DynamicArrayType getDynamicArrayType() const;
    00107
    00118                                 void setOwnershipFlag(bool myOwnershipStatus);
    00119
    00126                                 void makeEmpty();
    00127
    00140                                 int resize(unsigned int newSize);
    00141
    00149                                 virtual unsigned int getLength() const;
    00157                                 unsigned int size() const
    00158                                 {
    00159                                         return getLength();
    00160                                 }
    00161
    00167                                 virtual bool isEmpty() const;
    00168
    00179                                 void * find(char const * elementName);
    00190                                 void const * find(char const * elementName) const;
    00191
    00197                                 void * & peekBack();
    00203                                 void const * & peekBack() const;
    00204
    00211                                 void erase(unsigned int elementIndex);
    00212
    00213                                 //-----------------------------------------
    00214                                 // Operators
    00215                                 //-----------------------------------------
    00216
    00225                                 void * &operator[](int elementIndex);
    00234                                 void * &operator[](unsigned int elementIndex);
    00243                                 void const * &operator[](int elementIndex) const;
    00252                                 void const * &operator[](unsigned int elementIndex) const;
    00253
    00254 #ifndef EMBEDDED
    00255
    00263                                 void print(std::ostream &out) const;
    00264
    00279                                 virtual void printArray(std::ostream &out, char const * seperator,
    00280                                         bool skipNULL = true);
    00295                                 virtual void printArray(std::ostream &out, char const * seperator,
    00296                                                                                                                                 bool skipNULL = true) const;
    00297 #endif
    00298
    00299                         protected:
    00300                                 //-----------------------------------------
    00301                                 // Copy constructors
    00302                                 //-----------------------------------------
    00303
    00310                                 DynamicArray(DynamicArray const &other);
    00311
    00312                                 //-----------------------------------------
    00313                                 // Functions
    00314                                 //-----------------------------------------
    00315
    00320                                 void deleteAll();
    00327                                 void clearAll();
    00328
    00329 #ifndef EMBEDDED
    00330
    00340                                 virtual void printElement(std::ostream &out,
    00341                                         void const * element) const = 0;
    00342 #endif
    00343
    00351                                 virtual void deleteElement(void * element) const = 0;
    00360                                 virtual void * newElement(void const * element) const = 0;
    00372                                 virtual bool foundMatch(char const * elementName,
    00373                                         void const * element) const;
    00385                                 virtual bool isEqual(void const * element1,
    00386                                         void const * element2) const;
    00387
    00394                                 virtual void destroy();
    00407                                 virtual int copy(DynamicArray const &other);
    00408
    00416                                 int grow();
    00425                                 int shrink();
    00426
    00438                                 int pushBack(void * data);
    00439
    00447                                 void * popBack();
    00448
    00457                                 void insert(unsigned int elementIndex, void * data);
    00458
    00468                                 DynamicArray const & operator =(DynamicArray const &other);
    00477                                 DynamicArray const & operator +=(DynamicArray const &other);
    00486                                 DynamicArray const & operator +=(void const * other);
    00487
    00497                                 bool operator ==(DynamicArray const &other) const;
    00507                                 bool operator !=(DynamicArray const &other) const;
    00508
    00509                         protected:
    00510                                 //-----------------------------------------
    00511                                 // Data
    00512                                 //-----------------------------------------
    00513
    00515                                 DynamicArrayType const dynamicArrayType;
    00517                                 unsigned int mSize;
    00519                                 unsigned int maxSize;
    00521                                 void ** array;
    00522
    00524                                 bool ownsElements;
    00525
    00526                         private:
    00527                                 //-----------------------------------------
    00528                                 // Private Static Data
    00529                                 //-----------------------------------------
    00530
    00534                                 static void * nullPointer;
    00535
    00536                         private:
    00537                                 // disallow these:
    00538                         };
    00539                 }
    00540         }
    00541 }
    00542
    00543 #endif