• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

SmbiosTableIterator.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 "SmbiosImpl.h"
00021 
00022 // message.h should be included last.
00023 #include "smbios/message.h"
00024 
00025 using namespace smbiosLowlevel;
00026 using namespace std;
00027 
00028 namespace smbios
00029 {
00030     SmbiosTableIteratorBase::~SmbiosTableIteratorBase() throw() {}
00031     SmbiosTableIterator::~SmbiosTableIterator() throw() {}
00032     ConstSmbiosTableIterator::~ConstSmbiosTableIterator() throw() {}
00033 
00034     void SmbiosTableIteratorBase::reset()
00035     { 
00036         current=0; 
00037         incrementIterator(); 
00038     }
00039     
00040     bool SmbiosTableIteratorBase::eof()
00041     {
00042         return (current == 0);
00043     }
00044 
00045     SmbiosTableIterator::SmbiosTableIterator(ISmbiosTable * initialTable, int typeToMatch)
00046         : SmbiosTableIteratorBase(initialTable, typeToMatch)
00047     {}
00048 
00049     SmbiosTableIterator::reference SmbiosTableIterator::operator * ()
00050     { 
00051         return dereference(); 
00052     }
00053 
00054     SmbiosTableIterator::pointer   SmbiosTableIterator::operator -> ()
00055     { 
00056         return &dereference(); 
00057     }
00058 
00059     SmbiosTableIterator & SmbiosTableIterator::operator ++ () // ++Prefix
00060     { 
00061         incrementIterator(); return *this; 
00062     } // ++Prefix
00063 
00064     const SmbiosTableIterator SmbiosTableIterator::operator ++ (int)  //Postfix++
00065     {
00066         const SmbiosTableIterator oldValue = *this;
00067         ++(*this);
00068         return oldValue;
00069     }  //Postfix++
00070 
00071 
00072     ConstSmbiosTableIterator::ConstSmbiosTableIterator(const ISmbiosTable * initialTable, int typeToMatch)
00073         : SmbiosTableIteratorBase(initialTable, typeToMatch)
00074     {}
00075 
00076     SmbiosTableIteratorBase &SmbiosTableIteratorBase::operator =(const SmbiosTableIteratorBase &rhs)
00077     {
00078         table = rhs.table; 
00079         matchType = rhs.matchType;
00080         current = rhs.current;
00081         return *this;
00082     }
00083 
00084     ConstSmbiosTableIterator &ConstSmbiosTableIterator::operator =(const SmbiosTableIteratorBase &rhs)
00085     {
00086         SmbiosTableIteratorBase::operator=(rhs);
00087         return *this;
00088     }
00089 
00090     SmbiosTableIteratorBase::SmbiosTableIteratorBase(const ISmbiosTable * initialTable, int typeToMatch)
00091         : matchType(typeToMatch), table(initialTable), current(0)
00092     { 
00093         incrementIterator(); 
00094     }
00095 
00096     bool SmbiosTableIteratorBase::operator == (const SmbiosTableIteratorBase &other) const 
00097     { 
00098         return current == other.current; 
00099     }
00100 
00101     bool SmbiosTableIteratorBase::operator != (const SmbiosTableIteratorBase &other) const 
00102     { 
00103         return current != other.current; 
00104     }
00105 
00106     ConstSmbiosTableIterator & ConstSmbiosTableIterator::operator ++ ()
00107     { 
00108         incrementIterator(); return *this; 
00109     } // ++Prefix
00110 
00111     const ConstSmbiosTableIterator ConstSmbiosTableIterator::operator ++ (int)     
00112     {
00113         const ConstSmbiosTableIterator oldValue = *this;
00114         ++(*this);
00115         return oldValue;
00116     }  //Postfix++
00117 
00118     ConstSmbiosTableIterator::reference ConstSmbiosTableIterator::operator * () const
00119     { 
00120         return dereference(); 
00121     }
00122 
00123     ConstSmbiosTableIterator::pointer   ConstSmbiosTableIterator::operator -> () const
00124     { 
00125         return &dereference(); 
00126     }
00127 
00128     ISmbiosItem & SmbiosTableIteratorBase::dereference ()
00129     {
00130         if (0 == current)
00131         {
00132             throw ParameterExceptionImpl (_("Programmer error: attempt to dereference a Null iterator."));
00133         }
00134 
00135         return const_cast<ISmbiosTable *>(table)->getSmbiosItem(current);
00136     }
00137 
00138     const ISmbiosItem & SmbiosTableIteratorBase::dereference () const
00139     {
00140         if (0 == current)
00141         {
00142             throw ParameterExceptionImpl (_("Programmer error: attempt to dereference a Null iterator."));
00143         }
00144 
00145         return table->getSmbiosItem(current);
00146     }
00147 
00148     void SmbiosTableIteratorBase::incrementIterator ()
00149     {
00150         if(!table) return;
00151         do {
00152             current = table->nextSmbiosStruct (current);
00153         } while ((-1 != matchType) && 
00154                 (0 != current) && 
00155                 (reinterpret_cast<const smbios_structure_header *>(current)->type != matchType));
00156     }
00157 }

Generated on Sun Aug 22 2010 14:38:30 for SMBIOS Library by  doxygen 1.7.1