00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #define LIBSMBIOS_SOURCE
00020 #include "TokenImpl.h"
00021
00022 using namespace std;
00023
00024 namespace smbios
00025 {
00026 TokenTableIteratorBase::TokenTableIteratorBase (const ITokenTable *initialTable, int typeToMatch)
00027 :matchType(typeToMatch), table(initialTable), current(-1)
00028 {
00029 if( table == 0 )
00030 current = -2;
00031
00032 incrementIterator();
00033 }
00034
00035
00036 IToken * TokenTableIteratorBase::dereference () const
00037 {
00038 const TokenTable *CTTable = dynamic_cast<const TokenTable *>(table);
00039 if( current >= 0 && static_cast<unsigned int>(current) >= CTTable->tokenList.size() )
00040 current = -2;
00041 if( current > -1 )
00042 {
00043 return CTTable->tokenList[current] ;
00044 }
00045 throw DerefNullPointerImpl("tried to dereference non-existent token");
00046 }
00047
00048 void TokenTableIteratorBase::incrementIterator()
00049 {
00050 if( current == -2 )
00051 return;
00052
00053 const TokenTable *CTTable = dynamic_cast<const TokenTable *>(table);
00054 size_t size = CTTable->tokenList.size();
00055 do
00056 {
00057 ++current;
00058 }
00059 while(
00060 matchType != -1 &&
00061 current >= 0 &&
00062 static_cast<unsigned int>(current) < size &&
00063 CTTable->tokenList[current]->getType() != static_cast<u32>(matchType)
00064 );
00065
00066
00067
00068 if( current >= 0 && static_cast<unsigned int>(current) >= size )
00069 current = -2;
00070
00071 return;
00072 }
00073
00074
00075 TokenTableIterator & TokenTableIterator::operator ++ ()
00076 {
00077 if( current > -1 )
00078 incrementIterator();
00079 return *this;
00080 }
00081
00082
00083 const TokenTableIterator TokenTableIterator::operator ++ (int)
00084 {
00085 const TokenTableIterator oldValue = *this;
00086 ++(*this);
00087 return oldValue;
00088 }
00089
00090
00091 ConstTokenTableIterator & ConstTokenTableIterator::operator ++ ()
00092 {
00093 if( current > -1 )
00094 incrementIterator();
00095 return *this;
00096 }
00097
00098
00099 const ConstTokenTableIterator ConstTokenTableIterator::operator ++ (int)
00100 {
00101 const ConstTokenTableIterator oldValue = *this;
00102 ++(*this);
00103 return oldValue;
00104 }
00105
00106 }