Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

TokenTableIterator.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  * vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:textwidth=0:
00003  *
00004  * Copyright (C) 2005 Dell Inc.
00005  *  by Michael Brown <Michael_E_Brown@dell.com>
00006  * Licensed under the Open Software License version 2.1
00007  *
00008  * Alternatively, you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published
00010  * by the Free Software Foundation; either version 2 of the License,
00011  * or (at your option) any later version.
00012 
00013  * This program is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
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;   // should _never_ get here.
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         // don't overflow the size of the table.
00067         // be careful about signed vs unsigned comparisons.
00068         if( current >= 0 && static_cast<unsigned int>(current) >= size )
00069             current = -2;
00070 
00071         return;
00072     }
00073 
00074     //Prefix ++
00075     TokenTableIterator & TokenTableIterator::operator ++ ()
00076     {
00077         if( current > -1 )
00078             incrementIterator();
00079         return *this;
00080     }
00081 
00082     //Postfix ++
00083     const TokenTableIterator TokenTableIterator::operator ++ (int)
00084     {
00085         const TokenTableIterator oldValue = *this;
00086         ++(*this);
00087         return oldValue;
00088     }
00089 
00090     //Prefix ++
00091     ConstTokenTableIterator & ConstTokenTableIterator::operator ++ ()
00092     {
00093         if( current > -1 )
00094             incrementIterator();
00095         return *this;
00096     }
00097 
00098     //Postfix ++
00099     const ConstTokenTableIterator ConstTokenTableIterator::operator ++ (int)
00100     {
00101         const ConstTokenTableIterator oldValue = *this;
00102         ++(*this);
00103         return oldValue;
00104     }
00105 
00106 }

Generated on Wed Apr 11 16:25:10 2007 for SMBIOS Library by doxygen 1.3.5