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

# /Users/fpy/titan-1-5-MBARI/Mers/Utils/Containers/Iterators.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 "Iterators.h"
    00015
    00016 using Mers::Utils::Containers::IConstantIterator;
    00017 using Mers::Utils::Containers::IIterator;
    00018
    00020 // Construction/Destruction
    00022
    00024 // IConstantIterator Class
    00026
    00027 bool IConstantIterator::operator ==(const IConstantIterator &other) const
    00028 {
    00029         return (m_List == other.m_List && m_Index == other.m_Index);
    00030 }
    00031
    00033
    00034 bool IConstantIterator::operator !=(const IConstantIterator &other) const
    00035 {
    00036         return !operator==(other);
    00037 }
    00038
    00040
    00041 IConstantIterator::IConstantIterator(void const * myList, unsigned int myIndex)
    00042         : m_List(myList)
    00043 {
    00044         m_Index = myIndex;
    00045 }
    00046
    00048
    00049 IConstantIterator::IConstantIterator(IConstantIterator const &other)
    00050         : m_List(other.m_List)
    00051 {
    00052         m_Index = other.m_Index;
    00053 }
    00054
    00056
    00057 IConstantIterator &
    00058 IConstantIterator::operator =(const IConstantIterator &other)
    00059 {
    00060         if (this != &other) {
    00061                 m_List = other.m_List;
    00062                 m_Index = other.m_Index;
    00063         }
    00064         return *this;
    00065 }
    00066
    00068
    00069 IConstantIterator & IConstantIterator::operator +=(int ival)
    00070 {
    00071         // Since m_Index is unsigned, don't let ival subtract enough to
    00072         // make m_Index less than zero (add a large enough negative value).
    00073         if(ival > 0 || m_Index >= (unsigned int)-ival)
    00074                 m_Index += ival;
    00075         else
    00076                 m_Index = 0;
    00077         return *this;
    00078 }
    00079
    00081
    00082 IConstantIterator & IConstantIterator::operator -=(int ival)
    00083 {
    00084         // Since m_Index is unsigned, don't let ival subtract enough to
    00085         // make m_Index less than zero (subtract a large enough positive value).
    00086         if(ival < 0 || m_Index >= (unsigned int)ival)
    00087                 m_Index -= ival;
    00088         else
    00089                 m_Index = 0;
    00090         return *this;
    00091 }
    00092
    00094 // IIterator Class
    00096
    00097 IIterator::IIterator(void * myList, unsigned int myIndex)
    00098         : IConstantIterator(myList, myIndex), m_List(myList)
    00099 {
    00100 }
    00101
    00103
    00104 IIterator::IIterator(IIterator const &other)
    00105         : IConstantIterator(other), m_List(other.m_List)
    00106 {
    00107 }
    00108
    00110
    00111 IIterator & IIterator::operator =(const IIterator &other)
    00112 {
    00113         if (this != &other) {
    00114                 IConstantIterator::operator =(other);
    00115                 m_List = other.m_List;
    00116         }
    00117         return *this;
    00118 }
    00119
    00121