1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include "EnumerationValue.h"
8
9#include "Type.h"
10
11
12EnumerationValue::EnumerationValue(EnumerationType* type, const BVariant& value)
13	:
14	IntegerValue(value),
15	fType(type)
16{
17	fType->AcquireReference();
18}
19
20
21EnumerationValue::~EnumerationValue()
22{
23	fType->ReleaseReference();
24}
25
26
27bool
28EnumerationValue::ToString(BString& _string) const
29{
30	if (!fValue.IsInteger())
31		return false;
32
33	EnumeratorValue* enumValue = fType->ValueFor(fValue);
34	if (enumValue == NULL)
35		return IntegerValue::ToString(_string);
36
37	BString string(enumValue->Name());
38	if (string.Length() == 0)
39		return false;
40
41	_string = string;
42	return true;
43}
44