lang/include/doc_nodes.hpp

65 lines
1.6 KiB
C++
Raw Normal View History

#pragma once
#include <optional>
#include <string>
#include <unordered_map>
2023-07-20 14:38:44 +03:00
namespace nodes {
class SymbolDocs {
public:
2023-07-23 19:40:27 +03:00
SymbolDocs() {}
SymbolDocs(std::string &&description)
: description_(std::move(description)) {}
SymbolDocs(const std::string &description) : description_(description) {}
template <typename T>
2023-07-18 16:45:35 +03:00
bool add_annotation_info(const std::string &annotation, T &&info) {
if (annotations_info_.count(annotation) == 0) {
annotations_info_[annotation] = std::forward<T>(info);
return true;
}
return false;
}
2023-07-23 19:40:27 +03:00
std::optional<std::string *> get_description() {
if (description_.has_value()) {
return &description_.value();
}
return std::nullopt;
}
2023-07-23 19:40:27 +03:00
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:
2023-07-23 19:40:27 +03:00
std::optional<std::string> description_;
std::unordered_map<std::string, std::string> annotations_info_;
};
2023-07-20 14:38:44 +03:00
} // namespace nodes