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 ConstTokenTableIterator::ConstTokenTableIterator (const ITokenTable * initialTable, int typeToMatch)
00027 : TokenTableIteratorBase( initialTable, typeToMatch )
00028 {}
00029
00030 TokenTableIterator::TokenTableIterator (const ITokenTable *initialTable, int typeToMatch)
00031 : TokenTableIteratorBase( initialTable, typeToMatch )
00032 {}
00033
00034
00035 TokenTableIteratorBase::TokenTableIteratorBase (const ITokenTable *initialTable, int typeToMatch)
00036 :matchType(typeToMatch), table(initialTable), current(-1)
00037 {
00038 if( table == 0 )
00039 current = -2;
00040
00041 incrementIterator();
00042 }
00043
00044 void TokenTableIteratorBase::reset()
00045 {
00046 current=0;
00047 incrementIterator();
00048 }
00049
00050 bool TokenTableIteratorBase::eof()
00051 {
00052 return (current < 0);
00053 }
00054
00055 IToken& TokenTableIterator::operator * () const
00056 {
00057 return *(const_cast<TokenTableIterator *>(this)->dereference());
00058 }
00059
00060 IToken* TokenTableIterator::operator -> () const
00061 {
00062 return const_cast<TokenTableIterator *>(this)->dereference();
00063 }
00064
00065 const IToken& ConstTokenTableIterator::operator * () const
00066 {
00067 return *dereference();
00068 }
00069
00070 const IToken* ConstTokenTableIterator::operator -> () const
00071 {
00072 return dereference();
00073 }
00074
00075
00076 const IToken * TokenTableIteratorBase::dereference () const
00077 {
00078 return const_cast<TokenTableIteratorBase *>(this)->dereference();
00079 }
00080
00081 IToken * TokenTableIteratorBase::dereference ()
00082 {
00083 const TokenTable *CTTable = dynamic_cast<const TokenTable *>(table);
00084 if( current >= 0 && static_cast<unsigned int>(current) >= CTTable->tokenList.size() )
00085 current = -2;
00086 if( current > -1 )
00087 {
00088 return CTTable->tokenList[current] ;
00089 }
00090 throw DerefNullPointerImpl("tried to dereference non-existent token");
00091 }
00092
00093 void TokenTableIteratorBase::incrementIterator()
00094 {
00095 if( current == -2 )
00096 return;
00097
00098 const TokenTable *CTTable = dynamic_cast<const TokenTable *>(table);
00099 size_t size = CTTable->tokenList.size();
00100 do
00101 {
00102 ++current;
00103 }
00104 while(
00105 matchType != -1 &&
00106 current >= 0 &&
00107 static_cast<unsigned int>(current) < size &&
00108 CTTable->tokenList[current]->getType() != static_cast<u32>(matchType)
00109 );
00110
00111
00112
00113 if( current >= 0 && static_cast<unsigned int>(current) >= size )
00114 current = -2;
00115
00116 return;
00117 }
00118
00119
00120 TokenTableIterator & TokenTableIterator::operator ++ ()
00121 {
00122 if( current > -1 )
00123 incrementIterator();
00124 return *this;
00125 }
00126
00127
00128 const TokenTableIterator TokenTableIterator::operator ++ (int)
00129 {
00130 const TokenTableIterator oldValue = *this;
00131 ++(*this);
00132 return oldValue;
00133 }
00134
00135
00136 ConstTokenTableIterator & ConstTokenTableIterator::operator ++ ()
00137 {
00138 if( current > -1 )
00139 incrementIterator();
00140 return *this;
00141 }
00142
00143
00144 const ConstTokenTableIterator ConstTokenTableIterator::operator ++ (int)
00145 {
00146 const ConstTokenTableIterator oldValue = *this;
00147 ++(*this);
00148 return oldValue;
00149 }
00150
00151 }