Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
77fd8250
Commit
77fd8250
authored
Jun 16, 2010
by
Ivan Donchevskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Iterator for CycleStorage
parent
44ffcd23
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
1 deletion
+104
-1
Storages.h
include/Storages.h
+65
-1
CycleStorage.cc
src/Various/CycleStorage.cc
+39
-0
No files found.
include/Storages.h
View file @
77fd8250
...
...
@@ -147,6 +147,57 @@ class TableBlockStorage
class
CycleStorage
{
public
:
class
CycleStorageIterator
{
public
:
typedef
CycleStorageIterator
Self
;
CycleStorageIterator
()
:
str
(
NULL
),
cs
(
NULL
),
current
(
0
)
{}
CycleStorageIterator
(
CycleStorage
*
cstor
)
{
cs
=
cstor
;
current
=
0
;
}
CycleStorageIterator
(
CycleStorage
*
cstor
,
int
num
)
{
cs
=
cstor
;
if
(
num
<
0
||
num
>=
cs
->
getSize
()
)
current
=
0
;
current
=
num
;
}
void
*
operator
*
()
const
{
return
str
;
}
Self
&
operator
++
();
Self
operator
++
(
int
);
Self
&
operator
--
();
Self
operator
--
(
int
);
inline
bool
operator
==
(
const
Self
&
other
)
const
{
if
(
memcmp
(
str
,
other
.
str
,
cs
->
getInfSize
())
==
0
)
return
true
;
return
false
;
}
inline
bool
operator
!=
(
const
Self
&
other
)
const
{
if
(
memcmp
(
str
,
other
.
str
,
cs
->
getInfSize
())
==
0
)
return
false
;
return
true
;
}
private
:
void
*
str
;
CycleStorage
*
cs
;
int
current
;
};
typedef
CycleStorageIterator
iterator
;
/*! Конструктор по умолчанию не открывает и не создает нового журнала */
CycleStorage
();
...
...
@@ -187,7 +238,7 @@ class CycleStorage
/*! Изменение размера журнала (количества записей в нем) */
bool
setSize
(
int
count
);
inline
int
getByteSize
()
{
return
(
size
*
full_size
+
sizeof
(
CycleStorageAttr
));
}
inline
int
getSize
(){
return
size
;
}
inline
int
getInfSize
(){
return
inf_size
;
}
...
...
@@ -195,6 +246,19 @@ class CycleStorage
bool
checkAttr
(
int
inf_sz
,
int
inf_count
,
int
seek
);
inline
int
getHead
(){
return
head
;
}
inline
int
getTail
(){
return
tail
;
}
iterator
begin
()
{
return
iterator
(
this
);
}
iterator
end
()
{
return
iterator
(
this
,
this
->
getTail
());
}
protected
:
FILE
*
file
;
int
inf_size
;
...
...
src/Various/CycleStorage.cc
View file @
77fd8250
...
...
@@ -490,3 +490,41 @@ bool CycleStorage::setSize(int count)
return
true
;
}
/*! Некоторые операции для итератора */
CycleStorage
::
iterator
&
CycleStorage
::
iterator
::
operator
++
()
{
if
(
current
>=
cs
->
getSize
()
)
throw
"Trying to perform operator ++ at the end of collection"
;
current
++
;
cs
->
readRow
(
current
,
str
);
return
*
this
;
}
CycleStorage
::
iterator
CycleStorage
::
iterator
::
operator
++
(
int
)
{
Self
temp
=
*
this
;
if
(
current
>=
cs
->
getSize
())
throw
"Trying to perform operator ++ at the end of collection"
;
current
++
;
cs
->
readRow
(
current
,
str
);
return
temp
;
}
CycleStorage
::
iterator
&
CycleStorage
::
iterator
::
operator
--
()
{
if
(
current
<=
0
)
throw
"Trying to perform operator -- at the begining of collection"
;
current
--
;
cs
->
readRow
(
current
,
str
);
return
*
this
;
}
CycleStorage
::
iterator
CycleStorage
::
iterator
::
operator
--
(
int
)
{
Self
temp
=
*
this
;
if
(
current
<=
0
)
throw
"Trying to perform operator -- at the begining of collection"
;
current
--
;
cs
->
readRow
(
current
,
str
);
return
temp
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment