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

# /Users/fpy/titan-1-5-MBARI/Mers/Planning/Reactive/CCA/rpStates.cpp

    00001 //=============================================================================
    00002 //
    00003 // Copyright (c) 2001           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 // Author:                      Seung H. Chung
    00010 // Organization:        Model-based Embedded and Robotic Systems Group
    00011 //                                      Massachusetts Institute of Technology
    00012 //
    00013 // rpStates class
    00014 //
    00015 //=============================================================================
    00016
    00017 #include <cstdio>
    00018 #include <cassert>
    00019
    00020 #include "rpAutomaton.h"
    00021 #include "rpTransition.h"
    00022 #include "rpStates.h"
    00023
    00025
    00026 using Mers::Models::CCA::CCAState;
    00027 using Mers::Models::CCA::CCAValue;
    00028
    00030 // Constructors, Copy Constructors, & Destructors
    00032
    00033 rpStates::rpStates() {
    00034         _rpState_array  = NULL;
    00035         _size                   = 0;
    00036 }
    00037 rpStates::rpStates(sizeType size_) {
    00038         _size                   = size_;
    00039         _rpState_array  = new rpState[_size];
    00040 }
    00041 rpStates::rpStates(const rpStates &other) {
    00042         if (this != &other) {
    00043                 copy(other);
    00044         }
    00045 }
    00046 rpStates::~rpStates() {
    00047         destroy();
    00048 }
    00049 //------------------------------------------------------------------------------
    00050 // Public Function Members
    00051 //------------------------------------------------------------------------------
    00052 const unsigned int rpStates::size() const {
    00053         return _size;
    00054 }
    00055 const bool rpStates::empty() const {
    00056         return (_size == 0);
    00057 }
    00058 //------------------------------------------------------------------------------
    00059 rpState *const rpStates::rpState_p(const CCAValue &_value) const {
    00060         for (sizeType i = 0; i < _size; i++) {
    00061                 if (_rpState_array[i].value_p() == &_value) return &_rpState_array[i];
    00062         }
    00063         return NULL;
    00064 }
    00065 rpState *const rpStates::rpState_p(const CCAState &_state) const {
    00066         for (sizeType i = 0; i < _size; i++) {
    00067                 if (_rpState_array[i].name() == _state.name())
    00068                         return &_rpState_array[i];
    00069         }
    00070         return NULL;
    00071 }
    00072 void rpStates::clear() {
    00073         for (sizeType i = 0; i < _size; i++) {
    00074                 _rpState_array[i].clear();
    00075         }
    00076 }
    00077 //------------------------------------------------------------------------------
    00078 // Public Operators
    00079 //------------------------------------------------------------------------------
    00080 rpState &rpStates::operator [](const sizeType index_) {
    00081         if (index_ < _size) {
    00082                 return _rpState_array[index_];
    00083         } else {
    00084                 return _rpState_array[0];
    00085         }
    00086 }
    00087 const rpState &rpStates::operator [](const sizeType index_) const {
    00088         if (index_ < _size) {
    00089                 return _rpState_array[index_];
    00090         } else {
    00091                 return _rpState_array[0];
    00092         }
    00093 }
    00094 const rpStates &rpStates::operator =(const rpStates &other) {
    00095         if (this != &other) {
    00096                 destroy();
    00097                 copy(other);
    00098         }
    00099         return (*this);
    00100 }
    00101 const bool rpStates::operator ==(const rpStates &other) const {
    00102         if (_size == other._size) {
    00103                 for (sizeType i = 0; i < _size; i++) {
    00104                         if (_rpState_array[i] != other._rpState_array[i]) return false;
    00105                 }
    00106                 return true;
    00107         }
    00108         return false;
    00109 }
    00110 const bool rpStates::operator !=(const rpStates &other) const {
    00111         return !(*this == other);
    00112 }
    00113 std::ostream &operator <<(std::ostream &_ostream, const rpStates &_rpStates) {
    00114         _ostream << "rpStates:" << std::endl;
    00115         rpStates::sizeType i = 0;
    00116         while (i < _rpStates.size()) {
    00117                 _ostream << _rpStates[i];
    00118                 i++;
    00119                 if (i < _rpStates.size()) {
    00120                         _ostream << std::endl;
    00121                 }
    00122         }
    00123         return _ostream;
    00124 }
    00125 //------------------------------------------------------------------------------
    00126 // Private Function Members
    00127 //------------------------------------------------------------------------------
    00128 void rpStates::destroy() {
    00129         clear();
    00130         delete [] _rpState_array;
    00131         _size = 0;
    00132 }
    00133 void rpStates::copy(const rpStates &other) {
    00134         _size                   = other.size();
    00135         _rpState_array  = new rpState[_size];
    00136         for (sizeType i = 0; i < _size; i++) {
    00137                 _rpState_array[i] = other[i];
    00138         }
    00139 }