lang/include/nodes/doc_nodes.hpp

103 lines
2.6 KiB
C++
Raw Normal View History

#pragma once
#include <optional>
#include <string>
#include <unordered_map>
2023-07-25 21:33:57 +03:00
#include <vector>
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) {}
bool add_annotation_info(const std::string &annotation, std::string &&info) {
2023-07-25 21:33:57 +03:00
if (annotations_info_ids_.count(annotation) == 0) {
annotations_info_ids_[annotation] = annotations_info_.size();
annotations_info_.emplace_back(annotation, std::move(info));
return true;
}
return false;
}
bool add_annotation_info(const std::string &annotation,
const std::string &info) {
2023-07-25 21:33:57 +03:00
if (annotations_info_ids_.count(annotation) == 0) {
annotations_info_ids_[annotation] = annotations_info_.size();
annotations_info_.emplace_back(annotation, std::move(info));
return true;
}
return false;
}
2023-07-25 21:33:57 +03:00
//
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;
}
2023-07-25 21:33:57 +03:00
//
std::optional<std::string *>
get_annotation_info(const std::string &annotation) {
2023-07-25 21:33:57 +03:00
auto info_iterator = annotations_info_ids_.find(annotation);
if (info_iterator != annotations_info_ids_.end()) {
return &annotations_info_[info_iterator->second].second;
}
return std::nullopt;
}
std::optional<const std::string *>
get_annotation_info(const std::string &annotation) const {
2023-07-25 21:33:57 +03:00
auto info_iterator = annotations_info_ids_.find(annotation);
if (info_iterator != annotations_info_ids_.end()) {
return &annotations_info_[info_iterator->second].second;
}
return std::nullopt;
}
2023-07-25 21:33:57 +03:00
//
size_t get_annotations_info_size() const { return annotations_info_.size(); }
std::string *get_annotation(size_t id) {
return &annotations_info_[id].first;
}
const std::string *get_annotation(size_t id) const {
return &annotations_info_[id].first;
}
std::string *get_annotation_info(size_t id) {
return &annotations_info_[id].second;
}
const std::string *get_annotation_info(size_t id) const {
return &annotations_info_[id].second;
}
//
private:
2023-07-23 19:40:27 +03:00
std::optional<std::string> description_;
2023-07-25 21:33:57 +03:00
std::vector<std::pair<std::string, std::string>> annotations_info_;
std::unordered_map<std::string, size_t> annotations_info_ids_;
};
2023-07-20 14:38:44 +03:00
} // namespace nodes