载入中...
搜索中...
未找到
Social.cpp
浏览该文件的文档.
25bool Social::setOwner(const std::string& entity, const std::string& owner) { return graph_.setOwner(entity, owner); }
30std::string Social::ownerOfInt(int entity) const { return graph_.ownerOf(SocialGraph::integerId(entity)); }
31int Social::ownedCount(const std::string& owner) const { return static_cast<int>(graph_.ownedBy(owner).size()); }
32std::string Social::ownedAt(const std::string& owner, int index) const { return at(graph_.ownedBy(owner), index); }
40std::string Social::controllerOf(const std::string& entity) const { return graph_.controllerOf(entity); }
41std::string Social::controllerOfInt(int entity) const { return graph_.controllerOf(SocialGraph::integerId(entity)); }
49bool Social::assign(const std::string& source, const std::string& role, const std::string& target) {
55bool Social::unassign(const std::string& source, const std::string& role, const std::string& target) {
58bool Social::isAssigned(const std::string& source, const std::string& role, const std::string& target) const {
64std::string Social::targetAt(const std::string& source, const std::string& role, int index) const {
70std::string Social::assigneeAt(const std::string& target, const std::string& role, int index) const {
78 return graph_.setRelation(SocialGraph::integerId(source), SocialGraph::integerId(target), type, value);
80float Social::addRelation(const std::string& source, const std::string& target, const std::string& type, float delta) {
83bool Social::link(const std::string& source, const std::string& target, const std::string& type) {
86bool Social::removeRelation(const std::string& source, const std::string& target, const std::string& type) {
89bool Social::hasRelation(const std::string& source, const std::string& target, const std::string& type) const {
92float Social::relation(const std::string& source, const std::string& target, const std::string& type,
96int Social::relationTargetCount(const std::string& source, const std::string& type, float minimum) const {
99std::string Social::relationTargetAt(const std::string& source, const std::string& type, float minimum,
103int Social::relationSourceCount(const std::string& target, const std::string& type, float minimum) const {
106std::string Social::relationSourceAt(const std::string& target, const std::string& type, float minimum,
112bool Social::removeEntityInt(int entity) { return graph_.removeEntity(SocialGraph::integerId(entity)); }
219void SocialGraph::emit(std::string action, EntityId source, EntityId target, std::string type, double oldValue,
221 events_.push_back({nextSequence_++, std::move(action), std::move(source), std::move(target), std::move(type),
308std::vector<EntityId> SocialGraph::targetsOf(const EntityId& source, const std::string& role) const {
313std::vector<EntityId> SocialGraph::assigneesOf(const EntityId& target, const std::string& role) const {
318bool SocialGraph::setRelation(const EntityId& source, const EntityId& target, const std::string& type, double value) {
363std::vector<EntityId> SocialGraph::relationTargets(const EntityId& source, const std::string& type,
374std::vector<EntityId> SocialGraph::relationSources(const EntityId& target, const std::string& type,
397 if (key.first == entity || target == entity) assignments.emplace_back(key.first, key.second, target);
400 for (const auto& [source, role, target] : assignments) changed = unassign(source, role, target) || changed;
bool assign(const EntityId &source, const std::string &role, const EntityId &target)
Adds a role-based source-to-target assignment.
Definition Social.cpp:283
EntityId controllerOf(const EntityId &entity) const
Returns an entity's controller, or an empty string when absent.
Definition Social.cpp:273
bool link(const EntityId &source, const EntityId &target, const std::string &type)
Creates a directed typed relation with weight 1.
Definition Social.cpp:337
std::vector< EntityId > ownedBy(const EntityId &owner) const
Returns entities owned by owner in deterministic ID order.
Definition Social.cpp:253
bool setOwner(const EntityId &entity, const EntityId &owner)
Sets an entity's owner; an empty owner removes ownership.
Definition Social.cpp:233
static EntityId integerId(std::int64_t id)
Converts a stable integer ID to its canonical graph key.
Definition Social.cpp:217
double addRelation(const EntityId &source, const EntityId &target, const std::string &type, double delta)
Adds delta to a directed typed relation and returns its new weight.
Definition Social.cpp:331
std::vector< EntityId > controlledBy(const EntityId &controller) const
Returns entities controlled by controller in deterministic ID order.
Definition Social.cpp:278
bool setRelation(const EntityId &source, const EntityId &target, const std::string &type, double value)
Sets a directed typed relation weight, creating the edge if needed.
Definition Social.cpp:318
bool unassign(const EntityId &source, const std::string &role, const EntityId &target)
Removes a role-based source-to-target assignment.
Definition Social.cpp:293
bool setController(const EntityId &entity, const EntityId &controller)
Sets an entity's controller; an empty controller removes control.
Definition Social.cpp:258
std::vector< EntityId > targetsOf(const EntityId &source, const std::string &role) const
Returns targets assigned from source with role in deterministic order.
Definition Social.cpp:308
bool removeEntity(const EntityId &entity)
Removes an entity and every incoming/outgoing graph reference to it.
Definition Social.cpp:385
std::vector< EntityId > assigneesOf(const EntityId &target, const std::string &role) const
Returns sources assigned to target with role in deterministic order.
Definition Social.cpp:313
EntityId ownerOf(const EntityId &entity) const
Returns an entity's owner, or an empty string when absent.
Definition Social.cpp:248
bool removeRelation(const EntityId &source, const EntityId &target, const std::string &type)
Removes an exact directed typed relation.
Definition Social.cpp:341
bool isAssigned(const EntityId &source, const std::string &role, const EntityId &target) const
Tests whether an exact assignment exists.
Definition Social.cpp:303
double relation(const EntityId &source, const EntityId &target, const std::string &type, double fallback=0.0) const
Gets an exact relation weight, or fallback when absent.
Definition Social.cpp:357
std::vector< EntityId > relationTargets(const EntityId &source, const std::string &type, double minimum=0.0) const
Returns outgoing relation targets filtered by type and minimum weight.
Definition Social.cpp:363
bool hasRelation(const EntityId &source, const EntityId &target, const std::string &type) const
Tests whether an exact directed typed relation exists.
Definition Social.cpp:353
const std::vector< SocialChangeEvent > & events() const
Returns queued mutation events in sequence order.
Definition SocialGraph.h:88
std::vector< EntityId > relationSources(const EntityId &target, const std::string &type, double minimum=0.0) const
Returns incoming relation sources filtered by type and minimum weight.
Definition Social.cpp:374
bool removeEntityInt(int entity)
Removes an integer-ID entity and every graph reference to it.
Definition Social.cpp:112
std::string controllerOfInt(int entity) const
Gets controller of an integer ID as a canonical key.
Definition Social.cpp:41
std::string relationSourceAt(const std::string &target, const std::string &type, float minimum, int index) const
Gets incoming relation source by deterministic filtered index.
Definition Social.cpp:106
int ownedCount(const std::string &owner) const
Gets count of deterministically ordered entities owned by owner.
Definition Social.cpp:31
bool unassign(const std::string &source, const std::string &role, const std::string &target)
Removes an exact assignment.
Definition Social.cpp:55
int relationTargetCount(const std::string &source, const std::string &type, float minimum) const
Gets outgoing relation target count after threshold filtering.
Definition Social.cpp:96
std::string relationTargetAt(const std::string &source, const std::string &type, float minimum, int index) const
Gets outgoing relation target by deterministic filtered index.
Definition Social.cpp:99
std::string ownerOf(const std::string &entity) const
Gets owner of a string ID.
Definition Social.cpp:29
bool assign(const std::string &source, const std::string &role, const std::string &target)
Adds a role-based assignment between string IDs.
Definition Social.cpp:49
std::string targetAt(const std::string &source, const std::string &role, int index) const
Gets an assignment target by deterministic index.
Definition Social.cpp:64
std::string controllerOf(const std::string &entity) const
Gets controller of a string ID.
Definition Social.cpp:40
bool setController(const std::string &entity, const std::string &controller)
Sets control between string IDs.
Definition Social.cpp:34
bool setRelation(const std::string &source, const std::string &target, const std::string &type, float value)
Sets a directed typed relation between string IDs.
Definition Social.cpp:74
bool setRelationInt(int source, int target, const std::string &type, float value)
Sets a directed typed relation between integer IDs.
Definition Social.cpp:77
int eventSequence(int index) const
Gets event sequence by index, or zero when out of range.
Definition Social.cpp:116
std::string controlledAt(const std::string &controller, int index) const
Gets a controlled entity by deterministic index.
Definition Social.cpp:45
bool removeEntity(const std::string &entity)
Removes a string-ID entity and every graph reference to it.
Definition Social.cpp:111
int targetCount(const std::string &source, const std::string &role) const
Gets target count for source and role.
Definition Social.cpp:61
bool isAssigned(const std::string &source, const std::string &role, const std::string &target) const
Tests an exact assignment.
Definition Social.cpp:58
bool hasRelation(const std::string &source, const std::string &target, const std::string &type) const
Tests an exact relation.
Definition Social.cpp:89
bool removeRelation(const std::string &source, const std::string &target, const std::string &type)
Removes an exact relation.
Definition Social.cpp:86
int assigneeCount(const std::string &target, const std::string &role) const
Gets assignee count for target and role.
Definition Social.cpp:67
int relationSourceCount(const std::string &target, const std::string &type, float minimum) const
Gets incoming relation source count after threshold filtering.
Definition Social.cpp:103
int controlledCount(const std::string &controller) const
Gets count of deterministically ordered controlled entities.
Definition Social.cpp:42
std::string assigneeAt(const std::string &target, const std::string &role, int index) const
Gets an assignee by deterministic index.
Definition Social.cpp:70
bool assignInt(int source, const std::string &role, int target)
Adds a role-based assignment between integer IDs.
Definition Social.cpp:52
std::string ownedAt(const std::string &owner, int index) const
Gets an owned entity by deterministic index.
Definition Social.cpp:32
bool setControllerInt(int entity, int controller)
Sets control between integer IDs.
Definition Social.cpp:37
std::string idFromInt(int id) const
Returns the canonical graph key for an integer entity ID.
Definition Social.cpp:23
float relation(const std::string &source, const std::string &target, const std::string &type, float fallback) const
Gets relation value or fallback.
Definition Social.cpp:92
std::string ownerOfInt(int entity) const
Gets owner of an integer ID as a canonical key.
Definition Social.cpp:30
bool setOwner(const std::string &entity, const std::string &owner)
Sets ownership between string IDs.
Definition Social.cpp:25
float addRelation(const std::string &source, const std::string &target, const std::string &type, float delta)
Adds to a relation and returns its new value.
Definition Social.cpp:80
bool link(const std::string &source, const std::string &target, const std::string &type)
Creates a weight-one directed typed relation.
Definition Social.cpp:83
Definition SocialDocument.h:13
std::string EntityId
Stable, game-defined identifier used by the social graph.
Definition SocialGraph.h:15