~ubuntu-branches/ubuntu/intrepid/schroot/intrepid

« back to all changes in this revision

Viewing changes to sbuild/sbuild-parse-value.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2006-07-08 18:33:28 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060708183328-rlo4mpldmyoda55q
Tags: 0.99.2-2ubuntu1
* remerge ubuntu changes:
  + debian/control: libpam-dev (>> 0.79-3ubuntu6)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright © 2005-2006  Roger Leigh <rleigh@debian.org>
 
2
 *
 
3
 * schroot is free software; you can redistribute it and/or modify it
 
4
 * under the terms of the GNU General Public License as published by
 
5
 * the Free Software Foundation; either version 2 of the License, or
 
6
 * (at your option) any later version.
 
7
 *
 
8
 * schroot is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program; if not, write to the Free Software
 
15
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 
16
 * MA  02111-1307  USA
 
17
 *
 
18
 *********************************************************************/
 
19
 
 
20
#ifndef SBUILD_PARSE_VALUE_H
 
21
#define SBUILD_PARSE_VALUE_H
 
22
 
 
23
#include <sbuild/sbuild-parse-error.h>
 
24
#include <sbuild/sbuild-log.h>
 
25
 
 
26
#include <string>
 
27
#include <sstream>
 
28
 
 
29
namespace sbuild
 
30
{
 
31
 
 
32
  /**
 
33
   * Parse a boolean value.
 
34
   * @param value the value to parse.
 
35
   * @param parsed_value the variable to store the parsed value.
 
36
   * @returns true on success, false on failure.
 
37
   */
 
38
  void
 
39
  parse_value (std::string const& value,
 
40
               bool&              parsed_value);
 
41
 
 
42
  /**
 
43
   * Parse a string value.
 
44
   * @param value the value to parse.
 
45
   * @param parsed_value the variable to store the parsed value.
 
46
   * @returns true on success, false on failure.
 
47
   */
 
48
  void
 
49
  parse_value (std::string const& value,
 
50
               std::string&       parsed_value);
 
51
 
 
52
  /**
 
53
   * Parse a value of type T.
 
54
   * @param value the value to parse.
 
55
   * @param parsed_value the variable to store the parsed value.
 
56
   * @returns true on success, false on failure.
 
57
   */
 
58
  template <typename T>
 
59
  void
 
60
  parse_value (std::string const& value,
 
61
               T& parsed_value)
 
62
  {
 
63
    std::istringstream is(value);
 
64
    is.imbue(std::locale("C"));
 
65
    T tmpval;
 
66
    if (is >> tmpval)
 
67
      {
 
68
        parsed_value = tmpval;
 
69
        log_debug(DEBUG_NOTICE) << "value=" << parsed_value << std::endl;
 
70
      }
 
71
    else
 
72
      {
 
73
        log_debug(DEBUG_NOTICE) << "parse error" << std::endl;
 
74
        throw parse_error(parse_error::BAD_VALUE, value);
 
75
        }
 
76
  }
 
77
 
 
78
}
 
79
 
 
80
#endif /* SBUILD_PARSE_VALUE_H */
 
81
 
 
82
/*
 
83
 * Local Variables:
 
84
 * mode:C++
 
85
 * End:
 
86
 */