~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to contrib/Sharpen/Sharpen/SoftReference.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
namespace Sharpen
 
2
{
 
3
        using System;
 
4
 
 
5
        internal class SoftReference<T> : Reference<T>
 
6
        {
 
7
                private ReferenceQueue<T> queue;
 
8
                private T value;
 
9
 
 
10
                public SoftReference (T val)
 
11
                {
 
12
                        this.value = val;
 
13
                }
 
14
 
 
15
                public SoftReference (T val, ReferenceQueue<T> queue)
 
16
                {
 
17
                        this.value = val;
 
18
                        this.queue = queue;
 
19
                }
 
20
 
 
21
                public void Clear ()
 
22
                {
 
23
                        this.value = default(T);
 
24
                }
 
25
 
 
26
                public bool Enqueue ()
 
27
                {
 
28
                        if (this.queue == null) {
 
29
                                return false;
 
30
                        }
 
31
                        return this.queue.Add (this);
 
32
                }
 
33
 
 
34
                public override T Get ()
 
35
                {
 
36
                        return this.value;
 
37
                }
 
38
        }
 
39
}