1 using System;
2 using System.Collections;
3 using System.IO;
4
5 namespace cmsx.object
6 {
7 public class ClassIdMap
8 {
9 public ClassIdMap()
10 {
11 }
12 public void Read(const string& clsIdFileName)
13 {
14 BinaryReader reader = File.OpenBinary(clsIdFileName);
15 ulong n = reader.ReadULong();
16 for (ulong i = 0u; i < n; ++i;)
17 {
18 try
19 {
20 Uuid typeId = reader.ReadUuid();
21 ulong classId = reader.ReadULong();
22 ulong classIdHigh = reader.ReadULong();
23 classIdMap[typeId] = classId;
24 }
25 catch (const Exception& ex)
26 {
27 throw Exception("error reading class id map: " + ToString(n) + " total entries, trying to read entry " + ToString(i) + ": " + ex.ToString());
28 }
29 }
30 }
31 public ulong GetClassId(const Uuid& typeId) const
32 {
33 HashMap<Uuid, ulong>.ConstIterator it = classIdMap.CFind(typeId);
34 if (it != classIdMap.CEnd())
35 {
36 return it->second;
37 }
38 else
39 {
40 throw Exception("class id for type id " + ToString(typeId) + " not found");
41 }
42 }
43 private HashMap<Uuid, ulong> classIdMap;
44 }
45 }