NEURON
resource.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1987, 1988, 1989, 1990, 1991 Stanford University
3  * Copyright (c) 1991 Silicon Graphics, Inc.
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and
6  * its documentation for any purpose is hereby granted without fee, provided
7  * that (i) the above copyright notices and this permission notice appear in
8  * all copies of the software and related documentation, and (ii) the names of
9  * Stanford and Silicon Graphics may not be used in any advertising or
10  * publicity relating to the software without the specific, prior written
11  * permission of Stanford and Silicon Graphics.
12  *
13  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * IN NO EVENT SHALL STANFORD OR SILICON GRAPHICS BE LIABLE FOR
18  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22  * OF THIS SOFTWARE.
23  */
24 
25 /*
26  * Resources are shared objects.
27  */
28 
29 #ifndef iv_resource_h
30 #define iv_resource_h
31 
32 #include <InterViews/enter-scope.h>
33 
34 class Resource {
35 public:
36  Resource();
37  virtual ~Resource();
38 
39  virtual void ref() const;
40  virtual void unref() const;
41  virtual void unref_deferred() const;
42  virtual void cleanup();
43 
44  /* nops for nil pointers */
45  static void ref(const Resource*);
46  static void unref(const Resource*);
47  static void unref_deferred(const Resource*);
48 
49  /* postpone unref deletes */
50  static bool defer(bool);
51  static void flush();
52 
53  /* for backward compatibility */
54  virtual void Reference() const { ref(); }
55  virtual void Unreference() const { unref(); }
56 private:
57  unsigned refcount_;
58 private:
59  /* prohibit default assignment */
60  Resource& operator =(const Resource&);
61 };
62 
63 /*
64  * For backward compatibility
65  */
66 
67 static inline void Unref(const Resource* r) { Resource::unref(r); }
68 
69 #endif
static bool defer(bool)
Definition: resource.cpp:101
virtual void unref_deferred() const
Definition: resource.cpp:63
virtual void ref() const
Definition: resource.cpp:47
Resource()
Definition: resource.cpp:44
Resource & operator=(const Resource &)
unsigned refcount_
Definition: resource.h:57
static void Unref(const Resource *r)
Definition: resource.h:67
virtual void cleanup()
Definition: resource.cpp:81
virtual void unref() const
Definition: resource.cpp:52
virtual ~Resource()
Definition: resource.cpp:45
virtual void Unreference() const
Definition: resource.h:55
virtual void Reference() const
Definition: resource.h:54
static void flush()
Definition: resource.cpp:110