Main Page   Compound List   Header Files   Compound Members  

simplecfg.h

This is the verbatim text of the simplecfg.h include file.
//======================================================================
// File:    simplecfg.h
// Author:  Matthias Toussaint
// Created: Mon Okt 30 22:01:05 CET 2000
//----------------------------------------------------------------------
// Permission to use, copy, modify, and distribute this software and its
// documentation  for any  purpose and  without fee is  hereby  granted,
// provided  that below copyright notice appear  in all copies  and that
// both  that  copyright  notice and  this permission  notice  appear in
// supporting documentation.
// 
// This  file is  provided AS IS  with no  warranties  of any kind.  The
// author shall  have no liability  with respect  to the infringement of
// copyrights, trade  secrets  or any patents by  this file  or any part
// thereof.  In no event will the author be liable  for any lost revenue
// or profits or other special, indirect and consequential damages.
//----------------------------------------------------------------------
// (c) 2000 Matthias Toussaint
//======================================================================

#ifndef SIMPLECFG_HH
#define SIMPLECFG_HH

#include <qstring.h>
#include <qmap.h>
#include <qcolor.h>
#include <qtextstream.h>

// I _REALLY_ like writing documentation. Here documentation
// efficiently hides the code ...
//
class SimpleCfg;

class SimpleCfgGroup
{
  friend class SimpleCfg;
      
public:
  virtual ~SimpleCfgGroup();

  QString name() const { return groupName; }
  void remove( const QString & key );
  bool contains( const QString & key );
  void    setInt( const QString & key, int val );
  int     getInt( const QString & key, int def );
  void    setDouble( const QString & key, double val );
  double  getDouble( const QString & key, double def );
  void    setString( const QString & key, const QString & val );
  QString getString( const QString & key, const QString & def );
  void    setRGB( const QString & key, QRgb val );
  QRgb    getRGB( const QString & key, QRgb def );
  void    setBool( const QString & key, bool val );
  bool    getBool( const QString & key, bool def );
  inline QMap<QString,QString>::Iterator begin() { return map.begin(); }
  inline QMap<QString,QString>::Iterator end()   { return map.end(); }

protected:
  SimpleCfgGroup( const QString & name );
  
  void setName( const QString & name );
  void read( QTextStream & );
  void write( QTextStream & );
  
  QMap<QString,QString> map;
  QString               groupName;
  
};

class SimpleCfg
{
public:
  SimpleCfg( const QString & );
  virtual ~SimpleCfg();
  
  QString filename() const { return fname; }
  void setFilename( const QString & fn ) { fname = fn; }
  bool load();
  bool save();
  void clear();
  void removeEmpty();
  void remove( const QString & group, const QString & key );
  void remove( const QString & group );
  bool contains( const QString & group );
  bool contains( const QString & group, const QString & key );
  void add( const QString & group );
  void setInt( const QString &group, const QString & key, int val );
  int     getInt( const QString &group, const QString & key, int def );
  void    setDouble( const QString &group, const QString & key, double val );
  double  getDouble( const QString &group, const QString & key, double def );
  void    setString( const QString &group, const QString & key, const QString & val );
  QString getString( const QString &group, const QString & key, const QString & def );
  void    setRGB( const QString &group, const QString & key, QRgb val );
  QRgb    getRGB( const QString &group, const QString & key, QRgb def );
  void    setBool( const QString &group, const QString & key, bool val );
  bool    getBool( const QString &group, const QString & key, bool def );

  inline QMap<QString,SimpleCfgGroup *>::Iterator begin() { return map.begin(); }
  inline QMap<QString,SimpleCfgGroup *>::Iterator end()   { return map.end(); }
  
protected:
  QMap<QString,SimpleCfgGroup *> map;
  QString                        fname;
  QString                        curGroup;
  
};

#endif

Generated at Sat Nov 11 18:45:04 2000 for SimpleCfg by doxygen 1.0.0 written by Dimitri van Heesch, © 1997-1999