SMBIOS Library
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
libraries
token
TokenTableIterator.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 "
TokenImpl.h
"
21
22
using namespace
std;
23
24
namespace
smbios
25
{
26
ConstTokenTableIterator::ConstTokenTableIterator (
const
ITokenTable
* initialTable,
int
typeToMatch)
27
:
TokenTableIteratorBase
( initialTable, typeToMatch )
28
{}
29
30
TokenTableIterator::TokenTableIterator
(
const
ITokenTable
*initialTable,
int
typeToMatch)
31
:
TokenTableIteratorBase
( initialTable, typeToMatch )
32
{}
33
34
35
TokenTableIteratorBase::TokenTableIteratorBase
(
const
ITokenTable
*initialTable,
int
typeToMatch)
36
:matchType(typeToMatch), table(initialTable), current(-1)
37
{
38
if
(
table
== 0 )
39
current
= -2;
40
41
incrementIterator
();
42
}
43
44
void
TokenTableIteratorBase::reset
()
45
{
46
current
=0;
47
incrementIterator
();
48
}
49
50
bool
TokenTableIteratorBase::eof
()
51
{
52
return
(
current
< 0);
53
}
54
55
IToken
&
TokenTableIterator::operator *
()
const
56
{
57
return
*(
const_cast<
TokenTableIterator
*
>
(
this
)->
dereference
());
58
}
59
60
IToken
*
TokenTableIterator::operator ->
()
const
61
{
62
return
const_cast<
TokenTableIterator
*
>
(
this
)->
dereference
();
63
}
64
65
const
IToken
&
ConstTokenTableIterator::operator *
()
const
66
{
67
return
*
dereference
();
68
}
69
70
const
IToken
*
ConstTokenTableIterator::operator ->
()
const
71
{
72
return
dereference
();
73
}
74
75
76
const
IToken
*
TokenTableIteratorBase::dereference
()
const
77
{
78
return
const_cast<
TokenTableIteratorBase
*
>
(
this
)->
dereference
();
79
}
80
81
IToken
*
TokenTableIteratorBase::dereference
()
82
{
83
const
TokenTable
*CTTable =
dynamic_cast<
const
TokenTable
*
>
(
table
);
84
if
(
current
>= 0 && static_cast<unsigned int>(
current
) >= CTTable->
tokenList
.size() )
85
current
= -2;
// should _never_ get here.
86
if
(
current
> -1 )
87
{
88
return
CTTable->
tokenList
[
current
] ;
89
}
90
throw
DerefNullPointerImpl(
"tried to dereference non-existent token"
);
91
}
92
93
void
TokenTableIteratorBase::incrementIterator
()
94
{
95
if
(
current
== -2 )
96
return
;
97
98
const
TokenTable
*CTTable =
dynamic_cast<
const
TokenTable
*
>
(
table
);
99
size_t
size = CTTable->
tokenList
.size();
100
do
101
{
102
++
current
;
103
}
104
while
(
105
matchType
!= -1 &&
106
current
>= 0 &&
107
static_cast<unsigned int>(
current
) < size &&
108
CTTable->
tokenList
[
current
]->getType() !=
static_cast<
u32
>
(
matchType
)
109
);
110
111
// don't overflow the size of the table.
112
// be careful about signed vs unsigned comparisons.
113
if
(
current
>= 0 && static_cast<unsigned int>(
current
) >= size )
114
current
= -2;
115
116
return
;
117
}
118
119
//Prefix ++
120
TokenTableIterator
&
TokenTableIterator::operator ++
()
121
{
122
if
(
current
> -1 )
123
incrementIterator
();
124
return
*
this
;
125
}
126
127
//Postfix ++
128
const
TokenTableIterator
TokenTableIterator::operator ++
(
int
)
129
{
130
const
TokenTableIterator
oldValue = *
this
;
131
++(*this);
132
return
oldValue;
133
}
134
135
//Prefix ++
136
ConstTokenTableIterator
&
ConstTokenTableIterator::operator ++
()
137
{
138
if
(
current
> -1 )
139
incrementIterator
();
140
return
*
this
;
141
}
142
143
//Postfix ++
144
const
ConstTokenTableIterator
ConstTokenTableIterator::operator ++
(
int
)
145
{
146
const
ConstTokenTableIterator
oldValue = *
this
;
147
++(*this);
148
return
oldValue;
149
}
150
151
}
Generated on Thu Mar 27 2014 09:27:19 for SMBIOS Library by
1.8.1.2