~ubuntu-branches/ubuntu/wily/cxxtools/wily-proposed

« back to all changes in this revision

Viewing changes to include/cxxtools/iniparser.h

  • Committer: Bazaar Package Importer
  • Author(s): Kari Pahula
  • Date: 2008-06-16 12:24:28 UTC
  • mfrom: (3.1.3 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616122428-7bllgyt1358u779r
Tags: 1.4.8-2
Made libcxxtools-dev depend on libcxxtools6, not libcxxtools5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * cxxtools - general purpose C++-toolbox
 
3
 * Copyright (C) 2007 Tommi Maekitalo
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License as
 
7
 * published by the Free Software Foundation; either version 2 of the
 
8
 * License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful, but
 
11
 * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
 
12
 * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
 
13
 * NON-INFRINGEMENT.  See the GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
18
 *
 
19
 */
 
20
 
 
21
#include <iosfwd>
 
22
#include <string>
 
23
 
 
24
namespace cxxtools
 
25
{
 
26
  /**
 
27
   * Parser for files in ini-format
 
28
   */
 
29
  class IniParser
 
30
  {
 
31
    public:
 
32
      class Event
 
33
      {
 
34
        public:
 
35
          // events return true, if parsing should be stopped
 
36
          virtual bool onSection(const std::string& section);
 
37
          virtual bool onKey(const std::string& key);
 
38
          virtual bool onValue(const std::string& key);
 
39
          virtual bool onComment(const std::string& comment);
 
40
          virtual bool onError();
 
41
      };
 
42
 
 
43
    private:
 
44
      Event& event;
 
45
      std::string data;
 
46
      enum
 
47
      {
 
48
        state_0,
 
49
        state_section,
 
50
        state_key,
 
51
        state_key_sp,
 
52
        state_value0,
 
53
        state_value,
 
54
        state_comment
 
55
 
 
56
      } state;
 
57
 
 
58
    public:
 
59
      IniParser(Event& event_)
 
60
        : event(event_),
 
61
          state(state_0)
 
62
        { }
 
63
 
 
64
      bool parse(char ch);
 
65
      void end();
 
66
      void parse(std::istream& in);
 
67
  };
 
68
}