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

# /Users/fpy/titan-1-5-MBARI/Mers/Models/CCA/CCAVariables.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 "CCAVariables.h"
    00015
    00016 #include <cstdio>
    00017 #include <cassert>
    00018
    00020
    00021 using namespace Mers::Models::CCA;
    00022 using Mers::Utils::Lang::String;
    00023 using std::ostream;
    00024
    00026 // Constructors, Copy Constructors, & Destructors
    00028
    00029 CCAVariables::CCAVariables(bool myOwnershipStatus)
    00030 : BaseModelVariableArray(myOwnershipStatus)
    00031 {
    00032 }
    00033
    00034 CCAVariables::CCAVariables(const CCAVariables &other)
    00035 : BaseModelVariableArray(other)
    00036 {
    00037 }
    00038
    00039 CCAVariables::~CCAVariables()
    00040 {
    00041 }
    00042
    00044 // Public Function Members
    00046
    00047 bool CCAVariables::empty() const
    00048 {
    00049         return isEmpty();
    00050 }
    00051
    00052 void CCAVariables::clear()
    00053 {
    00054         makeEmpty();
    00055 }
    00056
    00057 const CCAVariable & CCAVariables::front() const
    00058 {
    00059         return *begin();
    00060 }
    00061
    00062 const CCAVariable & CCAVariables::back() const
    00063 {
    00064         return *(--end());
    00065 }
    00066
    00067 CCAVariable & CCAVariables::front()
    00068 {
    00069         return *begin();
    00070 }
    00071
    00072 CCAVariable & CCAVariables::back()
    00073 {
    00074         return *(--end());
    00075 }
    00076
    00078
    00079 CCAVariables::const_iterator CCAVariables::insert_variable(const CCAVariable &new_variable)
    00080 {
    00081         for (const_iterator const_it = begin(); const_it != end(); const_it++) {
    00082                 if (*const_it == new_variable)
    00083                         return end();
    00084         }
    00085         CCAVariable * variable = (CCAVariable *) newElement(&new_variable);
    00086         if(!variable){
    00087                 fprintf(stderr, "CCAVariables::insert_variable: Failed to copy variable\n");
    00088                 return end();
    00089         }
    00090         if(FAILED(pushBack(variable)))
    00091                 return end();
    00092         return --end();
    00093 }
    00094
    00095 const CCAVariable * CCAVariables::variable_p(const String &variable_name) const
    00096 {
    00097         for (const_iterator const_it = begin(); const_it != end(); const_it++) {
    00098                 if (variable_name == const_it->getName())
    00099                         return &*const_it;
    00100         }
    00101         return NULL;
    00102 }
    00103
    00104 const CCAVariable * CCAVariables::variable_p(unsigned int variableUID) const
    00105 {
    00106         for (const_iterator const_it = begin(); const_it != end(); const_it++) {
    00107                 if ((*const_it).getUID() == variableUID)
    00108                         return &(*const_it);
    00109         }
    00110         return NULL;
    00111 }
    00112
    00114
    00115 int CCAVariables::pushBack(CCAVariable * data)
    00116 {
    00117         return BaseModelVariableArray::pushBack(data);
    00118 }
    00119
    00121
    00122 CCAVariable * CCAVariables::popBack()
    00123 {
    00124         return (CCAVariable *) BaseModelVariableArray::popBack();
    00125 }
    00126
    00128
    00129 #ifndef EMBEDDED
    00130
    00131 void CCAVariables::print(ostream &out) const
    00132 {
    00133         printArray(out, "\n");
    00134 }
    00135
    00136 #endif
    00137
    00139 // Public Operators
    00141
    00142 bool CCAVariables::operator ==(const CCAVariables &other) const
    00143 {
    00144         return BaseModelVariableArray::operator ==(other);
    00145 }
    00146
    00148
    00149 bool CCAVariables::operator !=(const CCAVariables &other) const
    00150 {
    00151         return !operator ==(other);
    00152 }
    00153
    00155
    00156 CCAVariable * & CCAVariables::operator[](int elementIndex)
    00157 {
    00158         return (CCAVariable * &) BaseModelVariableArray::operator [](elementIndex);
    00159 }
    00160
    00162
    00163 CCAVariable * & CCAVariables::operator[](unsigned int elementIndex)
    00164 {
    00165         return (CCAVariable * &) BaseModelVariableArray::operator [](elementIndex);
    00166 }
    00167
    00169
    00170 CCAVariable const * & CCAVariables::operator[](int elementIndex) const
    00171 {
    00172         return (CCAVariable const * &) BaseModelVariableArray::operator [](elementIndex);
    00173 }
    00174
    00176
    00177 CCAVariable const * & CCAVariables::operator[](unsigned int elementIndex) const
    00178 {
    00179         return (CCAVariable const * &) BaseModelVariableArray::operator [](elementIndex);
    00180 }
    00181
    00183
    00184 const CCAVariables & CCAVariables::operator =(const CCAVariables &other)
    00185 {
    00186         BaseModelVariableArray::operator =(other);
    00187         return (*this);
    00188 }
    00189
    00191
    00192 const CCAVariables & CCAVariables::operator +=(const CCAVariables &other)
    00193 {
    00194         BaseModelVariableArray::operator +=(other);
    00195         return (*this);
    00196 }
    00197
    00199
    00200 const CCAVariables & CCAVariables::operator +=(const CCAVariable &data)
    00201 {
    00202         BaseModelVariableArray::operator +=(data);
    00203         return (*this);
    00204 }
    00205
    00207 // Protected Function Members
    00209
    00210 void * CCAVariables::newElement(void const * element) const
    00211 {
    00212         return new CCAVariable(*((CCAVariable const *) element));
    00213 }
    00214
    00216
    00217 bool CCAVariables::isEqual(void const * element1, void const * element2) const
    00218 {
    00219         CCAVariable const * e1 = (CCAVariable const *) element1;
    00220         CCAVariable const * e2 = (CCAVariable const *) element2;
    00221         return e1->operator ==(*e2);
    00222 }
    00223