casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PlotMSWatchedParameters.h
Go to the documentation of this file.
1 //# PlotMSWatchedParameters.h: Classes for watched/synchronized parameters.
2 //# Copyright (C) 2009
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef PLOTMSWATCHEDPARAMETERS_H_
28 #define PLOTMSWATCHEDPARAMETERS_H_
29 
30 #include <casa/BasicSL/String.h>
31 
32 #include <vector>
33 
34 namespace casa {
35 
36 //# Forward Declarations
37 class PlotMSWatchedParameters;
38 
39 
40 // Interface for classes that wish to be notified when PlotMSWatchedParameters
41 // have changed. This watching system is used to keep the different aspects of
42 // PlotMS synchronized with parameters that could potentially come from many
43 // different sources.
45 public:
46  // Constructor.
48 
49  // Destructor.
51 
52 
53  // This method is called whenever the watched parameters have been changed.
54  // This can either happen immediately after any change or, if notification
55  // has been held via PlotMSWatchedParameters::holdNotification, when
56  // notification is released via
57  // PlotMSWatchedParameters::releaseNotification. If this watcher is the
58  // watcher that was holding notifications, this method is NOT called.
59  // The updateFlag parameter lets the watcher know which categories the
60  // changes were in.
61  virtual void parametersHaveChanged(const PlotMSWatchedParameters& params,
62  int updateFlag) = 0;
63 };
64 
65 
66 // Abstract class for parameters that may be watched by one or more interested
67 // classes. Any subclass is assumed to have different properties in one or
68 // more of the update categories defined different update flag values which
69 // must be registered with the public static methods in
70 // PlotMSWatchedParameters. Using this system, any classes watching the
71 // parameters for changes can be notified which categories the changes occurred
72 // in.
74 public:
75  // Static //
76 
77  // "Base", or no updates, flag.
78  static const int NO_UPDATES;
79 
80 
81  // Registers an update flag with the given name (if it is not already
82  // registered) and returns its flag value.
83  static int REGISTER_UPDATE_FLAG(const casacore::String& name);
84 
85  // Unregisters the given update flag, if it is registered.
86  // <group>
87  static void UNREGISTER_UPDATE_FLAG(const casacore::String& name);
88  static void UNREGISTER_UPDATE_FLAG(int flag);
89  // </group>
90 
91  // Converts between an update flag's name and value, if valid.
92  // <group>
93  static int UPDATE_FLAG(const casacore::String& name);
94  static casacore::String UPDATE_FLAG(int flag);
95  // </group>
96 
97  // Returns all registered update flags.
98  // <group>
99  static std::vector<int> UPDATE_FLAGS();
100  static std::vector<casacore::String> UPDATE_FLAG_NAMES();
101  // </group>
102 
103  // Returns all registered update flags as one or-ed value.
104  static int ALL_UPDATE_FLAGS();
105 
106  // Returns all registered update flags that were turned on in the given
107  // flags value.
108  // <group>
109  static std::vector<int> UPDATE_FLAGS(int value);
110  static std::vector<casacore::String> UPDATE_FLAG_NAMES(int value);
111  // </group>
112 
113 
114  // Non-Static //
115 
116  // Constructor.
118 
119  // Destructor.
120  virtual ~PlotMSWatchedParameters();
121 
122 
123  // Adds/Removes the given watcher for this PlotMSParameters.
124  // <group>
125  void addWatcher(PlotMSParametersWatcher* watcher);
126  void removeWatcher(PlotMSParametersWatcher* watcher);
127  // </group>
128 
129  // Holds update notifications for any registered watchers. Notifications
130  // will not be sent out until releaseNotification() is called. If a
131  // non-NULL watcher is given, it will be excluded from notifications when
132  // releaseNotification() is called.
133  void holdNotification(PlotMSParametersWatcher* updater = NULL);
134 
135  // Releases update notification; notifies all watchers of an update except
136  // for the one (if any) that called holdNotification.
137  void releaseNotification();
138 
139  // Equality operators.
140  // <group>
141  virtual bool operator==(const PlotMSWatchedParameters& other) const {
142  return equals(other, ALL_UPDATE_FLAGS()); }
143  virtual bool operator!=(const PlotMSWatchedParameters& other) const {
144  return !(operator==(other)); }
145  // </group>
146 
147 
148  // ABSTRACT METHODS //
149 
150  // Returns true if this PlotMSParameters equals the other, in the given
151  // update categories flag.
152  virtual bool equals(const PlotMSWatchedParameters& other,
153  int updateFlags) const = 0;
154 
155 protected:
156  // Returns the current update flag.
157  int currentUpdateFlag() const;
158 
159  // Provides access to children to indicate whether the given update flag
160  // should be turned on or off. This should be used by setter functions to
161  // classify the changes appropriately. If update notifications are NOT
162  // being held, any watchers will immediately be notified of the change.
163  // <group>
164  void updateFlag(int updateFlag, bool on = true);
165  void updateFlag(const casacore::String& updateFlagName, bool on = true);
166  // </group>
167 
168  // Provides access to children to indicate which update flags are on.
169  // The given value should be a bit-wise or of one or more UpdateFlag
170  // enum values.
171  void updateFlags(int updateFlags);
172 
173 private:
174  // Current update flags.
176 
177  // Watchers.
178  std::vector<PlotMSParametersWatcher*> itsWatchers_;
179 
180  // Flag for whether notifications are currently being held or not.
182 
183  // Watcher that is currently holding notifications, or NULL for none.
185 
186 
187  // Static //
188 
189  // Registered flags.
190  static std::vector<int> FLAGS;
191 
192  // Registered flag names.
193  static std::vector<casacore::String> NAMES;
194 };
195 
196 }
197 
198 #endif /* PLOTMSWATCHEDPARAMETERS_H_ */
static void UNREGISTER_UPDATE_FLAG(const casacore::String &name)
Unregisters the given update flag, if it is registered.
static std::vector< int > FLAGS
Static //.
static std::vector< casacore::String > NAMES
Registered flag names.
virtual ~PlotMSParametersWatcher()
Destructor.
void addWatcher(PlotMSParametersWatcher *watcher)
Adds/Removes the given watcher for this PlotMSParameters.
virtual bool equals(const PlotMSWatchedParameters &other, int updateFlags) const =0
ABSTRACT METHODS //.
static std::vector< casacore::String > UPDATE_FLAG_NAMES()
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
void releaseNotification()
Releases update notification; notifies all watchers of an update except for the one (if any) that cal...
Abstract class for parameters that may be watched by one or more interested classes.
virtual void parametersHaveChanged(const PlotMSWatchedParameters &params, int updateFlag)=0
This method is called whenever the watched parameters have been changed.
void holdNotification(PlotMSParametersWatcher *updater=NULL)
Holds update notifications for any registered watchers.
int currentUpdateFlag() const
Returns the current update flag.
void updateFlags(int updateFlags)
Provides access to children to indicate which update flags are on.
static int ALL_UPDATE_FLAGS()
Returns all registered update flags as one or-ed value.
PlotMSWatchedParameters()
Non-Static //.
virtual ~PlotMSWatchedParameters()
Destructor.
virtual bool operator!=(const PlotMSWatchedParameters &other) const
PlotMSParametersWatcher * itsUpdater_
Watcher that is currently holding notifications, or NULL for none.
static std::vector< int > UPDATE_FLAGS()
Returns all registered update flags.
void removeWatcher(PlotMSParametersWatcher *watcher)
static int REGISTER_UPDATE_FLAG(const casacore::String &name)
Registers an update flag with the given name (if it is not already registered) and returns its flag v...
static const int NO_UPDATES
Static //.
static int UPDATE_FLAG(const casacore::String &name)
Converts between an update flag&#39;s name and value, if valid.
int itsUpdateFlags_
Current update flags.
Interface for classes that wish to be notified when PlotMSWatchedParameters have changed.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
bool isHolding_
Flag for whether notifications are currently being held or not.
std::vector< PlotMSParametersWatcher * > itsWatchers_
Watchers.
virtual bool operator==(const PlotMSWatchedParameters &other) const
Equality operators.
void updateFlag(int updateFlag, bool on=true)
Provides access to children to indicate whether the given update flag should be turned on or off...
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.