printing fixes

This commit is contained in:
ProgramSnail 2023-07-25 21:33:57 +03:00
parent 0bb72e0b10
commit 469cb3581f
23 changed files with 318 additions and 151 deletions

View file

@ -3,6 +3,7 @@
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>
namespace nodes {
@ -16,8 +17,9 @@ public:
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);
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;
@ -25,13 +27,16 @@ public:
bool add_annotation_info(const std::string &annotation,
const std::string &info) {
if (annotations_info_.count(annotation) == 0) {
annotations_info_[annotation] = info;
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;
}
//
std::optional<std::string *> get_description() {
if (description_.has_value()) {
return &description_.value();
@ -46,27 +51,52 @@ public:
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;
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 {
auto info_iterator = annotations_info_.find(annotation);
if (info_iterator != annotations_info_.end()) {
return &info_iterator->second;
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;
}
//
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:
std::optional<std::string> description_;
std::unordered_map<std::string, std::string> annotations_info_;
std::vector<std::pair<std::string, std::string>> annotations_info_;
std::unordered_map<std::string, size_t> annotations_info_ids_;
};
} // namespace nodes