lang/include/doc_nodes.hpp
2023-07-20 22:21:51 +03:00

52 lines
1.3 KiB
C++

#pragma once
#include <optional>
#include <string>
#include <unordered_map>
namespace nodes {
class SymbolDocs {
public:
SymbolDocs(std::string &&description)
: description_(std::move(description)) {}
SymbolDocs(const std::string &description) : description_(description) {}
template <typename T>
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;
}
std::string *get_description() { return &description_; }
const std::string *get_description() const { return &description_; }
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::string description_;
std::unordered_map<std::string, std::string> annotations_info_;
};
} // namespace nodes