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

# /Users/fpy/titan-1-5-MBARI/Mers/Models/CCA/CCATransitions.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 "CCATransitions.h"
    00015
    00016 #include <cstdio>
    00017 #include <cassert>
    00018
    00020
    00021 using namespace Mers::Models::CCA;
    00022 using std::ostream;
    00023 using std::endl;
    00024
    00026 // Constructors, Copy Constructors, & Destructors
    00028
    00029 CCATransitions::CCATransitions(bool myOwnershipStatus)
    00030 : ObjectArray(myOwnershipStatus)
    00031 {
    00032         hasReferences = false;
    00033 }
    00034
    00035 CCATransitions::CCATransitions(const CCATransitions &other)
    00036 : ObjectArray(other)
    00037 {
    00038         hasReferences = other.hasReferences;
    00039 }
    00040
    00041 CCATransitions::~CCATransitions()
    00042 {
    00043         if(hasReferences)
    00044                 clearAll();
    00045 }
    00046
    00048 // Public Function Members
    00050
    00051 bool CCATransitions::empty() const
    00052 {
    00053         return isEmpty();
    00054 }
    00055
    00056 void CCATransitions::clear()
    00057 {
    00058         makeEmpty();
    00059 }
    00060
    00062
    00063 CCATransitions::const_iterator
    00064 CCATransitions::insert_transition(const CCATransition &new_transition)
    00065 {
    00066         for (const_iterator const_it = begin(); const_it != end(); const_it++) {
    00067                 if (*const_it == new_transition)
    00068                         return end();
    00069         }
    00070         CCATransition * transition = (CCATransition *) newElement(&new_transition);
    00071         if(!transition){
    00072                 fprintf(stderr, "CCATransitions::insert_transition: Unable to copy transition\n");
    00073                 return end();
    00074         }
    00075         if(FAILED(pushBack(transition)))
    00076                 return end();
    00077         return --end();
    00078 }
    00079
    00081
    00082 CCATransitions::const_iterator
    00083 CCATransitions::insert_transition_p(CCATransition * new_transition)
    00084 {
    00085         hasReferences = true;
    00086         for (const_iterator const_it = begin(); const_it != end(); const_it++) {
    00087                 if (*const_it == *new_transition)
    00088                         return end();
    00089         }
    00090         if(FAILED(pushBack(NULL)))
    00091                 return end();
    00092         // record a reference to this object - we don't own it
    00093         operator[](getLength() - 1) = new_transition;
    00094         return --end();
    00095 }
    00096
    00098
    00099 int CCATransitions::pushBack(CCATransition * data)
    00100 {
    00101         if(data)
    00102                 data->setUID(getLength());
    00103         return ObjectArray::pushBack(data);
    00104 }
    00105
    00107
    00108 CCATransition * CCATransitions::popBack()
    00109 {
    00110         return (CCATransition *) ObjectArray::popBack();
    00111 }
    00112
    00114
    00115 #ifndef EMBEDDED
    00116
    00117 void CCATransitions::print(ostream &out) const
    00118 {
    00119         out << "Transitions:" << endl;
    00120         printArray(out, "\n");
    00121 }
    00122
    00123 #endif
    00124
    00126 // Public Operators
    00128
    00129 bool CCATransitions::operator ==(const CCATransitions &other) const
    00130 {
    00131         return ObjectArray::operator ==(other);
    00132 }
    00133
    00135
    00136 bool CCATransitions::operator !=(const CCATransitions &other) const
    00137 {
    00138         return !operator ==(other);
    00139 }
    00140
    00142
    00143 CCATransition * & CCATransitions::operator[](int elementIndex)
    00144 {
    00145         return (CCATransition * &) ObjectArray::operator [](elementIndex);
    00146 }
    00147
    00149
    00150 CCATransition * & CCATransitions::operator[](unsigned int elementIndex)
    00151 {
    00152         return (CCATransition * &) ObjectArray::operator [](elementIndex);
    00153 }
    00154
    00156
    00157 CCATransition const * & CCATransitions::operator[](int elementIndex) const
    00158 {
    00159         return (CCATransition const * &) ObjectArray::operator [](elementIndex);
    00160 }
    00161
    00163
    00164 CCATransition const * & CCATransitions::operator[](unsigned int elementIndex) const
    00165 {
    00166         return (CCATransition const * &) ObjectArray::operator [](elementIndex);
    00167 }
    00168
    00170
    00171 const CCATransitions & CCATransitions::operator =(const CCATransitions &other)
    00172 {
    00173         ObjectArray::operator =(other);
    00174         return (*this);
    00175 }
    00176
    00178
    00179 const CCATransitions & CCATransitions::operator +=(const CCATransitions &other)
    00180 {
    00181         ObjectArray::operator +=(other);
    00182         return (*this);
    00183 }
    00184
    00186
    00187 const CCATransitions & CCATransitions::operator +=(const CCATransition &data)
    00188 {
    00189         ObjectArray::operator +=(data);
    00190         return (*this);
    00191 }
    00192
    00194 // Protected Function Members
    00196
    00197 void * CCATransitions::newElement(void const * element) const
    00198 {
    00199         if(hasReferences)
    00200                 return (void *) element;
    00201         else
    00202                 return new CCATransition(*(CCATransition const *) element);
    00203 }
    00204
    00206
    00207 bool CCATransitions::isEqual(void const * element1, void const * element2) const
    00208 {
    00209         CCATransition const * e1 = (CCATransition const *) element1;
    00210         CCATransition const * e2 = (CCATransition const *) element2;
    00211         return e1->operator ==(*e2);
    00212 }
    00213
    00215