| 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 | |
| 21 | using Poco::NumberFormatter; |
| 22 | |
| 23 | |
| 24 | namespace Poco { |
| 25 | namespace CppParser { |
| 26 | |
| 27 | |
| 28 | int Enum::_count = 0; |
| 29 | |
| 30 | |
| 31 | Enum::Enum(const std::string& name, NameSpace* pNameSpace): |
| 32 | Symbol(processName(name), pNameSpace) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | |
| 37 | Enum::~Enum() |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | |
| 42 | void Enum::addValue(EnumValue* pValue) |
| 43 | { |
| 44 | poco_check_ptr (pValue); |
| 45 | |
| 46 | _values.push_back(pValue); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | Enum::Iterator Enum::begin() const |
| 51 | { |
| 52 | return _values.begin(); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | Enum::Iterator Enum::end() const |
| 57 | { |
| 58 | return _values.end(); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | std::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 | |
| 74 | Symbol::Kind Enum::kind() const |
| 75 | { |
| 76 | return Symbol::SYM_ENUM; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | std::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 |