diff options
author | olpc user <olpc@xo-5d-f7-86.localdomain> | 2020-01-10 14:56:27 -0800 |
---|---|---|
committer | olpc user <olpc@xo-5d-f7-86.localdomain> | 2020-01-10 14:56:27 -0800 |
commit | 26c980d302adce8e3d802cb8db8ab1c69d58ce1a (patch) | |
tree | e296225f17370c9e472660396b3a51539f76ff28 /intellect-framework-from-internet/starts/meaning-vm/level-0/concept.hpp | |
parent | 2e01fed206e46a669ba56f57b4b943cfe661a0f1 (diff) | |
parent | c8bb547bea279af2bb48c13260f98aa8add07131 (diff) | |
download | standingwithresilience-26c980d302adce8e3d802cb8db8ab1c69d58ce1a.tar.gz standingwithresilience-26c980d302adce8e3d802cb8db8ab1c69d58ce1a.zip |
Merge branch 'intellect-framework-from-internet'
Diffstat (limited to 'intellect-framework-from-internet/starts/meaning-vm/level-0/concept.hpp')
-rw-r--r-- | intellect-framework-from-internet/starts/meaning-vm/level-0/concept.hpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/intellect-framework-from-internet/starts/meaning-vm/level-0/concept.hpp b/intellect-framework-from-internet/starts/meaning-vm/level-0/concept.hpp new file mode 100644 index 0000000..833e417 --- /dev/null +++ b/intellect-framework-from-internet/starts/meaning-vm/level-0/concept.hpp @@ -0,0 +1,73 @@ +#pragma once + +#include "common.hpp" + +#include <any> +#include <map> +#include <unordered_set> +#include <vector> + +namespace intellect { +namespace level0 { + +struct concept +{ + // a concept is made of concept-typed links to other concepts + std::multimap<concept*,concept*> links; + // and optional associated arbitrary data + std::any data; + + using array = std::vector<concept*>; + + concept* id(); + + void link(concept* type, concept* target); + void unlink(concept* type, concept* target); + void unlink(concept* type); + void unlink(decltype(links)::iterator it); + + bool crucial() { return iscrucial || crucialparts.size(); } + bool crucial(concept* type, concept* target); + bool crucial(decltype(links)::iterator it) { return crucialparts.count(it); } + void setcrucial() { iscrucial = true; } + void setcrucial(concept* type, concept* target); + void setcrucial(decltype(links)::iterator it) { crucialparts.insert(it); } + + bool linked(concept* type) const; + bool linked(concept* type, concept* target) const; + + array getAll(concept* type) const; + + // get and set enforce that only 1 link of a given type is present + concept* get(concept* type) const; + void set(concept* type, concept* target); + + template <typename T> + T & vget(concept* type) const { return get(type)->val<T>(); } + + template <typename T> + T & val() { return std::any_cast<T&>(data); } + + template <typename T> + void val(T const & v) { data = v; } + + bool hasval() { return data.has_value(); } + + template <typename T> + bool hasvalof() { return hasval() && data.type() == typeid(T); } + +private: + // for permanence + bool iscrucial; + struct linksit_hash + { + size_t operator()(decltype(links)::iterator const &it) const + { + return std::hash<decltype(&*it)>()(&*it); + } + }; + std::unordered_set<decltype(links)::iterator, linksit_hash> crucialparts; +}; + +} +} |