Skip to content

Commit

Permalink
Better impl
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Jan 11, 2022
1 parent 3e0d983 commit b808465
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
30 changes: 27 additions & 3 deletions src/library/F3DOperators.h
@@ -1,21 +1,45 @@
#ifndef F3DOperators_h
#define F3DOperators_h

#include <sstream>
#include <algorithm>
#include <iterator>
#include <locale>
#include <sstream>
#include <vector>

//----------------------------------------------------------------------------
// Make the istream_iterator works with comma
// Uses std coding style for consistency
class comma_ctype : public std::ctype<char>
{
mask ctype_table[table_size];
public:
comma_ctype(size_t refs = 0)
: std::ctype<char>(&ctype_table[0], false, refs)
{
std::copy_n(classic_table(), table_size, ctype_table);
ctype_table[','] = (mask)space;
}
};

static std::locale comma(std::locale::classic(), new comma_ctype);

//----------------------------------------------------------------------------
// Operator<< for easy copy of vector into string
template<typename T>
std::ostream& operator<< (std::ostream &stream, const std::vector<T>& vector)
{
std::copy(vector.begin(), vector.end(), std::ostream_iterator<T>(stream,"\n"));
std::copy(vector.begin(), vector.end(), std::ostream_iterator<T>(stream,","));
return stream;
}

//----------------------------------------------------------------------------
// Operator<< for easy copy of string into vector
template<typename T>
std::istream& operator>> (std::istream &stream, std::vector<T>& vector)
{
copy(std::istream_iterator<T>(stream), std::istream_iterator<T>(), std::back_inserter(vector));
stream.imbue(comma);
std::copy(std::istream_iterator<T>(stream), std::istream_iterator<T>(), std::back_inserter(vector));
return stream;
}

Expand Down
37 changes: 18 additions & 19 deletions src/library/f3d_options.cxx
Expand Up @@ -27,13 +27,12 @@ void options::set(const std::string &name, const T& value)
}

//----------------------------------------------------------------------------
template void options::set<bool>(const std::string &name, const bool& value);
template void options::set<int>(const std::string &name, const int& value);
template void options::set<double>(const std::string &name, const double& value);
template void options::set<std::string>(const std::string &name, const std::string& value);
template void options::set<std::vector<int>>(const std::string &name, const std::vector<int>& value);
template void options::set<std::vector<double>>(const std::string &name, const std::vector<double>& value);

template void options::set<>(const std::string &name, const bool& value);
template void options::set<>(const std::string &name, const int& value);
template void options::set<>(const std::string &name, const double& value);
template void options::set<>(const std::string &name, const std::string& value);
template void options::set<>(const std::string &name, const std::vector<int>& value);
template void options::set<>(const std::string &name, const std::vector<double>& value);

//----------------------------------------------------------------------------
template <typename T>
Expand All @@ -44,12 +43,12 @@ void options::get(const std::string &name, T& value) const
}

//----------------------------------------------------------------------------
template void options::get<bool>(const std::string &name, bool& value) const;
template void options::get<int>(const std::string &name, int& value) const;
template void options::get<double>(const std::string &name, double& value) const;
template void options::get<std::string>(const std::string &name, std::string& value) const;
template void options::get<std::vector<int>>(const std::string &name, std::vector<int>& value) const;
template void options::get<std::vector<double>>(const std::string &name, std::vector<double>& value) const;
template void options::get<>(const std::string &name, bool& value) const;
template void options::get<>(const std::string &name, int& value) const;
template void options::get<>(const std::string &name, double& value) const;
template void options::get<>(const std::string &name, std::string& value) const;
template void options::get<>(const std::string &name, std::vector<int>& value) const;
template void options::get<>(const std::string &name, std::vector<double>& value) const;

//----------------------------------------------------------------------------
template <typename T>
Expand All @@ -62,10 +61,10 @@ T options::get(const std::string &name) const
}

//----------------------------------------------------------------------------
template bool options::get<bool>(const std::string &name) const;
template int options::get<int>(const std::string &name) const;
template double options::get<double>(const std::string &name) const;
template std::string options::get<std::string>(const std::string &name) const;
template std::vector<int> options::get<std::vector<int>>(const std::string &name) const;
template std::vector<double> options::get<std::vector<double>>(const std::string &name) const;
template bool options::get<>(const std::string &name) const;
template int options::get<>(const std::string &name) const;
template double options::get<>(const std::string &name) const;
template std::string options::get<>(const std::string &name) const;
template std::vector<int> options::get<>(const std::string &name) const;
template std::vector<double> options::get<>(const std::string &name) const;
}

0 comments on commit b808465

Please sign in to comment.