argagg
Loading...
Searching...
No Matches
include
argagg
convert
csv.hpp
Go to the documentation of this file.
1
/*
2
* @file
3
* @brief
4
* Defines the argagg::csv type and an argument conversion specialization that
5
* parses an argument as an argagg::csv.
6
*
7
* @copyright
8
* Copyright (c) 2018 Viet The Nguyen
9
*
10
* @copyright
11
* Permission is hereby granted, free of charge, to any person obtaining a copy
12
* of this software and associated documentation files (the "Software"), to
13
* deal in the Software without restriction, including without limitation the
14
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
15
* sell copies of the Software, and to permit persons to whom the Software is
16
* furnished to do so, subject to the following conditions:
17
*
18
* @copyright
19
* The above copyright notice and this permission notice shall be included in
20
* all copies or substantial portions of the Software.
21
*
22
* @copyright
23
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29
* IN THE SOFTWARE.
30
*/
31
#pragma once
32
#ifndef ARGAGG_ARGAGG_CONVERT_CSV_HPP
33
#define ARGAGG_ARGAGG_CONVERT_CSV_HPP
34
35
#include "
../argagg.hpp
"
36
37
#include <vector>
38
39
40
namespace
argagg
{
41
48
template
<
typename
T>
49
struct
csv
{
50
std::vector<T>
values
;
51
};
52
53
namespace
convert {
54
60
template
<
typename
T>
61
struct
converter
<
csv
<T>> {
62
static
csv<T>
convert(
const
char
* s);
63
};
64
65
}
// namespace convert
66
67
}
// namespace argagg
68
69
70
// ---- end of declarations, header-only implementations follow ----
71
72
73
namespace
argagg
{
74
namespace
convert {
75
76
77
template
<
typename
T>
78
csv<T>
79
converter<csv<T>
>::convert(
const
char
* s)
80
{
81
csv<T>
result {{}};
82
T value;
83
while
(
parse_next_component
(s, value,
','
)) {
84
result.
values
.emplace_back(
std::move
(value));
85
}
86
result.values.emplace_back(
std::move
(value));
87
return
result;
88
}
89
90
91
}
// namespace convert
92
}
// namespace argagg
93
94
95
#endif
// ARGAGG_ARGAGG_CONVERT_CSV_HPP
argagg.hpp
std::move
T move(T... args)
argagg::convert::parse_next_component
bool parse_next_component(const char *&s, T &out_arg, const char delim=',')
A utility function for parsing an argument as a delimited list. To use, initialize a const char* poin...
Definition
argagg.hpp:1552
argagg
There are only two hard things in Computer Science: cache invalidation and naming things (Phil Karlto...
Definition
argagg.hpp:96
argagg::convert::converter
For simple types the main extension point for adding argument conversions is argagg::convert::arg<T>(...
Definition
argagg.hpp:186
argagg::csv
Represents a list of comma-separated values. This is defined as a new type to embed the delimiter sem...
Definition
csv.hpp:49
argagg::csv::values
std::vector< T > values
Definition
csv.hpp:50
std::vector
Generated by
1.11.0