Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
ab38059d
Commit
ab38059d
authored
Sep 28, 2013
by
Davis King
Browse files
Simplified the implementation of the array2d object.
parent
8516ced3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
54 deletions
+21
-54
dlib/array2d/array2d_kernel.h
dlib/array2d/array2d_kernel.h
+19
-51
dlib/array2d/array2d_kernel_abstract.h
dlib/array2d/array2d_kernel_abstract.h
+2
-3
No files found.
dlib/array2d/array2d_kernel.h
View file @
ab38059d
...
...
@@ -23,7 +23,6 @@ namespace dlib
- nc_ == 0
- nr_ == 0
- data == 0
- rows == 0
- at_start_ == true
- cur == 0
- last == 0
...
...
@@ -34,15 +33,10 @@ namespace dlib
- if (data != 0) then
- last == a pointer to the last element in the data array
- data == pointer to an array of nc_*nr_ T objects
- rows == pointer to an array of nr_ row objects
- for all x < nr_:
- rows[x].data == data + x*nc_
- rows[x].nc_ == nc_
- else
- nc_ == 0
- nr_ == 0
- data == 0
- rows == 0
- last == 0
...
...
@@ -119,13 +113,14 @@ namespace dlib
private:
long
nc_
;
row
(
T
*
data_
,
long
nc__
)
:
data
(
data_
),
nc_
(
nc__
)
{}
T
*
data
;
long
nc_
;
// restricted functions
row
(){}
row
(
row
&
);
row
&
operator
=
(
row
&
);
};
...
...
@@ -133,10 +128,9 @@ namespace dlib
array2d
(
)
:
data
(
0
),
nc_
(
0
),
nr_
(
0
),
rows
(
0
),
data
(
0
),
cur
(
0
),
last
(
0
),
at_start_
(
true
)
...
...
@@ -147,10 +141,9 @@ namespace dlib
long
nr__
,
long
nc__
)
:
data
(
0
),
nc_
(
0
),
nr_
(
0
),
rows
(
0
),
data
(
0
),
cur
(
0
),
last
(
0
),
at_start_
(
true
)
...
...
@@ -177,36 +170,36 @@ namespace dlib
long
nr
(
)
const
{
return
nr_
;
}
row
&
operator
[]
(
long
row
row
operator
[]
(
long
row
_
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
row
<
nr
()
&&
row
>=
0
,
"
\t
row
&
array2d::operator[](long row)"
DLIB_ASSERT
(
row
_
<
nr
()
&&
row
_
>=
0
,
"
\t
row array2d::operator[](long row
_
)"
<<
"
\n\t
The row index given must be less than the number of rows."
<<
"
\n\t
this: "
<<
this
<<
"
\n\t
row: "
<<
row
<<
"
\n\t
row
_
: "
<<
row
_
<<
"
\n\t
nr(): "
<<
nr
()
);
return
row
s
[
row
];
return
row
(
data
+
row_
*
nc_
,
nc_
);
}
const
row
&
operator
[]
(
long
row
const
row
operator
[]
(
long
row
_
)
const
{
// make sure requires clause is not broken
DLIB_ASSERT
(
row
<
nr
()
&&
row
>=
0
,
"
\t
const row
&
array2d::operator[](long row) const"
DLIB_ASSERT
(
row
_
<
nr
()
&&
row
_
>=
0
,
"
\t
const row array2d::operator[](long row
_
) const"
<<
"
\n\t
The row index given must be less than the number of rows."
<<
"
\n\t
this: "
<<
this
<<
"
\n\t
row: "
<<
row
<<
"
\n\t
row
_
: "
<<
row
_
<<
"
\n\t
nr(): "
<<
nr
()
);
return
row
s
[
row
];
return
row
(
data
+
row_
*
nc_
,
nc_
);
}
void
swap
(
...
...
@@ -214,14 +207,12 @@ namespace dlib
)
{
exchange
(
data
,
item
.
data
);
exchange
(
rows
,
item
.
rows
);
exchange
(
nr_
,
item
.
nr_
);
exchange
(
nc_
,
item
.
nc_
);
exchange
(
at_start_
,
item
.
at_start_
);
exchange
(
cur
,
item
.
cur
);
exchange
(
last
,
item
.
last
);
pool
.
swap
(
item
.
pool
);
rpool
.
swap
(
item
.
rpool
);
}
void
clear
(
...
...
@@ -229,11 +220,9 @@ namespace dlib
{
if
(
data
!=
0
)
{
rpool
.
deallocate_array
(
reinterpret_cast
<
row_helper
*>
(
rows
));
pool
.
deallocate_array
(
data
);
nc_
=
0
;
nr_
=
0
;
rows
=
0
;
data
=
0
;
at_start_
=
true
;
cur
=
0
;
...
...
@@ -317,20 +306,12 @@ namespace dlib
private:
// this object exists just so we can have a row type object that
// has a public default constructor so the memory_manager can construct it.
// I would have made rpool a friend of row but some compilers can't handle
// that without crapping out.
class
row_helper
:
public
row
{};
typename
mem_manager
::
template
rebind
<
T
>
::
other
pool
;
typename
mem_manager
::
template
rebind
<
row_helper
>
::
other
rpool
;
T
*
data
;
long
nc_
;
long
nr_
;
row
*
rows
;
T
*
data
;
typename
mem_manager
::
template
rebind
<
T
>
::
other
pool
;
mutable
T
*
cur
;
T
*
last
;
mutable
bool
at_start_
;
...
...
@@ -464,9 +445,7 @@ namespace dlib
if
(
data
!=
0
)
{
pool
.
deallocate_array
(
data
);
rpool
.
deallocate_array
(
reinterpret_cast
<
row_helper
*>
(
rows
));
data
=
0
;
rows
=
0
;
}
// now setup this object to have the new size
...
...
@@ -474,32 +453,21 @@ namespace dlib
{
if
(
nr_
>
0
)
{
rows
=
rpool
.
allocate_array
(
nr_
);
data
=
pool
.
allocate_array
(
nr_
*
nc_
);
last
=
data
+
nr_
*
nc_
-
1
;
}
}
catch
(...)
{
if
(
rows
)
rpool
.
deallocate_array
(
reinterpret_cast
<
row_helper
*>
(
rows
));
if
(
data
)
pool
.
deallocate_array
(
data
);
rows
=
0
;
data
=
0
;
nc_
=
0
;
nr_
=
0
;
last
=
0
;
throw
;
}
// now set up all the rows
for
(
long
i
=
0
;
i
<
nr_
;
++
i
)
{
rows
[
i
].
nc_
=
nc_
;
rows
[
i
].
data
=
data
+
i
*
nc_
;
}
}
// ----------------------------------------------------------------------------------------
...
...
dlib/array2d/array2d_kernel_abstract.h
View file @
ab38059d
...
...
@@ -108,7 +108,6 @@ namespace dlib
private:
// restricted functions
row
();
row
(
row
&
);
row
&
operator
=
(
row
&
);
};
...
...
@@ -191,7 +190,7 @@ namespace dlib
value for its type.
!*/
row
&
operator
[]
(
row
operator
[]
(
long
row_index
);
/*!
...
...
@@ -202,7 +201,7 @@ namespace dlib
given row_index'th row in *this.
!*/
const
row
&
operator
[]
(
const
row
operator
[]
(
long
row_index
)
const
;
/*!
...
...
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