argagg
Loading...
Searching...
No Matches
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
40namespace argagg {
41
48template <typename T>
52
53namespace 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
73namespace argagg {
74namespace convert {
75
76
77template <typename T>
79converter<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
T move(T... args)
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
T arg(const char *arg)
Explicit instantiations of this function are used to convert arguments to types.
Definition argagg.hpp:1488
There are only two hard things in Computer Science: cache invalidation and naming things (Phil Karlto...
Definition argagg.hpp:96
For simple types the main extension point for adding argument conversions is argagg::convert::arg<T>(...
Definition argagg.hpp:186
Represents a list of comma-separated values. This is defined as a new type to embed the delimiter sem...
Definition csv.hpp:49
std::vector< T > values
Definition csv.hpp:50