SMBIOS Library
SmbiosTableIterator.cpp
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:textwidth=0:
3  *
4  * Copyright (C) 2005 Dell Inc.
5  * by Michael Brown <Michael_E_Brown@dell.com>
6  * Licensed under the Open Software License version 2.1
7  *
8  * Alternatively, you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published
10  * by the Free Software Foundation; either version 2 of the License,
11  * or (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  */
18 
19 #define LIBSMBIOS_SOURCE
20 #include "SmbiosImpl.h"
21 
22 // message.h should be included last.
23 #include "smbios/message.h"
24 
25 using namespace smbiosLowlevel;
26 using namespace std;
27 
28 namespace smbios
29 {
30  SmbiosTableIteratorBase::~SmbiosTableIteratorBase() throw() {}
31  SmbiosTableIterator::~SmbiosTableIterator() throw() {}
32  ConstSmbiosTableIterator::~ConstSmbiosTableIterator() throw() {}
33 
34  void SmbiosTableIteratorBase::reset()
35  {
36  current=0;
37  incrementIterator();
38  }
39 
40  bool SmbiosTableIteratorBase::eof()
41  {
42  return (current == 0);
43  }
44 
45  SmbiosTableIterator::SmbiosTableIterator(ISmbiosTable * initialTable, int typeToMatch)
46  : SmbiosTableIteratorBase(initialTable, typeToMatch)
47  {}
48 
50  {
51  return dereference();
52  }
53 
55  {
56  return &dereference();
57  }
58 
60  {
61  incrementIterator(); return *this;
62  } // ++Prefix
63 
65  {
66  const SmbiosTableIterator oldValue = *this;
67  ++(*this);
68  return oldValue;
69  } //Postfix++
70 
71 
73  : SmbiosTableIteratorBase(initialTable, typeToMatch)
74  {}
75 
77  {
78  table = rhs.table;
79  matchType = rhs.matchType;
80  current = rhs.current;
81  return *this;
82  }
83 
85  {
87  return *this;
88  }
89 
90  SmbiosTableIteratorBase::SmbiosTableIteratorBase(const ISmbiosTable * initialTable, int typeToMatch)
91  : matchType(typeToMatch), table(initialTable), current(0)
92  {
94  }
95 
97  {
98  return current == other.current;
99  }
100 
102  {
103  return current != other.current;
104  }
105 
107  {
108  incrementIterator(); return *this;
109  } // ++Prefix
110 
112  {
113  const ConstSmbiosTableIterator oldValue = *this;
114  ++(*this);
115  return oldValue;
116  } //Postfix++
117 
119  {
120  return dereference();
121  }
122 
124  {
125  return &dereference();
126  }
127 
129  {
130  if (0 == current)
131  {
132  throw ParameterExceptionImpl (_("Programmer error: attempt to dereference a Null iterator."));
133  }
134 
135  return const_cast<ISmbiosTable *>(table)->getSmbiosItem(current);
136  }
137 
139  {
140  if (0 == current)
141  {
142  throw ParameterExceptionImpl (_("Programmer error: attempt to dereference a Null iterator."));
143  }
144 
145  return table->getSmbiosItem(current);
146  }
147 
149  {
150  if(!table) return;
151  do {
153  } while ((-1 != matchType) &&
154  (0 != current) &&
155  (reinterpret_cast<const smbios_structure_header *>(current)->type != matchType));
156  }
157 }