mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-06 23:18:45 +00:00
72 lines
1.8 KiB
C++
72 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
namespace nodes {
|
|
|
|
class SymbolDocs {
|
|
public:
|
|
SymbolDocs() {}
|
|
|
|
SymbolDocs(std::string &&description)
|
|
: description_(std::move(description)) {}
|
|
|
|
SymbolDocs(const std::string &description) : description_(description) {}
|
|
|
|
bool add_annotation_info(const std::string &annotation, std::string &&info) {
|
|
if (annotations_info_.count(annotation) == 0) {
|
|
annotations_info_[annotation] = std::move(info);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool add_annotation_info(const std::string &annotation,
|
|
const std::string &info) {
|
|
if (annotations_info_.count(annotation) == 0) {
|
|
annotations_info_[annotation] = info;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
std::optional<std::string *> get_description() {
|
|
if (description_.has_value()) {
|
|
return &description_.value();
|
|
}
|
|
return std::nullopt;
|
|
}
|
|
|
|
std::optional<const std::string *> get_description() const {
|
|
if (description_.has_value()) {
|
|
return &description_.value();
|
|
}
|
|
return std::nullopt;
|
|
}
|
|
|
|
std::optional<std::string *>
|
|
get_annotation_info(const std::string &annotation) {
|
|
auto info_iterator = annotations_info_.find(annotation);
|
|
if (info_iterator != annotations_info_.end()) {
|
|
return &info_iterator->second;
|
|
}
|
|
return std::nullopt;
|
|
}
|
|
|
|
std::optional<const std::string *>
|
|
get_annotation_info(const std::string &annotation) const {
|
|
auto info_iterator = annotations_info_.find(annotation);
|
|
if (info_iterator != annotations_info_.end()) {
|
|
return &info_iterator->second;
|
|
}
|
|
return std::nullopt;
|
|
}
|
|
|
|
private:
|
|
std::optional<std::string> description_;
|
|
std::unordered_map<std::string, std::string> annotations_info_;
|
|
};
|
|
|
|
} // namespace nodes
|