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
11756238
Commit
11756238
authored
Jul 08, 2013
by
Davis King
Browse files
Added the csv io manipulator that lets you print a matrix in cvs format.
parent
a97b5794
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
dlib/matrix/matrix.h
dlib/matrix/matrix.h
+45
-0
No files found.
dlib/matrix/matrix.h
View file @
11756238
...
@@ -1813,6 +1813,51 @@ namespace dlib
...
@@ -1813,6 +1813,51 @@ namespace dlib
This function is defined inside the matrix_read_from_istream.h file.
This function is defined inside the matrix_read_from_istream.h file.
*/
*/
// ----------------------------------------------------------------------------------------
class
print_matrix_as_csv_helper
{
/*!
This object is used to define an io manipulator for matrix expressions.
In particular, this code allows you to write statements like:
cout << csv << yourmatrix;
and have it print the matrix with commas separating each element.
!*/
public:
print_matrix_as_csv_helper
(
std
::
ostream
&
out_
)
:
out
(
out_
)
{}
template
<
typename
EXP
>
std
::
ostream
&
operator
<<
(
const
matrix_exp
<
EXP
>&
m
)
{
for
(
long
r
=
0
;
r
<
m
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
m
.
nc
();
++
c
)
{
if
(
c
+
1
==
m
.
nc
())
out
<<
m
(
r
,
c
)
<<
"
\n
"
;
else
out
<<
m
(
r
,
c
)
<<
", "
;
}
}
return
out
;
}
private:
std
::
ostream
&
out
;
};
class
print_matrix_as_csv
{};
const
print_matrix_as_csv
csv
;
inline
print_matrix_as_csv_helper
operator
<<
(
std
::
ostream
&
out
,
const
print_matrix_as_csv
&
)
{
return
print_matrix_as_csv_helper
(
out
);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
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