Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

/home/tommi/cxxtools/include/cxxtools/iniparser.h

00001 /*
00002  * Copyright (C) 2007 Tommi Maekitalo
00003  * 
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  * 
00009  * As a special exception, you may use this file as part of a free
00010  * software library without restriction. Specifically, if other files
00011  * instantiate templates or use macros or inline functions from this
00012  * file, or you compile this file and link it with other files to
00013  * produce an executable, this file does not by itself cause the
00014  * resulting executable to be covered by the GNU General Public
00015  * License. This exception does not however invalidate any other
00016  * reasons why the executable file might be covered by the GNU Library
00017  * General Public License.
00018  * 
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this library; if not, write to the Free Software
00026  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00027  */
00028 
00029 #include <iosfwd>
00030 #include <string>
00031 
00032 namespace cxxtools
00033 {
00037   class IniParser
00038   {
00039     public:
00040       class Event
00041       {
00042         public:
00043           // events return true, if parsing should be stopped
00044           virtual bool onSection(const std::string& section);
00045           virtual bool onKey(const std::string& key);
00046           virtual bool onValue(const std::string& key);
00047           virtual bool onComment(const std::string& comment);
00048           virtual bool onError();
00049       };
00050 
00051     private:
00052       Event& event;
00053       std::string data;
00054       enum
00055       {
00056         state_0,
00057         state_section,
00058         state_key,
00059         state_key_sp,
00060         state_value0,
00061         state_value,
00062         state_comment
00063 
00064       } state;
00065 
00066     public:
00067       IniParser(Event& event_)
00068         : event(event_),
00069           state(state_0)
00070         { }
00071 
00072       bool parse(char ch);
00073       void end();
00074       void parse(std::istream& in);
00075   };
00076 }
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6