!B (Sandbox) (CE-21795) Importing models with multisubmaterials via fbx switches...
[CRYENGINE.git] / Code / Tools / Statoscope / Statoscope / FrameRecordPathCollection.cs
blob8e5a17336caa762077d439bdf4c65145f2deea49
1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using System.Text;
8 namespace Statoscope
10 public interface IReadOnlyFRPC
12 int PathCount { get; }
13 string[] Paths { get; }
15 bool ContainsPath(string path);
16 int TryGetIndexFromPath(string path);
17 int GetIndexFromPath(string path);
19 string GetPathFromIndex(int idx);
22 public class FrameRecordPathCollection : IReadOnlyFRPC
24 private System.Threading.ReaderWriterLockSlim m_lock = new System.Threading.ReaderWriterLockSlim();
25 private Dictionary<string, int> m_pathsToIdx = new Dictionary<string, int>();
26 private List<string> m_idxToPaths = new List<string>();
28 public int PathCount
30 get { return m_idxToPaths.Count; }
33 public string[] Paths
35 get
37 m_lock.EnterReadLock();
38 string[] paths = m_idxToPaths.ToArray();
39 m_lock.ExitReadLock();
40 return paths;
44 public int AddPath(string path)
46 m_lock.EnterWriteLock();
48 int idx;
49 if (m_pathsToIdx.TryGetValue(path, out idx))
51 m_lock.ExitWriteLock();
52 return idx;
55 idx = m_idxToPaths.Count;
56 m_pathsToIdx.Add(path, idx);
57 m_idxToPaths.Add(path);
58 m_lock.ExitWriteLock();
60 return idx;
63 public void AddPaths(IEnumerable<string> paths)
65 m_lock.EnterWriteLock();
67 foreach (string path in paths)
69 int idx;
70 if (!m_pathsToIdx.TryGetValue(path, out idx))
72 idx = m_idxToPaths.Count;
73 m_pathsToIdx.Add(path, idx);
74 m_idxToPaths.Add(path);
78 m_lock.ExitWriteLock();
81 public bool ContainsPath(string path)
83 return TryGetIndexFromPath(path) != -1;
86 public int TryGetIndexFromPath(string path)
88 m_lock.EnterReadLock();
90 int idx;
91 if (m_pathsToIdx.TryGetValue(path, out idx))
93 m_lock.ExitReadLock();
94 return idx;
97 m_lock.ExitReadLock();
98 return -1;
101 public int GetIndexFromPath(string path)
103 int idx = TryGetIndexFromPath(path);
104 if (idx != -1)
105 return idx;
106 else
107 throw new Exception("Path does not exist: " + path);
110 public string GetPathFromIndex(int idx)
112 string res = string.Empty;
114 m_lock.EnterReadLock();
115 if (idx < m_idxToPaths.Count)
116 res = m_idxToPaths[idx];
117 m_lock.ExitReadLock();
119 return res;