iterator.cpp
Go to the documentation of this file.
00001 #include "yaml-cpp-pm/node.h"
00002 #include "yaml-cpp-pm/exceptions.h"
00003 #include "iterpriv.h"
00004 
00005 namespace YAML_PM
00006 {
00007         Iterator::Iterator(): m_pData(new IterPriv)
00008         {
00009         }
00010 
00011         Iterator::Iterator(std::auto_ptr<IterPriv> pData): m_pData(pData)
00012         {
00013         }
00014 
00015         Iterator::Iterator(const Iterator& rhs): m_pData(new IterPriv(*rhs.m_pData))
00016         {
00017         }
00018 
00019         Iterator& Iterator::operator = (const Iterator& rhs)
00020         {
00021                 if(this == &rhs)
00022                         return *this;
00023 
00024                 m_pData.reset(new IterPriv(*rhs.m_pData));
00025                 return *this;
00026         }
00027 
00028         Iterator::~Iterator()
00029         {
00030         }
00031 
00032         Iterator& Iterator::operator ++ ()
00033         {
00034                 if(m_pData->type == IterPriv::IT_SEQ)
00035                         ++m_pData->seqIter;
00036                 else if(m_pData->type == IterPriv::IT_MAP)
00037                         ++m_pData->mapIter;
00038 
00039                 return *this;
00040         }
00041 
00042         Iterator Iterator::operator ++ (int)
00043         {
00044                 Iterator temp = *this;
00045 
00046                 if(m_pData->type == IterPriv::IT_SEQ)
00047                         ++m_pData->seqIter;
00048                 else if(m_pData->type == IterPriv::IT_MAP)
00049                         ++m_pData->mapIter;
00050 
00051                 return temp;
00052         }
00053 
00054         const Node& Iterator::operator * () const
00055         {
00056                 if(m_pData->type == IterPriv::IT_SEQ)
00057                         return **m_pData->seqIter;
00058 
00059                 throw BadDereference();
00060         }
00061 
00062         const Node *Iterator::operator -> () const
00063         {
00064                 if(m_pData->type == IterPriv::IT_SEQ)
00065                         return *m_pData->seqIter;
00066 
00067                 throw BadDereference();
00068         }
00069 
00070         const Node& Iterator::first() const
00071         {
00072                 if(m_pData->type == IterPriv::IT_MAP)
00073                         return *m_pData->mapIter->first;
00074 
00075                 throw BadDereference();
00076         }
00077 
00078         const Node& Iterator::second() const
00079         {
00080                 if(m_pData->type == IterPriv::IT_MAP)
00081                         return *m_pData->mapIter->second;
00082 
00083                 throw BadDereference();
00084         }
00085 
00086         bool operator == (const Iterator& it, const Iterator& jt)
00087         {
00088                 if(it.m_pData->type != jt.m_pData->type)
00089                         return false;
00090 
00091                 if(it.m_pData->type == IterPriv::IT_SEQ)
00092                         return it.m_pData->seqIter == jt.m_pData->seqIter;
00093                 else if(it.m_pData->type == IterPriv::IT_MAP)
00094                         return it.m_pData->mapIter == jt.m_pData->mapIter;
00095 
00096                 return true;
00097         }
00098 
00099         bool operator != (const Iterator& it, const Iterator& jt)
00100         {
00101                 return !(it == jt);
00102         }
00103 }


libpointmatcher
Author(s):
autogenerated on Mon Sep 14 2015 02:59:06