- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- File List
- File Members

# sbuild-parse-value.h

Go to the documentation of this file.

    00001 /* Copyright © 2005-2006  Roger Leigh <rleigh@debian.org>
    00002  *
    00003  * schroot is free software; you can redistribute it and/or modify it
    00004  * under the terms of the GNU General Public License as published by
    00005  * the Free Software Foundation; either version 2 of the License, or
    00006  * (at your option) any later version.
    00007  *
    00008  * schroot is distributed in the hope that it will be useful, but
    00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
    00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00011  * General Public License for more details.
    00012  *
    00013  * You should have received a copy of the GNU General Public License
    00014  * along with this program; if not, write to the Free Software
    00015  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
    00016  * MA  02111-1307  USA
    00017  *
    00018  *********************************************************************/
    00019
    00020 #ifndef SBUILD_PARSE_VALUE_H
    00021 #define SBUILD_PARSE_VALUE_H
    00022
    00023 #include <sbuild/sbuild-parse-error.h>
    00024 #include <sbuild/sbuild-log.h>
    00025
    00026 #include <string>
    00027 #include <sstream>
    00028
    00029 namespace sbuild
    00030 {
    00031
    00032   enum parse_value_error_code
    00033     {
    00034       BAD_VALUE
    00035     };
    00036
    00037   typedef parse_error<parse_value_error_code> parse_value_error;
    00038
    00045   void
    00046   parse_value (std::string const& value,
    00047                bool&              parsed_value);
    00048
    00055   void
    00056   parse_value (std::string const& value,
    00057                std::string&       parsed_value);
    00058
    00065   template <typename T>
    00066   void
    00067   parse_value (std::string const& value,
    00068                T& parsed_value)
    00069   {
    00070     std::istringstream is(value);
    00071     is.imbue(std::locale::classic());
    00072     T tmpval;
    00073     if (is >> tmpval)
    00074       {
    00075         parsed_value = tmpval;
    00076         log_debug(DEBUG_NOTICE) << "value=" << parsed_value << std::endl;
    00077       }
    00078     else
    00079       {
    00080         log_debug(DEBUG_NOTICE) << "parse error" << std::endl;
    00081         throw parse_value_error(value, BAD_VALUE);
    00082       }
    00083   }
    00084
    00085 }
    00086
    00087 #endif /* SBUILD_PARSE_VALUE_H */
    00088
    00089 /*
    00090  * Local Variables:
    00091  * mode:C++
    00092  * End:
    00093  */