first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / library / loggers / filter_set.h
1 #ifndef FILTER_SET_CLASS
2 #define FILTER_SET_CLASS
3
4 /*****************************************************************************\
5 *                                                                             *
6 *  Name   : filter_set
7 *  Author : Chris Koeritz
8 *                                                                             *
9 *******************************************************************************
10 * Copyright (c) 1996-$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 <basis/astring.h>
19 #include <basis/definitions.h>
20 #include <basis/mutex.h>
21 #include <structures/set.h>
22
23 namespace loggers {
24
25 //! A simple object that wraps a templated set of ints.
26 class filter_set : public structures::set<int>, public virtual basis::root_object
27 {
28 public:
29   filter_set() {}
30     //!< Constructs an empty set of filters.
31
32   virtual ~filter_set() {}
33
34   filter_set(const structures::set<int> &to_copy) : structures::set<int>(to_copy) {}
35     //!< Constructs a copy of the "to_copy" array.
36
37   DEFINE_CLASS_NAME("filter_set");
38
39   //! Adds a member to the filter set.
40   /*! The filter set is used to check all extended filter values passed to
41   log and print.  if the special filters of ALWAYS_PRINT or NEVER_PRINT are
42   added, then either everything will be logged or nothing will be. */
43   virtual void add_filter(int new_filter) {
44     basis::auto_synchronizer l(c_lock);
45     add(new_filter);
46   }
47
48   //! Removes a member from the filter set.
49   virtual void remove_filter(int old_filter) {
50     basis::auto_synchronizer l(c_lock);
51     remove(old_filter);
52   }
53
54   //! Returns true if the "filter_to_check" is a member of the filter set.
55   /*! If "filter_to_check" is ALWAYS_PRINT, this always returns true.  If
56   the value is NEVER_PRINT, false is always returned. */
57   virtual bool member(int filter_to_check) {
58      if (filter_to_check == basis::ALWAYS_PRINT) return true;
59      if (filter_to_check == basis::NEVER_PRINT) return false;
60      return structures::set<int>::member(filter_to_check);
61   }
62
63   //! Resets the filter set to be empty.
64   virtual void clear_filters() {
65     basis::auto_synchronizer l(c_lock);
66     clear();
67   }
68
69 private:
70   basis::mutex c_lock;
71 };
72
73 }  // namespace.
74
75 #endif
76