Loading...
Searching...
No Matches
csv.hpp
Go to the documentation of this file.
/*
* @file
* @brief
* Defines the argagg::csv type and an argument conversion specialization that
* parses an argument as an argagg::csv.
*
* @copyright
* Copyright (c) 2018 Viet The Nguyen
*
* @copyright
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* @copyright
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* @copyright
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#pragma once
#ifndef ARGAGG_ARGAGG_CONVERT_CSV_HPP
#define ARGAGG_ARGAGG_CONVERT_CSV_HPP
#include "../argagg.hpp"
#include <vector>
namespace argagg {
template <typename T>
struct csv {
std::vector<T> values;
};
namespace convert {
template <typename T>
struct converter<csv<T>> {
static csv<T> convert(const char* s);
};
} // namespace convert
} // namespace argagg
// ---- end of declarations, header-only implementations follow ----
namespace argagg {
namespace convert {
template <typename T>
csv<T>
converter<csv<T>>::convert(const char* s)
{
csv<T> result {{}};
T value;
while (parse_next_component(s, value, ',')) {
result.values.emplace_back(std::move(value));
}
result.values.emplace_back(std::move(value));
return result;
}
} // namespace convert
} // namespace argagg
#endif // ARGAGG_ARGAGG_CONVERT_CSV_HPP
argagg.hpp
std::move
T move(T... args)
argagg::convert
The set of template instantiations that convert C-strings to other types for the option_result::as(),...
Definition argagg.hpp:164
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< csv< T > >::convert
static csv< T > convert(const char *s)
Definition csv.hpp:79
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