Changeset 264


Ignore:
Timestamp:
Apr 30, 2007, 11:54:25 PM (14 years ago)
Author:
Peter Johansson
Message:

turned Configuration class into a singleton

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/svndigest.cc

    r235 r264  
    6060
    6161  // Reading configuration file
    62   Configuration* config = NULL;
     62  Configuration* config = Configuration::instance();
    6363  if (node_exist(option->config_file())) {
    6464    std::ifstream is(option->config_file().c_str());
     
    6969      exit(-1);
    7070    }
    71     config = new Configuration(is);
     71    config->load(is);
    7272    is.close();
    7373  }
    7474  else
    75     config = new Configuration;
     75    config->load();
    7676  assert(config);
    7777 
  • trunk/lib/Configuration.cc

    r229 r264  
    3535namespace svndigest{
    3636
     37  Configuration* Configuration::instance_=NULL;
     38
     39
    3740  Configuration::Configuration(void)
     41  {
     42  }
     43
     44
     45  void Configuration::load(void)
    3846  {
    3947    set_default();
     
    4149
    4250
    43   Configuration::Configuration(std::istream& is)
     51  void Configuration::load(std::istream& is)
    4452  {
    4553    assert(is.good());
     
    6674      }
    6775    }
     76  }
     77
     78
     79  Configuration* Configuration::instance(void)
     80  {
     81    if (!instance_)
     82      instance_ = new Configuration;
     83    return instance_;
    6884  }
    6985
  • trunk/lib/Configuration.h

    r229 r264  
    2525*/
    2626
    27 #include <fstream>
     27#include <iostream>
    2828#include <map>
    2929#include <string>
     
    3535  {
    3636  public:
    37     ///
    38     /// Creates a Config object with default settings.
    39     ///
    40     /// @brief Default Constructor
    41     ///
    42     Configuration(void);
     37    static Configuration* instance(void);
    4338
    4439    ///
    45     /// @brief Stream Constructor
     40    /// @brief load deafult configuration
    4641    ///
    47     Configuration(std::istream&);
     42    void load(void);
     43
     44    ///
     45    /// @brief load configuration from stream
     46    ///
     47    void load(std::istream&);
    4848
    4949    ///
     
    5454
    5555  private:
     56    ///
     57    /// Creates a Config object with default settings.
     58    ///
     59    /// @brief Default Constructor
     60    ///
     61    Configuration(void);
     62
     63    void clear(void);
     64
    5665    void set_default(void);
     66
     67    static Configuration* instance_;
    5768
    5869    std::map<std::string, std::string> copyright_alias_;
Note: See TracChangeset for help on using the changeset viewer.