fipa_acl  1.4
agent_id.h
Go to the documentation of this file.
1 
7 #ifndef FIPA_ACL_AGENTID_H
8 #define FIPA_ACL_AGENTID_H
9 
10 #include <string>
11 #include <vector>
12 #include <iosfwd>
13 #include <utility>
14 #include "userdef_param.h"
15 
16 namespace fipa {
17 
18 namespace acl {
19 
20 class AgentID;
21 
22 // TODO: Recursive container, i.e. container with incomplete type are not supported by
23 // standard containers (though it will work for gcc)
24 // switch to using boost::container in future
25 typedef std::vector<AgentID> AgentIDList;
26 
27 typedef AgentIDList Resolvers;
28 typedef std::vector<std::string> Addresses;
29 
37 class AgentID
38 {
39  friend class ACLMessage;
44 private:
46  std::vector<std::string> mAddresses;
47 
49  AgentIDList mResolvers;
50 
52  std::vector<UserdefParam> mParameters;
53 
54 
55 protected:
57  std::string mName;
58 
60  static const std::string UNDEFINED;
61 
62 public:
63 
64  // depth in the resolver network to compare 2 agent aids; default is 1;
66 
71  bool isValid() const;
72 
76  AgentID();
77 
82  AgentID(const std::string& name);
83 
84  /* NOTE: setter and getter methods are all the functionality needed so far */
85 
90  const std::string& getName() const { return mName; }
91 
97  void setName(const std::string& name);
98 
104  void addAddress(const std::string &adr);
105 
110  const std::vector<std::string>& getAddresses() const { return mAddresses; }
111 
115  void setAddresses(const std::vector<std::string>& addresses) { mAddresses = addresses; }
116 
121  void addResolver(const AgentID &aid);
122 
127  const Resolvers& getResolvers() const { return mResolvers; }
128 
132  void setResolvers(const Resolvers& resolvers) { mResolvers = resolvers; }
133 
138  void deleteResolver(const AgentID& id);
139 
144  void addUserdefParam(const UserdefParam &p);
145 
150  const std::vector<UserdefParam>& getUserdefParams() const { return mParameters; }
151 
155  void setUserdefParams(const std::vector<UserdefParam>& params) { mParameters = params; }
156 
157  //static void setResCompDepth(int);
158  //static int getResCompDepth();
159 
164  bool empty() const;
165 
172  bool operator==(const AgentID& other) const;
173 
179  bool operator!=(const AgentID& other) const { return !(*this == other); }
180 
185  bool operator<(const AgentID& other) const { return this->getName() < other.getName(); }
186 
190  static bool compareEqual(const AgentID& a, const AgentID& b, int depth);
191 
196  std::string toString(size_t indent = 0) const;
197 
198 };
199 
200 template< typename C, typename E>
201 std::basic_ostream<C, E>& operator<<(std::basic_ostream<C,E>& out, const AgentID& agent)
202 {
203  out << "AgentID<" << agent.getName() << ">";
204  return out;
205 }
206 
207 template< typename C, typename E>
208 std::basic_ostream<C, E>& operator<<(std::basic_ostream<C,E>& out, const AgentIDList& agents)
209 {
210  AgentIDList::const_iterator cit = agents.begin();
211  out << "[";
212  for(; cit != agents.end(); ++cit)
213  {
214  out << *cit;
215  }
216  out << "]";
217  return out;
218 }
219 
223 class UndefinedAgentID : public AgentID
224 {
225 public:
227 };
228 
229 }//end of acl namespace
230 }// end of fipa namespace
231 #endif
AgentID()
Default constructor.
Definition: agent_id.cpp:21
void deleteResolver(const AgentID &id)
Delete a resolver.
Definition: agent_id.cpp:69
std::string mName
Definition: agent_id.h:57
bool operator==(const AgentID &other) const
overloaded equality operator for AgentID; the signature of the function was intentionally changed fro...
Definition: agent_id.cpp:85
std::string toString(size_t indent=0) const
Definition: agent_id.cpp:215
void setName(const std::string &name)
the method checks whether the passed name string is a word or not(according to the fipa spec) ...
Definition: agent_id.cpp:36
static bool compareEqual(const AgentID &a, const AgentID &b, int depth)
alternative function for equality operator; the depth can be specified through the depth param ...
Definition: agent_id.cpp:90
void addResolver(const AgentID &aid)
Add resolver.
Definition: agent_id.cpp:59
void addAddress(const std::string &adr)
the method checks whether the passed address string is a word or not(according to the fipa spec) ...
Definition: agent_id.cpp:48
std::vector< AgentID > AgentIDList
Definition: agent_id.h:20
void addUserdefParam(const UserdefParam &p)
Add a userdefined parameter.
Definition: agent_id.cpp:80
void setUserdefParams(const std::vector< UserdefParam > &params)
Definition: agent_id.h:155
AgentIDList Resolvers
Definition: agent_id.h:27
const std::string & getName() const
setter and getter methods for all fields; they do not result in deep-copies assignments/retreivals, but this can be easily changed if needed through the overloaded operator which do
Definition: agent_id.h:90
const std::vector< std::string > & getAddresses() const
Retrieve list of addresses.
Definition: agent_id.h:110
const std::vector< UserdefParam > & getUserdefParams() const
Get the all userdefined parameter.
Definition: agent_id.h:150
bool empty() const
Check if AgentId is empty, i.e. does not contain a name.
Definition: agent_id.cpp:210
static const std::string UNDEFINED
Definition: agent_id.h:60
void setResolvers(const Resolvers &resolvers)
Set list of resolvers.
Definition: agent_id.h:132
static int msResolverComparisonDepth
Definition: agent_id.h:65
std::vector< std::string > Addresses
Definition: agent_id.h:28
const Resolvers & getResolvers() const
Get list of resolvers.
Definition: agent_id.h:127
This class provides a representation of a message conforming to the FIPA specification SC00061...
Definition: acl_message.h:55
overloaded equality operator for UserdefParam class objects
Definition: userdef_param.h:25
bool operator!=(const AgentID &other) const
Allow testing on inequality of agents based on the agents&#39; names only.
Definition: agent_id.h:179
void setAddresses(const std::vector< std::string > &addresses)
Set list of addresses – overwrites existing list of addresses.
Definition: agent_id.h:115
defines the UserdefParam class
Implements the general AgentID functionality, which is present throughout the fipa specifications(FIP...
Definition: agent_id.h:37
Foundation of Physical Intelligent Agents.
Definition: conversation.cpp:6
bool operator<(const AgentID &other) const
Allow comparing two agents, based on the agent name only.
Definition: agent_id.h:185
bool isValid() const
Definition: agent_id.cpp:31