aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/WstringLookup.cpp
blob: 93b189f736f44012daa4cd216d036d85e45e8dc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "stdafx.h"

#include "WstringLookup.h"

WstringLookup::WstringLookup()
{
	numIDs = 0;
}

wstring WstringLookup::lookup(UINT id)
{
	// TODO
	//if (id > currentMaxID)
	//	throw error

	return int2str.at(id);
}
	
UINT WstringLookup::lookup(wstring str)
{
	if (str2int.find(str) == str2int.end())
	{
		pair<wstring,UINT> p = 
			pair<wstring,UINT>(str, numIDs);

		str2int.insert( p );
		int2str.push_back( str );

		return numIDs++;
	}
	else
	{
		return str2int.at(str);
	}
}

VOID WstringLookup::getTable(wstring **lookup, UINT *len)
{
	// Outputs
	wstring *out_lookup; UINT out_len;

	// Fill lookup.
	out_lookup = new wstring[int2str.size()];
	for (UINT i = 0; i < numIDs; i++)
		out_lookup[i] = int2str.at(i);

	out_len = numIDs;

	// Return.
	*lookup = out_lookup;
	*len = out_len;
	return;
}