helper-fns.h revision 087b237ce230e9b7a16dc95537dbb62f7d715026
5992N/A#ifndef SEEN_HELPER_FNS_H
5992N/A#define SEEN_HELPER_FNS_H
5992N/A/** \file
5992N/A *
5992N/A * Some helper functions
5992N/A *
5992N/A * Authors:
5992N/A * Felipe CorrĂȘa da Silva Sanches <felipe.sanches@gmail.com>
5992N/A *
5992N/A *
5992N/A * Copyright (C) 2006 Hugo Rodrigues
5992N/A *
5992N/A * Released under GNU GPL, read the file 'COPYING' for more information
5992N/A */
5992N/A
5992N/A#include <sstream>
5992N/A
5992N/Astatic double
5992N/Ahelperfns_read_number(gchar const *value) {
5992N/A if (!value) return 0;
5992N/A char *end;
5992N/A double ret = g_ascii_strtod(value, &end);
5992N/A if (*end) {
5992N/A g_warning("Unable to convert \"%s\" to number", value);
5992N/A // We could leave this out, too. If strtod can't convert
5992N/A // anything, it will return zero.
5992N/A ret = 0;
5992N/A }
5992N/A return ret;
5992N/A}
5992N/A
6003N/Astatic bool helperfns_read_bool(gchar const *value, bool default_value){
6003N/A if (!value) return default_value;
6003N/A switch(value[0]){
6003N/A case 't':
5992N/A if (strncmp(value, "true", 4) == 0) return true;
5992N/A break;
5992N/A case 'f':
5992N/A if (strncmp(value, "false", 5) == 0) return false;
5992N/A break;
5992N/A }
5992N/A return default_value;
6003N/A}
5992N/A
5992N/Astatic std::vector<gdouble> helperfns_read_vector(const gchar* value, int size){
5992N/A std::vector<gdouble> v(size, (gdouble) 0);
6003N/A std::istringstream is(value);
6003N/A for(int i = 0; i < size && (is >> v[i]); i++);
6003N/A return v;
5992N/A}
5992N/A
5992N/A#endif /* !SEEN_HELPER_FNS_H */
5992N/A
5992N/A/*
5992N/A Local Variables:
5992N/A mode:c++
5992N/A c-file-style:"stroustrup"
5992N/A c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
5992N/A indent-tabs-mode:nil
5993N/A fill-column:99
5992N/A End:
5992N/A*/
5992N/A// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
5992N/A