configlet.h

Go to the documentation of this file.
00001 #ifndef CONFIGLET_CLASS
00002 #define CONFIGLET_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : configlet                                                         *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2001-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "configurator.h"
00019 
00020 #include <basis/astring.h>
00021 #include <basis/contracts.h>
00022 
00023 namespace configuration {
00024 
00026 
00032 class configlet : public virtual basis::root_object
00033 {
00034 public:
00035   configlet(const basis::astring &section, const basis::astring &entry);
00037   configlet(const configlet &to_copy);
00038 
00039   virtual ~configlet();
00040 
00041   DEFINE_CLASS_NAME("configlet");
00042 
00043   configlet &operator =(const configlet &to_copy);
00044 
00045   const basis::astring &section() const;
00047   const basis::astring &entry() const;
00049 
00050   void section(const basis::astring &new_section) const;
00052   void entry(const basis::astring &new_entry) const;
00054 
00055   virtual bool load(configurator &config) = 0;
00057 
00063   virtual bool store(configurator &config) const = 0;
00065 
00066   virtual configlet *duplicate() const = 0;
00068 
00070 private:
00071   basis::astring *_section;  
00072   basis::astring *_entry;  
00073 };
00074 
00076 
00078 
00084 class string_configlet : public configlet
00085 {
00086 public:
00087   string_configlet(const basis::astring &section, const basis::astring &entry,
00088           const basis::astring &current_value = basis::astring::empty_string(),
00089           const basis::astring &default_value = basis::astring::empty_string());
00090   string_configlet(const string_configlet &to_copy);
00091   virtual ~string_configlet();
00092 
00093   string_configlet &operator =(const string_configlet &to_copy);
00094 
00095   const basis::astring &current_value() const;
00096   const basis::astring &default_value() const;
00097 
00098   void current_value(const basis::astring &new_current);
00099   void default_value(const basis::astring &new_default);
00100   
00101   virtual bool load(configurator &config);
00102   virtual bool store(configurator &config) const;
00103 
00104   configlet *duplicate() const;
00105 
00106 private:
00107   basis::astring *_current;
00108   basis::astring *_default;
00109 };
00110 
00112 
00114 
00115 class int_configlet : public configlet
00116 {
00117 public:
00118   int_configlet(const basis::astring &section, const basis::astring &entry,
00119           int current_value = 0, int default_value = 0);
00120   virtual ~int_configlet();
00121 
00122   int current_value() const { return _current; }
00123 
00124   virtual void current_value(int new_current);
00126 
00127   int default_value() const { return _default; }
00128   void default_value(int new_default) { _default = new_default; }
00129 
00130   virtual bool load(configurator &config);
00131   virtual bool store(configurator &config) const;
00132 
00133   configlet *duplicate() const;
00134 
00135 private:
00136   int _current;
00137   int _default;
00138 };
00139 
00141 
00143 
00150 class bounded_int_configlet : public int_configlet
00151 {
00152 public:
00153   bounded_int_configlet(const basis::astring &section, const basis::astring &entry,
00154           int current_value, int default_value, int minimum, int maximum);
00155   virtual ~bounded_int_configlet();
00156 
00157   virtual void current_value(int new_current);
00158 
00159   int minimum() const { return _minimum; }
00160   int maximum() const { return _maximum; }
00161   
00162   void minimum(int new_min) { _minimum = new_min; }
00163   void maximum(int new_max) { _maximum = new_max; }
00164 
00165   configlet *duplicate() const;
00166 
00167 private:
00168   int _minimum;
00169   int _maximum;
00170 };
00171 
00172 } //namespace.
00173 
00174 #endif
00175 
Generated on Sat Jan 28 04:22:17 2012 for hoople2 project by  doxygen 1.6.3