Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Socrate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Avionics
Software Development
Socrate
Commits
0694cd13
Commit
0694cd13
authored
3 years ago
by
Davide Mor
Browse files
Options
Downloads
Patches
Plain Diff
Uncommented csv example
parent
17b4e8f1
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/csv.cpp
+42
-42
42 additions, 42 deletions
examples/csv.cpp
with
42 additions
and
42 deletions
examples/csv.cpp
+
42
−
42
View file @
0694cd13
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
Simple example, showing the creation of csv printer for arrays, based on reflector.
Simple example, showing the creation of csv printer for arrays, based on reflector.
*/
*/
//
#include <iostream>
#include
<iostream>
#include
<vector>
#include
<vector>
#include
"../reflect.hpp"
#include
"../reflect.hpp"
...
@@ -10,46 +10,46 @@ Simple example, showing the creation of csv printer for arrays, based on reflect
...
@@ -10,46 +10,46 @@ Simple example, showing the creation of csv printer for arrays, based on reflect
// Csv printer
// Csv printer
// ================================
// ================================
//
namespace
C
sv {
namespace
c
sv
{
//
template<typename T>
template
<
typename
T
>
//
constexpr void header(std::ostream& output) {
constexpr
void
header
(
std
::
ostream
&
output
)
{
//
bool first = true;
bool
first
=
true
;
//
T::reflect().for_each_field_type([&](const char* name, auto _type) {
T
::
reflect
().
for_each_field_type
([
&
](
const
char
*
name
,
auto
_type
)
{
//
if(!first) {
if
(
!
first
)
{
//
output << ",";
output
<<
","
;
//
}
}
//
//
output << name;
output
<<
name
;
//
first = false;
first
=
false
;
//
});
});
//
//
output << std::endl;
output
<<
std
::
endl
;
//
}
}
//
//
template<typename T>
template
<
typename
T
>
//
constexpr void row(std::ostream& output, T& value) {
constexpr
void
row
(
std
::
ostream
&
output
,
T
&
value
)
{
//
bool first = true;
bool
first
=
true
;
//
T::reflect().for_each_field(value, [&](const char* name, auto &field) {
T
::
reflect
().
for_each_field
(
value
,
[
&
](
const
char
*
name
,
auto
&
field
)
{
//
if(!first) {
if
(
!
first
)
{
//
output << ",";
output
<<
","
;
//
}
}
//
//
output << field;
output
<<
field
;
//
first = false;
first
=
false
;
//
});
});
//
//
output << std::endl;
output
<<
std
::
endl
;
//
}
}
//
//
template<typename T>
template
<
typename
T
>
//
constexpr void print(std::ostream& output, std::vector<T>& rows) {
constexpr
void
print
(
std
::
ostream
&
output
,
std
::
vector
<
T
>&
rows
)
{
//
C
sv::header<T>(output);
c
sv
::
header
<
T
>
(
output
);
//
for(auto& row : rows) {
for
(
auto
&
row
:
rows
)
{
//
C
sv::row(output, row);
c
sv
::
row
(
output
,
row
);
//
}
}
//
}
}
//
}
}
//
// ================================
// ================================
// main
// main
// ================================
// ================================
...
@@ -86,7 +86,7 @@ int main() {
...
@@ -86,7 +86,7 @@ int main() {
Bar
{
20
,
35.0
f
,
'b'
,
false
}
Bar
{
20
,
35.0
f
,
'b'
,
false
}
};
};
// C
sv::print(std::cout, rows);
c
sv
::
print
(
std
::
cout
,
rows
);
return
0
;
return
0
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment