casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Notice.h
Go to the documentation of this file.
1 //# Notice.h: Classes for manipulating notices
2 //# Copyright (C) 1993,1994,1995,1999,2002
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 
28 #ifndef CASA_NOTICE_H
29 #define CASA_NOTICE_H
30 
31 #include <casacore/casa/aips.h>
33 
34 namespace casacore { //# NAMESPACE CASACORE - BEGIN
35 
36 //# Forward Declaration
37 class NoticeTarget;
38 
39 // <summary>abstract base class for notices</summary>
40 // <use visibility=export>
41 // <reviewed reviewer="Friso Olnon" date="1995/03/16" tests="" demos="">
42 // </reviewed>
43 
44 // <synopsis>
45 // A <src>Notice</src> is the piece of information passed around
46 // between a <src>NoticeSource</src> and a <src>NoticeTarget</src>. This
47 // abstract base class is only a skeleton intended to be derived from. It
48 // does not contain any relevant information -- that must be added by
49 // the derived classes --, but it enforces derived classes to implement
50 // the comparison operator <src>==</src> and the function
51 // <src>type()</src>.
52 // </synopsis>
53 
54 // <example>
55 // <linkto class=ListNotice>ListNotice</linkto>, derived from
56 // <src>Notice</src>, is the notification which is passed between
57 // <linkto class=List>List</linkto> and
58 // <linkto class=ListIter>ListIter</linkto>
59 // to keep cursors and container in sync.
60 // </example>
61 
62 class Notice {
63 public:
64  Notice() {}
65 
66  virtual ~Notice();
67 
68  // Return the identification number of the <src>Notice</src> type.
69  virtual uInt type() const = 0;
70 
71  // Compare two <src>Notice</src>s.
72  virtual int operator==(const Notice &) const = 0;
73 };
74 
75 // <summary>base class for notice originators</summary>
76 // <use visibility=export>
77 // <reviewed reviewer="Friso Olnon" date="1995/03/16" tests="" demos="">
78 // </reviewed>
79 
80 // <synopsis>
81 // A <src>NoticeSource</src> maintains a list of all of the
82 // <src>NoticeTarget</src>s which are interested in <src>Notice</src>s
83 // from this <src>NoticeSource</src>. Its member function
84 // <src>notify()</src> sends the specified <src>Notice</src> to all the
85 // <src>NoticeTarget</src>s in the list.
86 //
87 // Classes which have many other dependent objects which need to be
88 // updated, should derive from this class.
89 // </synopsis>
90 
91 // <example>
92 // <linkto class=List>List</linkto>, the linked list class, is
93 // derived from <src>NoticeSource</src>. It mainly contains status
94 // information; all the manipulation functions are located in the
95 // <linkto class=ListIter>ListIter</linkto> classes. The linked
96 // list and its iterators communicate with each other via the notice
97 // system. <src>List</src> does not provide any further notice
98 // functionality; everything is taken care of by its base class
99 // <src>NoticeSource</src>.
100 // </example>
101 
103 public:
104  friend class NoticeTarget;
105 
107 
108  virtual ~NoticeSource();
109 
110  // Sends the <src>note</src> to all <src>NoticeTarget</src>s in the
111  // target list.
112  void notify(const Notice & note);
113 
114 private:
115  Link<NoticeTarget*> *curIters; //# Do not Delete
116 
118 };
119 
120 // <summary>abstract base class for notice receptors</summary>
121 // <use visibility=export>
122 // <reviewed reviewer="Friso Olnon" date="1995/03/16" tests="" demos="">
123 // </reviewed>
124 
125 // <synopsis>
126 // A <src>NoticeTarget</src> receives the <src>Notice</src>s from the
127 // <src>NoticeSource</src> to which it is linked. A target can only be
128 // linked to one source.
129 //
130 // Classes which are dependent upon a particular
131 // <src>NoticeSource</src> should derive from this class.
132 // </synopsis>
133 
134 // <example>
135 // <linkto class=ListIter>ListIter</linkto> and its parent class
136 // <linkto class=ConstListIter>ConstListIter</linkto> are the iterators or
137 // "dynamic" cursors in the linked <linkto class=List>List</linkto>. They
138 // are derived from <src>NoticeTarget</src>, and the notice system ensures
139 // that multiple cursors are updated as elements are added and removed from
140 // the list, according to the following scheme:
141 // <ol>
142 // <li> An iterator changes something to the underlying list.
143 // <li> The iterator creates a <linkto class=ListNotice>ListNotice</linkto>
144 // containing all the necessary information about the change.
145 // <li> The iterator passes the notice to the <src>NoticeSource</src>
146 // <linkto class=List>List</linkto>.
147 // <li> The list relays the notice to all other iterators operating on the
148 // list (kept in the "target list").
149 // <li> Every iterator catches the notice and changes its state accordingly.
150 // </ol>
151 // </example>
152 
154 public:
155  friend class NoticeSource;
156 
157  // Destructs this <src>NoticeTarget</src>.
158  virtual ~NoticeTarget();
159 
160  // Returns a boolean value telling whether this <src>NoticeTarget</src>
161  // is still "valid".
162  Bool isValid() const {return valid;}
163 
164  // Returns a boolean value telling whether this <src>NoticeTarget</src>
165  // is still attached to a <src>NoticeSource</src> or not.
166  Bool isAttached() const {return ilink ? True : False;}
167 
168  // Makes the current <src>NoticeTarget</src> "invalid".
169  void invalidate() {valid = False;}
170 
171  // Hook through which <src>NoticeTarget</src>s are notified
172  // (by <src>NoticeSource</src>s).
173  virtual void notify(const Notice &) = 0;
174 
175 protected:
176 
180 
181  // Creates an unlinked, "invalid" <src>NoticeTarget</src>. An invalid
182  // <src>NoticeTarget</src> does not occur in the target list of any
183  // <src>NoticeSource</src>.
185 
186  // Creates a "valid" <src>NoticeTarget</src> linked to the specified
187  // <src>NoticeSource</src>. The <src>NoticeTarget</src> will be added
188  // to the target list in that <src>NoticeSource</src>.
189  // <group>
192  // </group>
193 
194  // Creates a "valid" <src>NoticeTarget</src> linked to the same
195  // <src>NoticeSource</src> as the <src>other NoticeTarget</src>.
196  // So, both <src>NoticeTarget</src>s will occur in the same target
197  // list.
198  // <group>
200  { if (other.isValid()) attach(other.container);}
202  { if (other && other->isValid()) attach( (*other).container );}
203 
204  // </group>
205 
206  // Unlinks this <src>NoticeTarget</src> from its <src>NoticeSource</src>.
207  // The <src>NoticeTarget</src> will be removed from the target list.
208  void unlink();
209 
210  // Links this <src>NoticeTarget</src> to the same <src>NoticeSource</src>
211  // as the <src>other NoticeTarget</src>. Any previous link will be undone.
212  // <group>
213  void link(const NoticeTarget &other);
214  void link(const NoticeTarget *other);
215  // </group>
216 
217  // Retrieves the next <src>NoticeTarget</src> in the target list
218  // of the associated <src>NoticeSource</src>.
219  // <group>
221  return(ilink ? (*ilink).next() : 0);
222  }
223  const Link<NoticeTarget*> *next() const {
224  return(ilink ? (*ilink).next() : 0);
225  }
226  // </group>
227 
228  // Adds this <src>NoticeTarget</src> to the target list in the
229  // specified <src>NoticeSource</src>, so that it will receive all
230  // notices sent out by that <src>NoticeSource</src>.
231  // <group>
232  void attach(NoticeSource *v);
233  void attach(NoticeSource &v);
234  // </group>
235 
236 };
237 
238 
239 } //# NAMESPACE CASACORE - END
240 
241 #endif
242 
243 
244 
245 
246 
Link< NoticeTarget * > * ilink
Definition: Notice.h:177
abstract base class for notice receptors
Definition: Notice.h:153
void attach(NoticeSource *v)
Adds this NoticeTarget to the target list in the specified NoticeSource, so that it will receive all ...
virtual int operator==(const Notice &) const =0
Compare two Notices.
virtual ~NoticeTarget()
Destructs this NoticeTarget.
virtual ~Notice()
NoticeTarget(NoticeTarget &other)
Creates a &quot;valid&quot; NoticeTarget linked to the same NoticeSource as the other NoticeTarget.
Definition: Notice.h:199
Link< NoticeTarget * > * curIters
Definition: Notice.h:115
virtual uInt type() const =0
Return the identification number of the Notice type.
NoticeTarget()
Creates an unlinked, &quot;invalid&quot; NoticeTarget.
Definition: Notice.h:184
base class for notice originators
Definition: Notice.h:102
Link< NoticeTarget * > * next()
Retrieves the next NoticeTarget in the target list of the associated NoticeSource.
Definition: Notice.h:220
void link(const NoticeTarget &other)
Links this NoticeTarget to the same NoticeSource as the other NoticeTarget.
NoticeTarget(NoticeSource *v)
Creates a &quot;valid&quot; NoticeTarget linked to the specified NoticeSource.
Definition: Notice.h:190
NoticeTarget(NoticeSource &v)
Definition: Notice.h:191
void invalidate()
Makes the current NoticeTarget &quot;invalid&quot;.
Definition: Notice.h:169
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
abstract base class for notices
Definition: Notice.h:62
Bool isValid() const
Returns a boolean value telling whether this NoticeTarget is still &quot;valid&quot;.
Definition: Notice.h:162
NoticeSource * container
Definition: Notice.h:178
NoticeTarget(NoticeTarget *other)
Definition: Notice.h:201
const Bool False
Definition: aipstype.h:44
void unlink()
Unlinks this NoticeTarget from its NoticeSource.
virtual void notify(const Notice &)=0
Hook through which NoticeTargets are notified (by NoticeSources).
const Link< NoticeTarget * > * next() const
Definition: Notice.h:223
Bool isAttached() const
Returns a boolean value telling whether this NoticeTarget is still attached to a NoticeSource or not...
Definition: Notice.h:166
void notify(const Notice &note)
Sends the note to all NoticeTargets in the target list.
Link< NoticeTarget * > *& head()
Definition: Notice.h:117
const Bool True
Definition: aipstype.h:43
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42