1/*
2 * Copyright 2015, Rene Gollent, rene@gollent.com.
3 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Distributed under the terms of the MIT License.
5 */
6#include "EnumerationValueFormatter.h"
7
8#include "EnumerationValue.h"
9#include "Type.h"
10
11
12EnumerationValueFormatter::EnumerationValueFormatter(Config* config)
13	:
14	IntegerValueFormatter(config)
15{
16}
17
18
19EnumerationValueFormatter::~EnumerationValueFormatter()
20{
21}
22
23
24status_t
25EnumerationValueFormatter::FormatValue(Value* _value, BString& _output)
26{
27	Config* config = GetConfig();
28	if (config != NULL && config->IntegerFormat() == INTEGER_FORMAT_DEFAULT) {
29		EnumerationValue* value = dynamic_cast<EnumerationValue*>(_value);
30		if (value == NULL)
31			return B_BAD_VALUE;
32
33		if (EnumeratorValue* enumValue
34				= value->GetType()->ValueFor(value->GetValue())) {
35			_output.SetTo(enumValue->Name());
36			return B_OK;
37		}
38	}
39
40	return IntegerValueFormatter::FormatValue(_value, _output);
41}
42