first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / library / configuration / config_watcher.h
1 #ifndef CONFIG_WATCHER_CLASS
2 #define CONFIG_WATCHER_CLASS
3
4 /*****************************************************************************\
5 *                                                                             *
6 *  Name   : config_watcher                                                    *
7 *  Author : Chris Koeritz                                                     *
8 *                                                                             *
9 *******************************************************************************
10 * Copyright (c) 2008-$now By Author.  This program is free software; you can  *
11 * redistribute it and/or modify it under the terms of the GNU General Public  *
12 * License as published by the Free Software Foundation; either version 2 of   *
13 * the License or (at your option) any later version.  This is online at:      *
14 *     http://www.fsf.org/copyleft/gpl.html                                    *
15 * Please send any updates to: fred@gruntose.com                               *
16 \*****************************************************************************/
17
18 #include "configurator.h"
19 #include "table_configurator.h"
20
21 #include <basis/contracts.h>
22 #include <structures/set.h>
23
24 namespace configuration {
25
26 //! an object that watches the contents of a configurator for changes.
27 /*!
28   when given a configurator object to check, this will initially build an
29   exact copy of the contents seen.  when asked to look for changes to the
30   configurator, the previous version is compared with the current state and
31   any changed sections are reported.
32 */
33
34 class config_watcher
35 {
36 public:
37   config_watcher(configurator &to_watch);
38     //!< watches the configurator for changes and tracks them.
39     /*!< "to_watch" must exist for lifetime of this class. */
40
41   virtual ~config_watcher();
42
43   DEFINE_CLASS_NAME("config_watcher");
44
45   bool rescan();
46     //!< updates the configurator snapshot and enables the comparison methods.
47     /*!< call this before testing the changed() method. */
48
49   // these lists describe how sections have changed, if at all.
50   structures::string_set new_sections() const;
51   structures::string_set deleted_sections() const;
52   structures::string_set changed_sections() const;
53
54   // methods for comparing changes within sections in the config.
55   structures::string_set new_items(const basis::astring &section_name);
56   structures::string_set deleted_items(const basis::astring &section_name);
57   structures::string_set changed_items(const basis::astring &section_name);
58
59 private:
60   configurator &_watching;  //!< the config object we examine.
61   table_configurator *_current_config;  //!< most current records.
62   table_configurator *_previous_config;  //!< records we saw earlier.
63 };
64
65 } //namespace.
66
67 #endif
68