00001 #include "GLIteratorStorageStl.h"
00002 #include "GLRuntimeError.h"
00007 template <class TStlContainer, class TStlIterator, class TOrganism>
00008 GLIteratorStorageStl<TStlContainer, TStlIterator, TOrganism>::
00009 GLIteratorStorageStl(TStlContainer& container): m_container(container)
00010 {
00011 m_it = m_container.begin();
00012 }
00013
00018 template <class TStlContainer, class TStlIterator, class TOrganism>
00019 GLBidirectionalIterator<TOrganism>&
00020 GLIteratorStorageStl<TStlContainer, TStlIterator, TOrganism>::
00021 operator++()
00022 {
00023 if (isEnd())
00024 {
00025 char errormsg[1000];
00026 sprintf(errormsg, "\nGLIteratorStorageStl::operator++\n"
00027 "Cannot move iterator further -- end is reached\n");
00028 throw GLRuntimeError(errormsg);
00029 }
00030 m_it++;
00031 return *this;
00032 }
00033
00038 template <class TStlContainer, class TStlIterator, class TOrganism>
00039 GLBidirectionalIterator<TOrganism>&
00040 GLIteratorStorageStl<TStlContainer, TStlIterator, TOrganism>::
00041 operator--()
00042 {
00043 if (isBegin())
00044 {
00045 char errormsg[1000];
00046 sprintf(errormsg, "\nGLIteratorStorageStl::operator--\n"
00047 "Cannot move iterator further -- beginning is reached\n");
00048 throw GLRuntimeError(errormsg);
00049 }
00050 m_it--;
00051 return *this;
00052 }
00053
00058 template <class TStlContainer, class TStlIterator, class TOrganism>
00059 TOrganism&
00060 GLIteratorStorageStl<TStlContainer, TStlIterator, TOrganism>::
00061 getElement()
00062 {
00063 if (isEnd())
00064 {
00065 char errormsg[1000];
00066 sprintf(errormsg, "\nGLIteratorStorageStl::getElement\n"
00067 "Cannot return the pointer to organism when "
00068 "iterator points to the end\n");
00069 throw GLRuntimeError(errormsg);
00070 }
00071
00072
00073
00074 TOrganism& t = const_cast<TOrganism&>(*m_it);
00075 return t;
00076 }
00077
00082 template <class TStlContainer, class TStlIterator, class TOrganism>
00083 const TOrganism&
00084 GLIteratorStorageStl<TStlContainer, TStlIterator, TOrganism>::
00085 getElement() const
00086 {
00087 if (isEnd())
00088 {
00089 char errormsg[1000];
00090 sprintf(errormsg, "\nGLIteratorStorageStl::getElement\n"
00091 "Cannot return the pointer to organism when "
00092 "iterator points to the end\n");
00093 throw GLRuntimeError(errormsg);
00094 }
00095 const TOrganism& t = (*m_it);
00096 return t;
00097 }