|
|
// ConfigFile - interface to configuration data // Copyright (C) 2000, 2001, 2002 Stephan Beal & Rusty Ballinger // sgbeal@users.sourceforge.net & bozo@users.sourceforge.net // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // http://www.gnu.org (but you knew that, didn't you?) #ifndef _FUN_CONFIGFILE_H #define _FUN_CONFIGFILE_H /** * Comment this out if you don't want ConfigFile to be XMLAble. This * should be set by the configure script depending on whether libxml is * available. Or if we know we'll always want ConfigFile to be XMLAble, * this can be removed. */ //#define CONFIGFILE_IS_XMLABLE #include#include #include #include //#ifdef CONFIGFILE_IS_XMLABLE //#include //#endif // CONFIGFILE_IS_XMLABLE #include //#include //#include //#include //#include #include namespace fun { /** * ConfigFile loads and saves configuration files which can be represented * as simple key/value pairs of strings. They can be loaded from & saved * to plain text or XML files. * * The most interesting methods are probably getString(), getInt(), etc., * as those are how you get at the configuration values loaded from file. * If you need to know whether a value was explicitly set in the file, * use isSet(). That might be a little cumbersome; hopefully there aren't * that many cases where it will matter whether a value was explicitly set, * or couldn't be interpreted as an int or whatever. * * The text format used will treat lines ending in "\" as continued on * the next line. \t and \n will be expanded into tab and newline during * reading, and will be escaped again during writing. */ //#ifdef CONFIGFILE_IS_XMLABLE // , public XMLAble //#endif class ConfigFile : public PropertyList { Q_OBJECT public: ConfigFile( const QString &filename = QString() ); ~ConfigFile(); virtual void deserialize(const Deserializer &node); virtual void serialize(Serializer &node) const; public slots: /** * Loads this ConfigFile from the given file. If filename is empty, * this->getFilename() will be used. */ virtual bool loadFromXML( const QString &filename = QString() ); /** * Saves this ConfigFile to the given file. If filename is empty, * this->getFilename() will be used. */ virtual bool saveToXML(const QString &filename=QString()) const; /* Type-savers for saveTo/loadFromXML() */ virtual bool save(); virtual bool load(); // #endif /** * Loads this ConfigFile from the given input stream. */ bool loadFromText( std::istream &is); /** * Stores this ConfigFile to the given output stream. */ bool saveToText( std::ostream &os) const; void setFilename( const QString &fn ); QString getFilename(); static ConfigFile & funConfig(); private: mutable QString filename; static ConfigFile funconfig; }; // end class ConfigFile }; // namespace fun #endif // _FUN_CONFIGFILE_H
Generated by: stephan on cheyenne on Mon Aug 11 14:06:52 2003, using kdoc 2.0a54. |