clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27  
28 using System;
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Reflection;
32 using log4net;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35  
36 namespace OpenSim.Region.Framework.Scenes
37 {
38 public class EntityManager
39 {
40 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
41  
42 private readonly DoubleDictionaryThreadAbortSafe<UUID, uint, EntityBase> m_entities
43 = new DoubleDictionaryThreadAbortSafe<UUID, uint, EntityBase>();
44  
45 public int Count
46 {
47 get { return m_entities.Count; }
48 }
49  
50 public void Add(EntityBase entity)
51 {
52 m_entities.Add(entity.UUID, entity.LocalId, entity);
53 }
54  
55 public void Clear()
56 {
57 m_entities.Clear();
58 }
59  
60 public bool ContainsKey(UUID id)
61 {
62 return m_entities.ContainsKey(id);
63 }
64  
65 public bool ContainsKey(uint localID)
66 {
67 return m_entities.ContainsKey(localID);
68 }
69  
70 public bool Remove(uint localID)
71 {
72 return m_entities.Remove(localID);
73 }
74  
75 public bool Remove(UUID id)
76 {
77 return m_entities.Remove(id);
78 }
79  
80 public EntityBase[] GetAllByType<T>()
81 {
82 List<EntityBase> tmp = new List<EntityBase>();
83  
84 ForEach(
85 delegate(EntityBase entity)
86 {
87 if (entity is T)
88 tmp.Add(entity);
89 }
90 );
91  
92 return tmp.ToArray();
93 }
94  
95 public EntityBase[] GetEntities()
96 {
97 List<EntityBase> tmp = new List<EntityBase>(m_entities.Count);
98 ForEach(delegate(EntityBase entity) { tmp.Add(entity); });
99 return tmp.ToArray();
100 }
101  
102 public void ForEach(Action<EntityBase> action)
103 {
104 m_entities.ForEach(action);
105 }
106  
107 public EntityBase Find(Predicate<EntityBase> predicate)
108 {
109 return m_entities.FindValue(predicate);
110 }
111  
112 public EntityBase this[UUID id]
113 {
114 get
115 {
116 EntityBase entity;
117 m_entities.TryGetValue(id, out entity);
118 return entity;
119 }
120 set
121 {
122 Add(value);
123 }
124 }
125  
126 public EntityBase this[uint localID]
127 {
128 get
129 {
130 EntityBase entity;
131 m_entities.TryGetValue(localID, out entity);
132 return entity;
133 }
134 set
135 {
136 Add(value);
137 }
138 }
139  
140 public bool TryGetValue(UUID key, out EntityBase obj)
141 {
142 return m_entities.TryGetValue(key, out obj);
143 }
144  
145 public bool TryGetValue(uint key, out EntityBase obj)
146 {
147 return m_entities.TryGetValue(key, out obj);
148 }
149 }
150 }