From ead1593107b4d4c390173076b3749e5ee2a3c666 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Mon, 10 Mar 2003 08:50:16 +0000 Subject: [PATCH] 2003-03-10 Robert Collins * Exception.h: Add a logic error exception id. * Makefile.am: Add new sources. * UserSettings.cc: New file. * UserSettings.h: New file. * UserSetting.cc: New file. * UserSetting.h: New file. * site.h: Add a SiteSetting as example of a UserSetting. * site.cc (ChosenSites): Add a instance of SiteSetting to trigger registration. --- ChangeLog | 11 ++++++++ Exception.h | 1 + Makefile.am | 4 +++ Makefile.in | 16 +++++++++--- UserSetting.cc | 47 ++++++++++++++++++++++++++++++++++ UserSetting.h | 27 ++++++++++++++++++++ UserSettings.cc | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ UserSettings.h | 37 +++++++++++++++++++++++++++ site.cc | 3 +++ site.h | 6 +++++ 10 files changed, 216 insertions(+), 4 deletions(-) create mode 100644 UserSetting.cc create mode 100644 UserSetting.h create mode 100644 UserSettings.cc create mode 100644 UserSettings.h diff --git a/ChangeLog b/ChangeLog index 18702e64..1994db38 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2003-03-10 Robert Collins + + * Exception.h: Add a logic error exception id. + * Makefile.am: Add new sources. + * UserSettings.cc: New file. + * UserSettings.h: New file. + * UserSetting.cc: New file. + * UserSetting.h: New file. + * site.h: Add a SiteSetting as example of a UserSetting. + * site.cc (ChosenSites): Add a instance of SiteSetting to trigger registration. + 2003-03-10 Robert Collins * compress_bz.cc (compress_bz::read): adjust incorrect assignment of lasterr. diff --git a/Exception.h b/Exception.h index 3fb7a707..4ace3b39 100644 --- a/Exception.h +++ b/Exception.h @@ -39,5 +39,6 @@ private: // Where should these live? #define APPERR_CORRUPT_PACKAGE 1 #define APPERR_IO_ERROR 2 +#define APPERR_LOGIC_ERROR 3 #endif /* _EXCEPTION_H_ */ diff --git a/Makefile.am b/Makefile.am index 8dc63ad6..6b16ea95 100644 --- a/Makefile.am +++ b/Makefile.am @@ -266,6 +266,10 @@ setup_SOURCES = \ String++.h \ threebar.cc \ threebar.h \ + UserSetting.cc \ + UserSetting.h \ + UserSettings.cc \ + UserSettings.h \ version.cc \ version.h \ win32.cc \ diff --git a/Makefile.in b/Makefile.in index 1a243701..b858bebe 100644 --- a/Makefile.in +++ b/Makefile.in @@ -409,6 +409,10 @@ setup_SOURCES = \ String++.h \ threebar.cc \ threebar.h \ + UserSetting.cc \ + UserSetting.h \ + UserSettings.cc \ + UserSettings.h \ version.cc \ version.h \ win32.cc \ @@ -476,7 +480,8 @@ am__setup_SOURCES_DIST = AntiVirus.cc AntiVirus.h archive.cc archive.h \ root.h ScanFindVisitor.cc ScanFindVisitor.h script.cc script.h \ setup_version.c simpsock.cc simpsock.h site.cc site.h source.cc \ source.h splash.cc splash.h state.cc state.h String++.cc \ - String++.h threebar.cc threebar.h version.cc version.h win32.cc \ + String++.h threebar.cc threebar.h UserSetting.cc UserSetting.h \ + UserSettings.cc UserSettings.h version.cc version.h win32.cc \ win32.h window.cc window.h io_stream_rsync.cc io_stream_rsync.h @ENABLERSYNC_TRUE@am__objects_2 = io_stream_rsync.$(OBJEXT) @ENABLERSYNC_FALSE@am__objects_2 = @@ -508,8 +513,8 @@ am_setup_OBJECTS = AntiVirus.$(OBJEXT) archive.$(OBJEXT) \ script.$(OBJEXT) setup_version.$(OBJEXT) simpsock.$(OBJEXT) \ site.$(OBJEXT) source.$(OBJEXT) splash.$(OBJEXT) \ state.$(OBJEXT) String++.$(OBJEXT) threebar.$(OBJEXT) \ - version.$(OBJEXT) win32.$(OBJEXT) window.$(OBJEXT) \ - $(am__objects_2) + UserSetting.$(OBJEXT) UserSettings.$(OBJEXT) version.$(OBJEXT) \ + win32.$(OBJEXT) window.$(OBJEXT) $(am__objects_2) setup_OBJECTS = $(am_setup_OBJECTS) setup_DEPENDENCIES = res.o zlib/libzcygw.a bz2lib/libbz2.a \ libgetopt++/libgetopt++.la @@ -531,7 +536,8 @@ am__depfiles_maybe = depfiles @AMDEP_TRUE@ ./$(DEPDIR)/PickPackageLine.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/PickView.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/ScanFindVisitor.Po \ -@AMDEP_TRUE@ ./$(DEPDIR)/String++.Po ./$(DEPDIR)/archive.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/String++.Po ./$(DEPDIR)/UserSetting.Po \ +@AMDEP_TRUE@ ./$(DEPDIR)/UserSettings.Po ./$(DEPDIR)/archive.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/archive_tar.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/archive_tar_file.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/autoload.Po ./$(DEPDIR)/category.Po \ @@ -656,6 +662,8 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PickView.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ScanFindVisitor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/String++.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UserSetting.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UserSettings.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/archive.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/archive_tar.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/archive_tar_file.Po@am__quote@ diff --git a/UserSetting.cc b/UserSetting.cc new file mode 100644 index 00000000..8aecb478 --- /dev/null +++ b/UserSetting.cc @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2003, Robert Collins + * + * 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. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif + +#include "site.h" +#include "win32.h" +#include +#include +#include +#include +#include + +#include "LogSingleton.h" +#include "io_stream.h" + +#include "port.h" +#include "Exception.h" +#include "UserSetting.h" +#include "UserSettings.h" + +using namespace std; + +UserSetting::UserSetting() +{ + UserSettings::Instance().registerSetting(*this); +} + +UserSetting::~UserSetting() +{ + UserSettings::Instance().deRegisterSetting(*this); +} diff --git a/UserSetting.h b/UserSetting.h new file mode 100644 index 00000000..3db09e04 --- /dev/null +++ b/UserSetting.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2003, Robert Collins. + * + * 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. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +/* A user-related settings */ + +#ifndef _USERSETTING_H_ +#define _USERSETTING_H_ + +class UserSetting { + public: + UserSetting(); + virtual ~UserSetting(); +}; + +#endif /* _USERSETTING_H_ */ diff --git a/UserSettings.cc b/UserSettings.cc new file mode 100644 index 00000000..eae5fa4d --- /dev/null +++ b/UserSettings.cc @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2003, Robert Collins + * + * 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. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +#if 0 +static const char *cvsid = + "\n%%% $Id$\n"; +#endif + +#include "site.h" +#include "win32.h" +#include +#include +#include +#include +#include + +#include "LogSingleton.h" +#include "io_stream.h" + +#include "port.h" +#include "Exception.h" +#include "UserSettings.h" + +using namespace std; + +UserSettings & +UserSettings::Instance() +{ + return Instance_; + if (Instance_.inited != 42) + Instance_.init (); + return Instance_; +} + +void +UserSettings::init () +{ + inited = 42; +} + +UserSettings UserSettings::Instance_; + +void +UserSettings::registerSetting(UserSetting &aSetting) +{ + settings.push_back(&aSetting); +} + +void +UserSettings::deRegisterSetting(UserSetting &aSetting) +{ + Settings::iterator i = find(settings.begin(), settings.end(), &aSetting); + if (i == settings.end()) + throw new Exception ("__LINE__ __FILE__", String ("Attempt to deregister non registered setting!"), APPERR_LOGIC_ERROR); + settings.erase(i); +} diff --git a/UserSettings.h b/UserSettings.h new file mode 100644 index 00000000..e02e9a48 --- /dev/null +++ b/UserSettings.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2003, Robert Collins. + * + * 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. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +/* A collection of user-related settings */ + +#ifndef _USERSETTINGS_H_ +#define _USERSETTINGS_H_ + +#include + +class UserSetting; +class UserSettings { + public: + static UserSettings &Instance(); + void registerSetting(UserSetting &); + void deRegisterSetting(UserSetting &); + private: + static UserSettings Instance_; + typedef std::vector Settings; + void init(); + int inited; + Settings settings; +}; + +#endif /* _USERSETTINGS_H_ */ diff --git a/site.cc b/site.cc index 43961a62..8dc0c1b0 100644 --- a/site.cc +++ b/site.cc @@ -54,6 +54,9 @@ SiteList all_site_list; StringOption SiteOption("", 's', "site", "Download site"); +/* XXX make into a singleton? */ +static SiteSetting ChosenSites; + void site_list_type::init (String const &newurl) { diff --git a/site.h b/site.h index 6866c77e..c0028d6e 100644 --- a/site.h +++ b/site.h @@ -82,4 +82,10 @@ extern SiteList all_site_list; void save_site_url (); +#include "UserSetting.h" +class SiteSetting : public UserSetting +{ + public: +}; + #endif /* _SITE_H_ */ -- 2.43.5