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

# /Users/fpy/titan-1-5-MBARI/Mers/Models/CCA/CCAStates.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 "CCAStates.h"
    00015
    00016 #include <cstdio>
    00017 #include <cassert>
    00018
    00019 #include "CCATransition.h"
    00020 #include "CCAAutomaton.h"
    00021 #include "CCAModel.h"
    00022
    00024
    00025 using namespace Mers::Models::CCA;
    00026 using std::ostream;
    00027
    00029 // Constructors, Copy Constructors, & Destructors
    00031
    00032 CCAStates::CCAStates(bool myOwnershipStatus)
    00033 : ObjectArray(myOwnershipStatus)
    00034 {
    00035 }
    00036
    00037 CCAStates::CCAStates(const CCAStates &other)
    00038 : ObjectArray(other)
    00039 {
    00040 }
    00041
    00042 CCAStates::~CCAStates()
    00043 {
    00044 }
    00045
    00047 // Public Function Members
    00049
    00050 bool CCAStates::empty() const
    00051 {
    00052         return isEmpty();
    00053 }
    00054
    00055 void CCAStates::clear()
    00056 {
    00057         makeEmpty();
    00058 }
    00059
    00061
    00062 bool CCAStates::set_automaton_p(const CCAAutomaton &_automaton)
    00063 {
    00064         for (CCAStates::iterator it = begin(); it != end(); it++) {
    00065                 it->set_automaton_p(_automaton);
    00066         }
    00067         return true;
    00068 }
    00069
    00070 const CCAState *CCAStates::state_p(const CCAValue &_value) const
    00071 {
    00072         for (const_iterator const_it = begin(); const_it != end(); const_it++) {
    00073                 if (const_it->value_p() == &_value)
    00074                         return &*const_it;
    00075         }
    00076         return NULL;
    00077 }
    00078
    00079 CCAStates::const_iterator CCAStates::insert_state(const CCAState &new_state)
    00080 {
    00081         for (const_iterator const_it = begin(); const_it != end(); const_it++) {
    00082                 if (*const_it == new_state)
    00083                         return end();
    00084         }
    00085         CCAState * state = (CCAState *) newElement(&new_state);
    00086         if(!state){
    00087                 fprintf(stderr, "CCAStates::insert_state: Unable to copy state\n");
    00088                 return end();
    00089         }
    00090         if(FAILED(pushBack(state)))
    00091                 return end();
    00092         return --end();
    00093 }
    00094
    00095 bool CCAStates::insert_in_transition(const CCAState &_state,
    00096                                                                      CCATransition * _transition)
    00097 {
    00098         for (iterator it = begin(); it != end(); it++) {
    00099                 if (*it == _state) {
    00100                         it->insert_in_transition(_transition);
    00101                         return true;
    00102                 }
    00103         }
    00104         return false;
    00105 }
    00106
    00107 bool CCAStates::insert_out_transition(const CCAState &_state,
    00108                                                                       CCATransition * _transition)
    00109 {
    00110         for (iterator it = begin(); it != end(); it++) {
    00111                 if (*it == _state) {
    00112                         it->insert_out_transition(_transition);
    00113                         return true;
    00114                 }
    00115         }
    00116         return false;
    00117 }
    00118
    00119 bool CCAStates::set_type(const CCAState &_state, const CCAState::StateType _type)
    00120 {
    00121         for (iterator it = begin(); it != end(); it++) {
    00122                 if (*it == _state) {
    00123                         it->set_type(_type);
    00124                         return true;
    00125                 }
    00126         }
    00127         return false;
    00128 }
    00129
    00130 bool CCAStates::set_constraint(const CCAState &_state,
    00131                                                         const CCASentence &_constraint)
    00132 {
    00133         for (iterator it = begin(); it != end(); it++) {
    00134                 if (*it == _state) {
    00135                         it->set_constraint(_constraint);
    00136                         return true;
    00137                 }
    00138         }
    00139         return false;
    00140 }
    00141
    00143
    00144 int CCAStates::pushBack(CCAState * data)
    00145 {
    00146         data->setUID(getLength());
    00147         return ObjectArray::pushBack(data);
    00148 }
    00149
    00151
    00152 CCAState * CCAStates::popBack()
    00153 {
    00154         return (CCAState *) ObjectArray::popBack();
    00155 }
    00156
    00158
    00159 #ifndef EMBEDDED
    00160
    00161 void CCAStates::print(ostream &out) const
    00162 {
    00163         printArray(out, "\n");
    00164 }
    00165
    00166 #endif
    00167
    00169 // Public Operators
    00171
    00172 bool CCAStates::operator ==(const CCAStates &other) const
    00173 {
    00174         return ObjectArray::operator ==(other);
    00175 }
    00176
    00177 bool CCAStates::operator !=(const CCAStates &other) const
    00178 {
    00179         return !operator ==(other);
    00180 }
    00181
    00183
    00184 CCAState * & CCAStates::operator[](int elementIndex)
    00185 {
    00186         return (CCAState * &) ObjectArray::operator [](elementIndex);
    00187 }
    00188
    00190
    00191 CCAState * & CCAStates::operator[](unsigned int elementIndex)
    00192 {
    00193         return (CCAState * &) ObjectArray::operator [](elementIndex);
    00194 }
    00195
    00197
    00198 CCAState const * & CCAStates::operator[](int elementIndex) const
    00199 {
    00200         return (CCAState const * &) ObjectArray::operator [](elementIndex);
    00201 }
    00202
    00204
    00205 CCAState const * & CCAStates::operator[](unsigned int elementIndex) const
    00206 {
    00207         return (CCAState const * &) ObjectArray::operator [](elementIndex);
    00208 }
    00209
    00211
    00212 const CCAStates & CCAStates::operator =(const CCAStates &other)
    00213 {
    00214         ObjectArray::operator =(other);
    00215         return (*this);
    00216 }
    00217
    00219
    00220 CCAStates const & CCAStates::operator +=(CCAStates const &other)
    00221 {
    00222         ObjectArray::operator +=(other);
    00223         return *this;
    00224 }
    00225
    00227
    00228 CCAStates const & CCAStates::operator +=(CCAState const &data)
    00229 {
    00230         ObjectArray::operator +=(data);
    00231         return *this;
    00232 }
    00233
    00235 // Protected Functions
    00237
    00238 void * CCAStates::newElement(void const * element) const
    00239 {
    00240         return new CCAState(*((CCAState const *) element));
    00241 }
    00242
    00244
    00245 bool CCAStates::isEqual(void const * element1, void const * element2) const
    00246 {
    00247         CCAState const * e1 = (CCAState const *) element1;
    00248         CCAState const * e2 = (CCAState const *) element2;
    00249         return e1->operator ==(*e2);
    00250 }
    00251