Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ObjectDatabaseAssetIndexMap.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using SiliconStudio.Core.Serialization.Assets;
7 
8 namespace SiliconStudio.Core.Storage
9 {
10  /// <summary>
11  /// Asset Index Map implementation which regroups all the asset index maps of every loaded file backend and asset bundle backends.
12  /// </summary>
14  {
15  public Dictionary<string, ObjectId> values = new Dictionary<string, ObjectId>();
16 
17  public IAssetIndexMap WriteableAssetIndexMap { get; set; }
18 
19  /// <summary>
20  /// Merges the values from the given asset index map.
21  /// </summary>
22  /// <param name="assetIndexMap">The asset index map to merge.</param>
23  public void Merge(IAssetIndexMap assetIndexMap)
24  {
25  Merge(assetIndexMap.GetMergedIdMap());
26  }
27 
28  /// <summary>
29  /// Merges the values from the given assets.
30  /// </summary>
31  /// <param name="assets">The assets to merge.</param>
32  public void Merge(IEnumerable<KeyValuePair<string, ObjectId>> assets)
33  {
34  lock (values)
35  {
36  foreach (var item in assets)
37  {
38  values[item.Key] = item.Value;
39  }
40  }
41  }
42 
43  /// <summary>
44  /// Unmerges the values from the given assets.
45  /// </summary>
46  /// <param name="assets">The assets to merge.</param>
47  public void Unmerge(IEnumerable<KeyValuePair<string, ObjectId>> assets)
48  {
49  lock (values)
50  {
51  foreach (var item in assets)
52  {
53  values.Remove(item.Key);
54  }
55  }
56  }
57 
58  public bool TryGetValue(string url, out ObjectId objectId)
59  {
60  lock (values)
61  {
62  return values.TryGetValue(url, out objectId);
63  }
64  }
65 
66  public IEnumerable<KeyValuePair<string, ObjectId>> SearchValues(Func<KeyValuePair<string, ObjectId>, bool> predicate)
67  {
68  lock (values)
69  {
70  return values.Where(predicate).ToArray();
71  }
72  }
73 
74  public bool Contains(string url)
75  {
76  lock (values)
77  {
78  return values.ContainsKey(url);
79  }
80  }
81 
82  public ObjectId this[string url]
83  {
84  get
85  {
86  lock (values)
87  {
88  return values[url];
89  }
90  }
91  set
92  {
93  lock (values)
94  {
95  if (WriteableAssetIndexMap != null)
96  WriteableAssetIndexMap[url] = value;
97  values[url] = value;
98  }
99  }
100  }
101 
103  {
104  lock (values)
105  {
106  return values.ToArray();
107  }
108  }
109 
110  public void Dispose()
111  {
112  }
113  }
114 }
IEnumerable< KeyValuePair< string, ObjectId > > GetMergedIdMap()
void Merge(IAssetIndexMap assetIndexMap)
Merges the values from the given asset index map.
Asset Index Map implementation which regroups all the asset index maps of every loaded file backend a...
void Unmerge(IEnumerable< KeyValuePair< string, ObjectId >> assets)
Unmerges the values from the given assets.
IEnumerable< KeyValuePair< string, ObjectId > > GetMergedIdMap()
void Merge(IEnumerable< KeyValuePair< string, ObjectId >> assets)
Merges the values from the given assets.
IEnumerable< KeyValuePair< string, ObjectId > > SearchValues(Func< KeyValuePair< string, ObjectId >, bool > predicate)
A hash to uniquely identify data.
Definition: ObjectId.cs:13