UCommon
Main Page
Namespaces
Data Structures
Files
Examples
File List
Globals
ucommon
counter.h
Go to the documentation of this file.
1
// Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
2
//
3
// This file is part of GNU uCommon C++.
4
//
5
// GNU uCommon C++ is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU Lesser General Public License as published
7
// by the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// GNU uCommon C++ is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU Lesser General Public License for more details.
14
//
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
17
26
#ifndef _UCOMMON_COUNTER_H_
27
#define _UCOMMON_COUNTER_H_
28
29
#ifndef _UCOMMON_CONFIG_H_
30
#include <
ucommon/platform.h
>
31
#endif
32
33
NAMESPACE_UCOMMON
34
42
class
__EXPORT
counter
43
{
44
private
:
45
unsigned
value, cycle;
46
47
public
:
51
counter
();
52
57
counter
(
unsigned
limit
);
58
63
unsigned
get
(void);
64
69
inline
unsigned
range
(
void
)
70
{
return
cycle;};
71
76
inline
unsigned
operator*
()
77
{
return
get
();};
78
83
inline
operator
unsigned()
84
{
return
get
();};
85
90
void
operator=(
unsigned
value);
91
};
92
100
class
__EXPORT
SeqCounter
:
protected
counter
101
{
102
private
:
103
void
*item;
104
size_t
offset;
105
106
protected
:
107
SeqCounter
(
void
*
start
,
size_t
size,
unsigned
count);
108
109
void
*
get
(void);
110
111
void
*
get
(
unsigned
idx);
112
113
public
:
118
inline
void
operator=
(
unsigned
inc_offset)
119
{
counter::operator=
(inc_offset);};
120
};
121
126
class
__EXPORT
toggle
127
{
128
private
:
129
bool
value;
130
131
public
:
132
inline
toggle
()
133
{value =
false
;};
134
135
bool
get
(void);
136
137
inline
bool
operator*()
138
{
return
get
();};
139
140
inline
void
operator=(
bool
v)
141
{value = v;};
142
143
inline
operator
bool()
144
{
return
get
();};
145
146
};
147
154
template
<
class
T>
155
class
sequence
:
public
SeqCounter
156
{
157
protected
:
158
inline
T *
get
(
unsigned
idx)
159
{
return
static_cast<
T *
>
(SeqCounter::get(idx));};
160
161
public
:
167
inline
sequence
(T *array,
unsigned
size) :
168
SeqCounter
(array, sizeof(T), size) {};
169
174
inline
T*
get
(void)
175
{
return
static_cast<
T *
>
(SeqCounter::get());};
176
181
inline
T&
operator*
()
182
{
return
*
get
();};
183
188
inline
operator
T&()
189
{
return
*
get
();};
190
196
inline
T&
operator[]
(
unsigned
offset)
197
{
return
*
get
(offset);};
198
};
199
203
typedef
counter
counter_t
;
204
208
typedef
toggle
toggle_t
;
209
210
END_NAMESPACE
211
212
#endif
Generated by
1.8.4