options: instantiate valueoptions privately

By not providing each translation unit with the general form code we can
more easily force people to use the specialised code for types like
bool.
This commit is contained in:
Danny Robson 2014-10-21 21:47:10 +11:00
parent 7278eff60a
commit 31326ef576
2 changed files with 32 additions and 12 deletions

View File

@ -131,6 +131,7 @@ presentoption::execute (void) {
* Value option
*/
namespace util {
template<>
bool&
@ -144,9 +145,36 @@ namespace util {
return *val;
}
template <typename T>
T&
valueoption<T>::get_arg(const std::string &arg,
T *val)
{
std::istringstream stream (arg, std::istringstream::in);
stream.exceptions (
std::istringstream::failbit
| std::istringstream::badbit
);
stream >> *val;
return *val;
}
}
template std::string& util::valueoption<std::string>::get_arg (const std::string&, std::string*);
template int16_t& util::valueoption< int16_t>::get_arg (const std::string&, int16_t*);
template int32_t& util::valueoption< int32_t>::get_arg (const std::string&, int32_t*);
template int64_t& util::valueoption< int64_t>::get_arg (const std::string&, int64_t*);
template uint16_t& util::valueoption<uint16_t>::get_arg (const std::string&, uint16_t*);
template uint32_t& util::valueoption<uint32_t>::get_arg (const std::string&, uint32_t*);
template uint64_t& util::valueoption<uint64_t>::get_arg (const std::string&, uint64_t*);
/*
* bytesoption
*/

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with libgim. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2013 Danny Robson <danny@nerdcruft.net>
* Copyright 2013-2014 Danny Robson <danny@nerdcruft.net>
*/
@ -167,18 +167,11 @@ namespace util {
protected:
// Retrieve string to value conversion
static
T& get_arg(const std::string &arg,
T *val) {
std::istringstream stream (arg, std::istringstream::in);
stream.exceptions (
std::istringstream::failbit
| std::istringstream::badbit
);
stream >> *val;
return *val;
}
T *val);
static
T& get_arg(const std::string &_arg,
T *val,
const T &defaultval) {
@ -303,5 +296,4 @@ namespace util {
};
}
#endif