GAMS  1.4.0
GroupBase.h
Go to the documentation of this file.
1 
54 #ifndef _GAMS_GROUPS_GROUP_BASE_H_
55 #define _GAMS_GROUPS_GROUP_BASE_H_
56 
57 #include <vector>
58 #include <string>
59 #include <map>
60 
61 #include "madara/knowledge/KnowledgeBase.h"
62 
63 #include "gams/GamsExport.h"
64 #include "GroupTypesEnum.h"
65 
66 namespace gams
67 {
68  namespace groups
69  {
71  typedef std::vector <std::string> AgentVector;
72 
74  typedef std::map <std::string,
75  madara::knowledge::KnowledgeRecord::Integer> AgentMap;
76 
84  int find_member_index(const std::string & prefix,
85  const AgentVector & members);
86 
91  {
92  public:
98  GroupBase(const std::string & prefix = "",
99  madara::knowledge::KnowledgeBase * knowledge = 0);
100 
104  virtual ~GroupBase();
105 
110  virtual void add_members(const AgentVector & members) = 0;
111 
115  virtual void clear_members(void) = 0;
116 
121  virtual void get_members(AgentVector & members) const = 0;
122 
129  virtual bool is_member(const std::string & id) const = 0;
130 
135  virtual void remove_members(const AgentVector & members) = 0;
136 
145  virtual void write(const std::string & prefix = "",
146  madara::knowledge::KnowledgeBase * knowledge = 0) const = 0;
147 
153  virtual void set_prefix(const std::string & prefix,
154  madara::knowledge::KnowledgeBase * knowledge = 0);
155 
160  virtual size_t size(void) = 0;
161 
165  virtual void sync(void) = 0;
166 
171  const std::string & get_prefix(void) const;
172 
173  protected:
174 
178  mutable madara::knowledge::KnowledgeBase * knowledge_;
179 
183  std::string prefix_;
184  };
185  }
186 }
187 
188 #include "GroupBase.inl"
189 
190 #endif // _GAMS_GROUPS_GROUP_BASE_H_
#define GAMS_EXPORT
Definition: GamsExport.h:20
Copyright (c) 2016 Carnegie Mellon University.
Base class for a group of agents.
Definition: GroupBase.h:91
GroupBase(const std::string &prefix="", madara::knowledge::KnowledgeBase *knowledge=0)
Constructor.
virtual void remove_members(const AgentVector &members)=0
Removes members from the group.
madara::knowledge::KnowledgeBase * knowledge_
The knowledge base to use as a data plane.
Definition: GroupBase.h:178
virtual void clear_members(void)=0
Clears the member list.
virtual void sync(void)=0
Syncs the list to the knowledge base.
virtual bool is_member(const std::string &id) const =0
Checks if the agent is a member of the formation.
virtual void set_prefix(const std::string &prefix, madara::knowledge::KnowledgeBase *knowledge=0)
Sets the prefix for the group in the knowledge base.
virtual size_t size(void)=0
Returns the number of members in the group.
virtual ~GroupBase()
Constructor.
std::string prefix_
the prefix for the group
Definition: GroupBase.h:183
virtual void get_members(AgentVector &members) const =0
Retrieves the members from the group.
virtual void write(const std::string &prefix="", madara::knowledge::KnowledgeBase *knowledge=0) const =0
Writes the group information to a specified prefix in a knowledge base.
const std::string & get_prefix(void) const
Gets the prefix for the group in the knowledge base.
virtual void add_members(const AgentVector &members)=0
Adds the members to the group.
int find_member_index(const std::string &prefix, const AgentVector &members)
Finds the index of the member prefix in a member listing.
std::vector< std::string > AgentVector
A vector of agent names.
Definition: GroupBase.h:71
std::map< std::string, madara::knowledge::KnowledgeRecord::Integer > AgentMap
A map of agent names.
Definition: GroupBase.h:75
Contains all GAMS-related tools, classes and code.