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 #pragma once
30 
31 #include <InterViews/enter-scope.h>
32 
33 class Resource {
34 public:
35  Resource() = default;
36  virtual ~Resource() = default;
37 
38  virtual void ref() const;
39  virtual void unref() const;
40  virtual void unref_deferred() const;
41  virtual void cleanup();
42 
43  /* nops for nil pointers */
44  static void ref(const Resource*);
45  static void unref(const Resource*);
46  static void unref_deferred(const Resource*);
47 
48  /* postpone unref deletes */
49  static bool defer(bool);
50  static void flush();
51 
52  /* for backward compatibility */
53  virtual void Reference() const { ref(); }
54  virtual void Unreference() const { unref(); }
55 private:
56  unsigned refcount_{};
57 private:
58  /* prohibit default assignment */
60 };
61 
62 /*
63  * For backward compatibility
64  */
65 
66 static inline void Unref(const Resource* r) { Resource::unref(r); }
virtual void Reference() const
Definition: resource.h:53
virtual void Unreference() const
Definition: resource.h:54
virtual void ref() const
Definition: resource.cpp:42
virtual void cleanup()
Definition: resource.cpp:73
Resource & operator=(const Resource &)
unsigned refcount_
Definition: resource.h:56
virtual ~Resource()=default
static bool defer(bool)
Definition: resource.cpp:93
Resource()=default
virtual void unref() const
Definition: resource.cpp:47
virtual void unref_deferred() const
Definition: resource.cpp:58
static void flush()
Definition: resource.cpp:102
static void Unref(const Resource *r)
Definition: resource.h:66