summaryrefslogtreecommitdiff
path: root/libcult/cult/cli/options-parser.txx
blob: bd8172acbf1362c57132676330d47fa68efa45e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// file      : cult/cli/options-parser.txx
// author    : Boris Kolpackov <boris@kolpackov.net>
// copyright : Copyright (c) 2005-2010 Boris Kolpackov
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

namespace Cult
{
  namespace CLI
  {
    // OptionParserBase
    //
    template <typename T>
    T OptionParserBase<T>::
    parse (Char const* o, Scanner& s)
    {
      Char const* v (s.next ());

      //@@ "expected something after --option"?
      //
      if (v == Scanner::eos)
        throw OptionFormat (o);

      T r;
      std::istringstream is (v);
      is >> r;

      if (is.fail () || !is.eof ())
        throw OptionFormat (o);

      return r;
    }
  }
}