1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
4 using System
.Collections
.Generic
;
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>();
30 get { return m_idxToPaths.Count; }
37 m_lock
.EnterReadLock();
38 string[] paths
= m_idxToPaths
.ToArray();
39 m_lock
.ExitReadLock();
44 public int AddPath(string path
)
46 m_lock
.EnterWriteLock();
49 if (m_pathsToIdx
.TryGetValue(path
, out idx
))
51 m_lock
.ExitWriteLock();
55 idx
= m_idxToPaths
.Count
;
56 m_pathsToIdx
.Add(path
, idx
);
57 m_idxToPaths
.Add(path
);
58 m_lock
.ExitWriteLock();
63 public void AddPaths(IEnumerable
<string> paths
)
65 m_lock
.EnterWriteLock();
67 foreach (string path
in paths
)
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();
91 if (m_pathsToIdx
.TryGetValue(path
, out idx
))
93 m_lock
.ExitReadLock();
97 m_lock
.ExitReadLock();
101 public int GetIndexFromPath(string path
)
103 int idx
= TryGetIndexFromPath(path
);
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();