Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
25ccbc42
Commit
25ccbc42
authored
Nov 05, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added serialization support for std::array.
parent
cccde632
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
0 deletions
+91
-0
serialize.h
dlib/serialize.h
+61
-0
serialize.cpp
dlib/test/serialize.cpp
+30
-0
No files found.
dlib/serialize.h
View file @
25ccbc42
...
...
@@ -62,6 +62,7 @@
- std::string
- std::wstring
- std::vector
- std::array
- std::deque
- std::map
- std::set
...
...
@@ -80,6 +81,7 @@
- std::string
- std::wstring
- std::vector
- std::array
- std::deque
- std::map
- std::set
...
...
@@ -145,6 +147,7 @@
#include <fstream>
#include <string>
#include <vector>
#include <array>
#include <deque>
#include <complex>
#include <map>
...
...
@@ -1363,6 +1366,64 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
size_t
N
>
inline
void
serialize
(
const
std
::
array
<
T
,
N
>&
array
,
std
::
ostream
&
out
)
{
typedef
T
c_array_type
[
N
];
serialize
(
*
(
const
c_array_type
*
)
array
.
data
(),
out
);
}
template
<
typename
T
,
size_t
N
>
inline
void
deserialize
(
std
::
array
<
T
,
N
>&
array
,
std
::
istream
&
in
)
{
typedef
T
c_array_type
[
N
];
deserialize
(
*
(
c_array_type
*
)
array
.
data
(),
in
);
}
template
<
typename
T
>
inline
void
serialize
(
const
std
::
array
<
T
,
0
>&
/*array*/
,
std
::
ostream
&
out
)
{
size_t
N
=
0
;
serialize
(
N
,
out
);
}
template
<
typename
T
>
inline
void
deserialize
(
std
::
array
<
T
,
0
>&
/*array*/
,
std
::
istream
&
in
)
{
size_t
N
;
deserialize
(
N
,
in
);
if
(
N
!=
0
)
{
std
::
ostringstream
sout
;
sout
<<
"Expected std::array of size 0 but found a size of "
<<
N
;
throw
serialization_error
(
sout
.
str
());
}
}
// ----------------------------------------------------------------------------------------
template
<
...
...
dlib/test/serialize.cpp
View file @
25ccbc42
...
...
@@ -616,6 +616,35 @@ namespace
DLIB_TEST
(
c
.
size
()
==
0
);
}
void
test_std_array
(
)
{
std
::
array
<
int
,
5
>
a
,
b
;
a
=
{
1
,
2
,
3
,
4
,
5
};
ostringstream
sout
;
dlib
::
serialize
(
a
,
sout
);
istringstream
sin
(
sout
.
str
());
dlib
::
deserialize
(
b
,
sin
);
DLIB_TEST
(
a
.
size
()
==
b
.
size
());
DLIB_TEST
(
a
.
size
()
==
5
);
for
(
unsigned
long
i
=
0
;
i
<
a
.
size
();
++
i
)
{
DLIB_TEST
(
a
[
i
]
==
b
[
i
]);
}
std
::
array
<
int
,
0
>
aa
,
bb
;
sout
.
str
(
""
);
dlib
::
serialize
(
aa
,
sout
);
sin
.
str
(
sout
.
str
());
dlib
::
deserialize
(
bb
,
sin
);
DLIB_TEST
(
bb
.
size
()
==
0
);
}
void
test_vector_bool
(
)
{
...
...
@@ -1020,6 +1049,7 @@ namespace
test_vector_bool
();
test_array2d_and_matrix_serialization
();
test_strings
();
test_std_array
();
}
}
a
;
...
...
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