|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_UTILS_TEXT_CONVERT_H_
2 #define GENESIS_UTILS_TEXT_CONVERT_H_
68 ss >> std::noskipws >> value;
78 throw std::invalid_argument(
79 "Cannot convert string \"" + str +
"\" to type " + std::string(
typeid(T).name() )
89 inline std::string convert_from_string<std::string>( std::string
const& str,
bool trim )
106 auto const value = std::strtod( input.c_str(), &end );
107 if( end ==
nullptr || *end !=
'\0' || end - input.c_str() !=
static_cast<long>( input.size() )) {
108 throw std::runtime_error(
109 "Cannot convert string \"" + input +
"\" to type double"
143 template<
typename ForwardIterator>
145 ForwardIterator first,
146 ForwardIterator last,
150 std::vector<bool> ret;
154 while( first != last ) {
161 template<
typename ForwardIterator>
163 ForwardIterator first,
166 while( first != last ) {
206 template<
typename ForwardIterator>
208 ForwardIterator first,
209 ForwardIterator last,
213 std::vector<double> ret;
217 while( first != last ) {
224 template<
typename ForwardIterator>
226 ForwardIterator first,
229 while( first != last ) {
259 template<
typename ForwardIterator>
261 ForwardIterator first,
262 ForwardIterator last,
266 std::vector<double> ret;
270 while( first != last ) {
277 template<
typename ForwardIterator>
279 ForwardIterator first,
282 while( first != last ) {
312 template<
typename ForwardIterator>
314 ForwardIterator first,
315 ForwardIterator last,
319 std::vector<long long> ret;
323 while( first != last ) {
330 template<
typename ForwardIterator>
332 ForwardIterator first,
335 while( first != last ) {
365 template<
typename ForwardIterator>
367 ForwardIterator first,
368 ForwardIterator last,
372 std::vector<unsigned long long> ret;
376 while( first != last ) {
383 template<
typename ForwardIterator>
385 ForwardIterator first,
388 while( first != last ) {
400 #endif // include guard
double convert_from_string< double >(std::string const &str, bool trim)
Specialization of the generic conversion function for double, which also takes nan and inf into accou...
bool is_convertible_to_unsigned_integer(std::string const &str)
Return whether a string can be converted to unsigned integer.
bool is_convertible_to_bool(Dataframe const &df, size_t col_index)
std::string trim(std::string const &s, std::string const &delimiters)
Return a copy of the input string, with trimmed white spaces (or any other delimiters).
void convert_to_double(Dataframe &df, size_t col_index)
Provides some commonly used string utility functions.
bool convert_to_unsigned_integer(std::string const &str, unsigned long long &result)
Convert a string to unsigned integer, store the result in result, and return whether the conversion a...
T convert_from_string(std::string const &str, bool trim=false)
Generic conversion from string to any data type that is supported by std::stringsteam operator >>.
bool is_convertible_to_bool_double(std::string const &str)
Return whether a string can be converted to bool (and stored as a double).
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
bool is_convertible_to_double(Dataframe const &df, size_t col_index)
void convert_to_bool(Dataframe &df, size_t col_index)
bool is_convertible_to_signed_integer(std::string const &str)
Return whether a string can be converted to signed integer.
bool convert_to_signed_integer(std::string const &str, long long &result)
Convert a string to signed integer, store the result in result, and return whether the conversion as ...
bool convert_to_bool_double(std::string const &str, double &result)
Convert a string to bool, but store the result as a double in result, and return whether the conversi...