1//
2// Enum.cpp
3//
4// Library: CppParser
5// Package: SymbolTable
6// Module: Enum
7//
8// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/CppParser/Enum.h"
16#include "Poco/CppParser/EnumValue.h"
17#include "Poco/NumberFormatter.h"
18#include <sstream>
19
20
21using Poco::NumberFormatter;
22
23
24namespace Poco {
25namespace CppParser {
26
27
28int Enum::_count = 0;
29
30
31Enum::Enum(const std::string& name, NameSpace* pNameSpace):
32 Symbol(processName(name), pNameSpace)
33{
34}
35
36
37Enum::~Enum()
38{
39}
40
41
42void Enum::addValue(EnumValue* pValue)
43{
44 poco_check_ptr (pValue);
45
46 _values.push_back(pValue);
47}
48
49
50Enum::Iterator Enum::begin() const
51{
52 return _values.begin();
53}
54
55
56Enum::Iterator Enum::end() const
57{
58 return _values.end();
59}
60
61
62std::string Enum::processName(const std::string& name)
63{
64 if (name.empty())
65 {
66 std::string result("#AnonEnum");
67 result.append(NumberFormatter::format0(_count++, 4));
68 return result;
69 }
70 else return name;
71}
72
73
74Symbol::Kind Enum::kind() const
75{
76 return Symbol::SYM_ENUM;
77}
78
79
80std::string Enum::toString() const
81{
82 std::ostringstream ostr;
83 ostr << "enum " << name() << "\n{\n";
84 for (Iterator it = begin(); it != end(); ++it)
85 {
86 ostr << "\t" << (*it)->toString() << "\n";
87 }
88 ostr << "};";
89 return ostr.str();
90}
91
92
93} } // namespace Poco::CppParser
94