From bf35a4a76d486f6395da9cbefc42e565202c4de8 Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Tue, 4 Sep 2012 13:13:13 +0200 Subject: [PATCH] Moved YesNoNone to own header and implementation file. --- src/Makefile.am | 25 +++++++++++++++++ src/SquidConfig.h | 1 + src/YesNoNone.cc | 43 +++++++++++++++++++++++++++++ src/YesNoNone.h | 56 ++++++++++++++++++++++++++++++++++++++ src/cache_cf.cc | 12 -------- src/structs.h | 23 ---------------- src/tests/stub_cache_cf.cc | 1 + 7 files changed, 126 insertions(+), 35 deletions(-) create mode 100644 src/YesNoNone.cc create mode 100644 src/YesNoNone.h diff --git a/src/Makefile.am b/src/Makefile.am index 4afc3dd211..35e7aa126d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -268,6 +268,8 @@ squid_SOURCES = \ AsyncEngine.h \ cache_cf.h \ AuthReg.h \ + YesNoNone.h \ + YesNoNone.cc \ cache_cf.cc \ CacheDigest.h \ CacheDigest.cc \ @@ -1145,6 +1147,7 @@ tests_testHttpReply_SOURCES=\ log/access_log.h \ tests/stub_access_log.cc \ cache_cf.h \ + YesNoNone.h \ tests/stub_cache_cf.cc \ tests/stub_cache_manager.cc \ tests/stub_debug.cc \ @@ -1253,6 +1256,7 @@ tests_testACLMaxUserIP_SOURCES= \ log/access_log.h \ tests/stub_access_log.cc \ cache_cf.h \ + YesNoNone.h \ tests/stub_cache_cf.cc \ tests/stub_debug.cc \ tests/stub_DelayId.cc \ @@ -1365,6 +1369,8 @@ tests_testCacheManager_SOURCES = \ cache_manager.cc \ cache_cf.h \ AuthReg.h \ + YesNoNone.h \ + YesNoNone.cc \ cache_cf.cc \ CacheDigest.h \ CacheDigest.cc \ @@ -1653,6 +1659,7 @@ tests_testDiskIO_SOURCES = \ tests/stub_access_log.cc \ tests/stub_acl.cc \ cache_cf.h \ + YesNoNone.h \ tests/stub_cache_cf.cc \ tests/stub_cache_manager.cc \ tests/stub_client_db.cc \ @@ -1748,6 +1755,8 @@ tests_testEvent_SOURCES = \ CacheDigest.cc \ cache_cf.h \ AuthReg.h \ + YesNoNone.h \ + YesNoNone.cc \ cache_cf.cc \ cache_manager.cc \ carp.h \ @@ -1981,6 +1990,8 @@ tests_testEventLoop_SOURCES = \ cache_manager.cc \ cache_cf.h \ AuthReg.h \ + YesNoNone.h \ + YesNoNone.cc \ cache_cf.cc \ carp.h \ carp.cc \ @@ -2209,6 +2220,8 @@ tests_test_http_range_SOURCES = \ BodyPipe.cc \ cache_cf.h \ AuthReg.h \ + YesNoNone.h \ + YesNoNone.cc \ cache_cf.cc \ cache_manager.cc \ CacheDigest.h \ @@ -2440,6 +2453,7 @@ tests_testHttpParser_SOURCES = \ String.cc \ structs.h \ cache_cf.h \ + YesNoNone.h \ tests/stub_cache_cf.cc \ tests/stub_cache_manager.cc \ tests/stub_debug.cc \ @@ -2492,6 +2506,8 @@ tests_testHttpRequest_SOURCES = \ cache_manager.cc \ cache_cf.h \ AuthReg.h \ + YesNoNone.h \ + YesNoNone.cc \ cache_cf.cc \ debug.cc \ CacheDigest.h \ @@ -2769,6 +2785,7 @@ tests_testStore_SOURCES= \ tests/stub_access_log.cc \ tests/stub_acl.cc \ cache_cf.h \ + YesNoNone.h \ tests/stub_cache_cf.cc \ tests/stub_cache_manager.cc \ tests/stub_client_side_request.cc \ @@ -2867,6 +2884,7 @@ tests_testString_SOURCES = \ tests/testString.cc \ tests/testString.h \ cache_cf.h \ + YesNoNone.h \ tests/stub_cache_cf.cc \ tests/stub_cache_manager.cc \ tests/stub_debug.cc \ @@ -2980,6 +2998,7 @@ tests_testUfs_SOURCES = \ SwapDir.cc \ tests/stub_acl.cc \ cache_cf.h \ + YesNoNone.h \ tests/stub_cache_cf.cc \ tests/stub_helper.cc \ cbdata.cc \ @@ -3152,6 +3171,7 @@ tests_testRock_SOURCES = \ log/access_log.h \ tests/stub_access_log.cc \ cache_cf.h \ + YesNoNone.h \ tests/stub_cache_cf.cc \ tests/stub_cache_manager.cc \ client_db.h \ @@ -3288,6 +3308,7 @@ tests_testCoss_SOURCES = \ SwapDir.cc \ tests/stub_acl.cc \ cache_cf.h \ + YesNoNone.h \ tests/stub_cache_cf.cc \ tests/stub_helper.cc \ cbdata.cc \ @@ -3439,6 +3460,7 @@ tests_testNull_SOURCES = \ SwapDir.cc \ tests/stub_acl.cc \ cache_cf.h \ + YesNoNone.h \ tests/stub_cache_cf.cc \ tests/stub_helper.cc \ cbdata.cc \ @@ -3530,6 +3552,8 @@ tests_testURL_SOURCES = \ BodyPipe.cc \ cache_cf.h \ AuthReg.h \ + YesNoNone.h \ + YesNoNone.cc \ cache_cf.cc \ cache_manager.cc \ CacheDigest.h \ @@ -3765,6 +3789,7 @@ tests_testConfigParser_SOURCES = \ tests/testConfigParser.cc \ tests/testConfigParser.h \ cache_cf.h \ + YesNoNone.h \ tests/stub_cache_cf.cc \ tests/stub_cache_manager.cc \ tests/stub_debug.cc \ diff --git a/src/SquidConfig.h b/src/SquidConfig.h index 54c62b8d3d..88fc205471 100644 --- a/src/SquidConfig.h +++ b/src/SquidConfig.h @@ -39,6 +39,7 @@ #include "ip/Address.h" #include "RefCount.h" #include "structs.h" +#include "YesNoNone.h" class acl_access; class acl_deny_info_list; diff --git a/src/YesNoNone.cc b/src/YesNoNone.cc new file mode 100644 index 0000000000..ec977a9236 --- /dev/null +++ b/src/YesNoNone.cc @@ -0,0 +1,43 @@ +/* + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * 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, USA. + * + */ + +#include "squid.h" +#include "YesNoNone.h" + +YesNoNone::operator void*() const +{ + assert(option != 0); // must call configure() first + return option > 0 ? (void*)this : NULL; +} + +void +YesNoNone::configure(bool beSet) +{ + option = beSet ? +1 : -1; +} diff --git a/src/YesNoNone.h b/src/YesNoNone.h new file mode 100644 index 0000000000..17965556fa --- /dev/null +++ b/src/YesNoNone.h @@ -0,0 +1,56 @@ +#ifndef SQUID_YESNONONE_H_ +#define SQUID_YESNONONE_H_ +/* + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * 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, USA. + * + */ + +/// Used for boolean enabled/disabled options with complex default logic. +/// Allows Squid to compute the right default after configuration. +/// Checks that not-yet-defined option values are not used. +class YesNoNone +{ +// TODO: generalize to non-boolean option types +public: + YesNoNone(): option(0) {} + + /// returns true iff enabled; asserts if the option has not been configured + operator void *() const; // TODO: use a fancy/safer version of the operator + + /// enables or disables the option; + void configure(bool beSet); + + /// whether the option was enabled or disabled, by user or Squid + bool configured() const { return option != 0; } + +private: + enum { optUnspecified = -1, optDisabled = 0, optEnabled = 1 }; + int option; ///< configured value or zero +}; + + +#endif /* SQUID_YESNONONE_H_ */ diff --git a/src/cache_cf.cc b/src/cache_cf.cc index c46c505ce8..6810248c3f 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -3295,18 +3295,6 @@ dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * storeAppendPrintf(entry, "\n"); } -void -YesNoNone::configure(bool beSet) -{ - option = beSet ? +1 : -1; -} - -YesNoNone::operator void*() const -{ - assert(option != 0); // must call configure() first - return option > 0 ? (void*)this : NULL; -} - inline void free_YesNoNone(YesNoNone *) { diff --git a/src/structs.h b/src/structs.h index 804a03a59b..26df25c2f6 100644 --- a/src/structs.h +++ b/src/structs.h @@ -146,29 +146,6 @@ struct PortCfg; } class SwapDir; -/// Used for boolean enabled/disabled options with complex default logic. -/// Allows Squid to compute the right default after configuration. -/// Checks that not-yet-defined option values are not used. -class YesNoNone -{ -// TODO: generalize to non-boolean option types -public: - YesNoNone(): option(0) {} - - /// returns true iff enabled; asserts if the option has not been configured - operator void *() const; // TODO: use a fancy/safer version of the operator - - /// enables or disables the option; - void configure(bool beSet); - - /// whether the option was enabled or disabled, by user or Squid - bool configured() const { return option != 0; } - -private: - enum { optUnspecified = -1, optDisabled = 0, optEnabled = 1 }; - int option; ///< configured value or zero -}; - struct SquidConfig2 { struct { int enable_purge; diff --git a/src/tests/stub_cache_cf.cc b/src/tests/stub_cache_cf.cc index cdb3d80c3a..699ee23e02 100644 --- a/src/tests/stub_cache_cf.cc +++ b/src/tests/stub_cache_cf.cc @@ -33,6 +33,7 @@ #include "squid.h" #include "ConfigParser.h" #include "wordlist.h" +#include "YesNoNone.h" #define STUB_API "cache_cf.cc" #include "tests/STUB.h" -- 2.47.3