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

# /Users/fpy/titan-1-5-MBARI/Mers/Utils/Containers/DynamicStackTemplate.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 DYNAMIC_ARRAY_STACK_TEMPLATE_HEADER_FILE
    00015 #define DYNAMIC_ARRAY_STACK_TEMPLATE_HEADER_FILE
    00016
    00017 #include <cassert>
    00018
    00019 #include "DynamicArray.h"
    00020
    00021 namespace Mers {
    00022         namespace Utils {
    00023                 namespace Containers {
    00024
    00028                         template<class Data> class StackTemplate : protected DynamicArray
    00029                         {
    00030                         public:
    00031                                 typedef Data value_type;
    00032                                 typedef Data & reference;
    00033                                 typedef const Data & const_reference;
    00034
    00036                                 // Constructors
    00038
    00042                                 StackTemplate(bool myOwnershipStatus)
    00043                                         : DynamicArray(DynamicArray::oDynamicStackTemplate,
    00044                                                 myOwnershipStatus)
    00045                                 {
    00046                                 }
    00047
    00049                                 // Destructors
    00051
    00055                                 virtual ~StackTemplate()
    00056                                 {
    00057                                         makeEmpty();
    00058                                 }
    00059
    00061                                 // Iterators
    00063
    00064                                 typedef Data * pointer;
    00065                                 typedef const Data * const_pointer;
    00066                                 typedef StackTemplate<Data> ContainerType;
    00067                                 typedef IteratorTemplate<const_pointer, ContainerType> const_iterator;
    00068                                 typedef IteratorTemplate<pointer, ContainerType> iterator;
    00069                                 typedef const_iterator ConstantIterator;
    00070                                 typedef iterator Iterator;
    00071
    00073                                 // Functions
    00075
    00080                                 iterator begin()
    00081                                 {
    00082                                         return iterator(this, 0);
    00083                                 }
    00090                                 const_iterator begin() const
    00091                                 {
    00092                                         return const_iterator((ContainerType *)this, 0);
    00093                                 }
    00094
    00101                                 iterator end()
    00102                                 {
    00103                                         return iterator(this, getLength());
    00104                                 }
    00111                                 const_iterator end() const
    00112                                 {
    00113                                         return const_iterator((ContainerType *)this, getLength());
    00114                                 }
    00115
    00128                                 virtual int push(pointer data)
    00129                                 {
    00130                                         return DynamicArray::pushBack((void *)data);
    00131                                 }
    00132
    00141                                 virtual pointer pop()
    00142                                 {
    00143                                         return (pointer) DynamicArray::popBack();
    00144                                 }
    00145
    00149                                 virtual bool empty() const {
    00150                                         return DynamicArray::isEmpty();
    00151                                 }
    00152
    00156                                 virtual unsigned int size() const {
    00157                                         return DynamicArray::getLength();
    00158                                 }
    00159
    00163                                 virtual reference top() {
    00164                                         return *(pointer) DynamicArray::peekBack();
    00165                                 }
    00166
    00170                                 virtual const_reference top() const {
    00171                                         return *(const_pointer) DynamicArray::peekBack();
    00172                                 }
    00173
    00179                                 virtual void clear() {
    00180                                         DynamicArray::makeEmpty();
    00181                                 }
    00182
    00184                                 // Operators
    00186
    00194                                 pointer & operator[](int elementIndex)
    00195                                 {
    00196                                         return (pointer &) DynamicArray::operator [](elementIndex);
    00197                                 }
    00198
    00205                                 pointer & operator[](unsigned int elementIndex)
    00206                                 {
    00207                                         return (pointer &) DynamicArray::operator [](elementIndex);
    00208                                 }
    00209
    00216                                 const_pointer operator[](int elementIndex) const
    00217                                 {
    00218                                         return (const_pointer) DynamicArray::operator [](elementIndex);
    00219                                 }
    00220
    00227                                 const_pointer operator[](unsigned int elementIndex) const
    00228                                 {
    00229                                         return (const_pointer) DynamicArray::operator [](elementIndex);
    00230                                 }
    00231
    00232 #ifndef EMBEDDED
    00233
    00243                                 friend std::ostream & operator <<(std::ostream &out,
    00244                                         const ContainerType &other) {
    00245                                         other.print(out);
    00246                                 }
    00247 #endif
    00248
    00249                         private:
    00253                                 StackTemplate(const ContainerType &other);
    00254
    00255                         protected:
    00257                                 // Functions
    00259
    00260 #ifndef EMBEDDED
    00261
    00270                                 void printElement(std::ostream &out, void const * element) const
    00271                                 {
    00272                                         pointer p = (pointer) element;
    00273                                         out << *p;
    00274                                 }
    00275
    00276 #endif
    00277
    00285                                 void deleteElement(void * element) const
    00286                                 {
    00287                                         delete (pointer) element;
    00288                                 }
    00289
    00296                                 void * newElement(void const * element) const
    00297                                 {
    00298                                         return NULL;
    00299                                 }
    00300
    00308                                 bool isEqual(void const * element1, void const * element2) const
    00309                                 {
    00310                                         const_reference e1 = *(const_pointer) element1;
    00311                                         const_reference e2 = *(const_pointer) element2;
    00312                                         return (e1 == e2);
    00313                                 }
    00314                         };
    00315
    00316                 }
    00317         }
    00318 }
    00319
    00320 #endif
    00321