fipa_acl  1.4
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Static Protected Attributes | Friends | List of all members
fipa::acl::AgentID Class Reference

Implements the general AgentID functionality, which is present throughout the fipa specifications(FIPA at http://www.fipa.org). Functionality may need to be extended as further modules are implemented Important notice: the probably main field of an AgentID, the actual id, is not yet declared/implemented, as it was not need for the encoding and it was not discussed what should it be. More...

#include <agent_id.h>

Inherited by fipa::acl::UndefinedAgentID.

Public Member Functions

bool isValid () const
 
 AgentID ()
 Default constructor. More...
 
 AgentID (const std::string &name)
 Construct an AgentID by name. More...
 
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 More...
 
void setName (const std::string &name)
 the method checks whether the passed name string is a word or not(according to the fipa spec) More...
 
void addAddress (const std::string &adr)
 the method checks whether the passed address string is a word or not(according to the fipa spec) More...
 
const std::vector< std::string > & getAddresses () const
 Retrieve list of addresses. More...
 
void setAddresses (const std::vector< std::string > &addresses)
 Set list of addresses – overwrites existing list of addresses. More...
 
void addResolver (const AgentID &aid)
 Add resolver. More...
 
const ResolversgetResolvers () const
 Get list of resolvers. More...
 
void setResolvers (const Resolvers &resolvers)
 Set list of resolvers. More...
 
void deleteResolver (const AgentID &id)
 Delete a resolver. More...
 
void addUserdefParam (const UserdefParam &p)
 Add a userdefined parameter. More...
 
const std::vector< UserdefParam > & getUserdefParams () const
 Get the all userdefined parameter. More...
 
void setUserdefParams (const std::vector< UserdefParam > &params)
 
bool empty () const
 Check if AgentId is empty, i.e. does not contain a name. More...
 
bool operator== (const AgentID &other) const
 overloaded equality operator for AgentID; the signature of the function was intentionally changed from the normal operator== (const type&, const type&) More...
 
bool operator!= (const AgentID &other) const
 Allow testing on inequality of agents based on the agents' names only. More...
 
bool operator< (const AgentID &other) const
 Allow comparing two agents, based on the agent name only. More...
 
std::string toString (size_t indent=0) const
 

Static Public Member Functions

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 More...
 

Static Public Attributes

static int msResolverComparisonDepth = 1
 

Protected Attributes

std::string mName
 

Static Protected Attributes

static const std::string UNDEFINED = "agent_id:undefined"
 

Friends

class ACLMessage
 

Detailed Description

Implements the general AgentID functionality, which is present throughout the fipa specifications(FIPA at http://www.fipa.org). Functionality may need to be extended as further modules are implemented Important notice: the probably main field of an AgentID, the actual id, is not yet declared/implemented, as it was not need for the encoding and it was not discussed what should it be.

Definition at line 37 of file agent_id.h.

Constructor & Destructor Documentation

◆ AgentID() [1/2]

fipa::acl::AgentID::AgentID ( )

Default constructor.

Definition at line 21 of file agent_id.cpp.

22 {
24 }
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 const std::string UNDEFINED
Definition: agent_id.h:60

◆ AgentID() [2/2]

fipa::acl::AgentID::AgentID ( const std::string &  name)

Construct an AgentID by name.

Parameters
name

Definition at line 26 of file agent_id.cpp.

27 {
28  setName(name);
29 }
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

Member Function Documentation

◆ addAddress()

void fipa::acl::AgentID::addAddress ( const std::string &  adr)

the method checks whether the passed address string is a word or not(according to the fipa spec)

Parameters
adrAddress
Exceptions
ifaddress contains invalid characters

Definition at line 48 of file agent_id.cpp.

49 {
50  if ( (address.find_first_of(illegalWordChars) != std::string::npos) || (illegalWordStart.find_first_of(address.c_str()[0]) != std::string::npos) )
51  {
52  char buffer[128];
53  snprintf(buffer, 128, "fipa::acl::AgentID: address '%s' contains invalid characters", address.c_str());
54  throw std::runtime_error(buffer);
55  }
56  mAddresses.push_back(address);
57 }
const std::string illegalWordStart
Definition: acl_message.cpp:40
const std::string illegalWordChars
Definition: acl_message.cpp:39

◆ addResolver()

void fipa::acl::AgentID::addResolver ( const AgentID aid)

Add resolver.

Parameters
aidResolver identified by its agentid

Definition at line 59 of file agent_id.cpp.

60 {
61  // prevent entering duplicates
62  // NOTE: this function searches for the resolver and uses the overloaded == op not the compareEqual()
63  if ( find(mResolvers.begin(), mResolvers.end(),aid) == mResolvers.end() )
64  {
65  mResolvers.push_back(aid);
66  }
67 }

◆ addUserdefParam()

void fipa::acl::AgentID::addUserdefParam ( const UserdefParam p)

Add a userdefined parameter.

Parameters
pThe userdefined parameter

Definition at line 80 of file agent_id.cpp.

81 {
82  mParameters.push_back(p);
83 }

◆ compareEqual()

bool fipa::acl::AgentID::compareEqual ( const AgentID a,
const AgentID b,
int  depth 
)
static

alternative function for equality operator; the depth can be specified through the depth param

Definition at line 90 of file agent_id.cpp.

91 {
92  if (a.getName() != b.getName())
93  {
94  return false;
95  }
96 
97  // comparing addresses
98  std::vector<std::string> addrA = a.getAddresses();
99  std::vector<std::string> addrB = b.getAddresses();
100  std::vector<std::string>::iterator sita = addrA.begin();
101  std::vector<std::string>::iterator sitb = addrB.begin();
102  int found_one = 0; // flag variable to control flow through inner loops
103  while (sita != addrA.end())
104  {
105  found_one = 0;
106  sitb = addrB.begin();
107  while (sitb != addrB.end())
108  {
109  if (*sita == *sitb)
110  {
111  addrA.erase(sita);
112  sita = addrA.begin();
113  addrB.erase(sitb);
114  sitb = addrB.end();
115  found_one = 1;
116  } else {
117  sitb++;
118  }
119  }
120 
121  if (!found_one)
122  sita++;
123  }
124 
125  if (!addrA.empty())
126  return false;
127  if (!addrB.empty())
128  return false;
129 
130  // only check the resolvers if the resCompDepth > 0;
131  if (depth > 0 )
132  {
133  // the resolvers are compared with up to resCompDepth -1 in the resolver network
134  //AgentID::setResCompDepth(depth-1);
135  // comparing resolvers
136  std::vector<AgentID> agentsA = a.getResolvers();
137  std::vector<AgentID> agentsB = b.getResolvers();
138  std::vector<AgentID>::iterator ait = agentsA.begin();
139  std::vector<AgentID>::iterator bit = agentsB.begin();
140 
141  while (ait != agentsA.end())
142  {
143  found_one = 0;
144  bit = agentsB.begin();
145  while (bit != agentsB.end())
146  {
147  if ( compareEqual((*ait),(*bit),depth-1))
148  {
149  agentsA.erase(ait);
150  ait = agentsA.begin();
151  agentsB.erase(bit);
152  bit = agentsB.end();
153  found_one = 1;
154  } else {
155  ++bit;
156  }
157  }
158  if (!found_one)
159  ++ait;
160  }
161 
162  if (!agentsA.empty())
163  return false;
164  if (!agentsB.empty())
165  return false;
166  }
167 
168  // comparing userdefined parameters
169  // Copy lists and delete identical elements
170  // When both list are empty the compared objects are equal
171  std::vector<UserdefParam> paramsA = a.getUserdefParams();
172  std::vector<UserdefParam> paramsB = b.getUserdefParams();
173  std::vector<UserdefParam>::iterator pita = paramsA.begin();
174  std::vector<UserdefParam>::iterator pitb = paramsB.begin();
175 
176  while (pita != paramsA.end())
177  {
178  found_one = 0;
179  pitb = paramsB.begin();
180 
181  while (pitb != paramsB.end())
182  {
183  if (*pita == *pitb)
184  {
185  paramsA.erase(pita);
186  paramsB.erase(pitb);
187 
188  pita = paramsA.begin();
189  // in order to break the inner while, set it to end()
190  pitb = paramsB.end();
191 
192  found_one = 1;
193  } else {
194  pitb++;
195  }
196  }
197 
198  if (!found_one)
199  pita++;
200  }
201 
202  // Both lists are empty when they contained the same Parameters
203  // before
204  if ( paramsA.empty() && paramsB.empty())
205  return true;
206 
207  return false;
208 }
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

◆ deleteResolver()

void fipa::acl::AgentID::deleteResolver ( const AgentID id)

Delete a resolver.

Parameters
idResolver to delete

Definition at line 69 of file agent_id.cpp.

70 {
71  std::vector<AgentID>::iterator it = find(mResolvers.begin(), mResolvers.end(),aid);
72  // prevent entering duplicates
73  // NOTE: this function searches for the resolver using the overloaded == op not the compareEqual()
74  if( it != mResolvers.end() )
75  {
76  mResolvers.erase(it);
77  }
78 }

◆ empty()

bool fipa::acl::AgentID::empty ( ) const

Check if AgentId is empty, i.e. does not contain a name.

Returns
True, if empty, False otherwise

Definition at line 210 of file agent_id.cpp.

211 {
212  return mName.empty();
213 }
std::string mName
Definition: agent_id.h:57

◆ getAddresses()

const std::vector<std::string>& fipa::acl::AgentID::getAddresses ( ) const
inline

Retrieve list of addresses.

Returns
List of addresses

Definition at line 110 of file agent_id.h.

110 { return mAddresses; }

◆ getName()

const std::string& fipa::acl::AgentID::getName ( ) const
inline

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 at line 90 of file agent_id.h.

90 { return mName; }
std::string mName
Definition: agent_id.h:57

◆ getResolvers()

const Resolvers& fipa::acl::AgentID::getResolvers ( ) const
inline

Get list of resolvers.

Returns
list of resolvers, i.e. agentids

Definition at line 127 of file agent_id.h.

127 { return mResolvers; }

◆ getUserdefParams()

const std::vector<UserdefParam>& fipa::acl::AgentID::getUserdefParams ( ) const
inline

Get the all userdefined parameter.

Returns
List of userdefined parameters

Definition at line 150 of file agent_id.h.

150 { return mParameters; }

◆ isValid()

bool fipa::acl::AgentID::isValid ( ) const

Test if this is a valid agent, i.e. is neither an instance of an undefined agent nor has it an empty name field

Definition at line 31 of file agent_id.cpp.

32 {
33  return mName != AgentID::UNDEFINED && !empty();
34 }
std::string mName
Definition: agent_id.h:57
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

◆ operator!=()

bool fipa::acl::AgentID::operator!= ( const AgentID other) const
inline

Allow testing on inequality of agents based on the agents' names only.

Returns
true if the agents' names are different, false otherwise

Definition at line 179 of file agent_id.h.

179 { return !(*this == other); }

◆ operator<()

bool fipa::acl::AgentID::operator< ( const AgentID other) const
inline

Allow comparing two agents, based on the agent name only.

Returns
True if first agent's name < other agent's name

Definition at line 185 of file agent_id.h.

185 { return this->getName() < other.getName(); }
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

◆ operator==()

bool fipa::acl::AgentID::operator== ( const AgentID other) const

overloaded equality operator for AgentID; the signature of the function was intentionally changed from the normal operator== (const type&, const type&)

The parameters are not passed by reference on purpose so that the copy constructor of the class is called. This is necessary because in the comparison, pointer fields are modified(removed) and we don't want this to affect the original object

Definition at line 85 of file agent_id.cpp.

86 {
88 }
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
static int msResolverComparisonDepth
Definition: agent_id.h:65

◆ setAddresses()

void fipa::acl::AgentID::setAddresses ( const std::vector< std::string > &  addresses)
inline

Set list of addresses – overwrites existing list of addresses.

Definition at line 115 of file agent_id.h.

115 { mAddresses = addresses; }

◆ setName()

void fipa::acl::AgentID::setName ( const std::string &  name)

the method checks whether the passed name string is a word or not(according to the fipa spec)

Parameters
nameName
Exceptions
ifname contains invalid characters

Definition at line 36 of file agent_id.cpp.

37 {
38  if ( (name.find_first_of(illegalWordChars) != std::string::npos) || (illegalWordStart.find_first_of(name.c_str()[0]) != std::string::npos) )
39  {
40  char buffer[128];
41  snprintf(buffer, 128, "fipa::acl::AgentID: name '%s' contains invalid characters", name.c_str());
42  throw std::runtime_error(buffer);
43  }
44 
45  mName = name;
46 }
std::string mName
Definition: agent_id.h:57
const std::string illegalWordStart
Definition: acl_message.cpp:40
const std::string illegalWordChars
Definition: acl_message.cpp:39

◆ setResolvers()

void fipa::acl::AgentID::setResolvers ( const Resolvers resolvers)
inline

Set list of resolvers.

Definition at line 132 of file agent_id.h.

132 { mResolvers = resolvers; }

◆ setUserdefParams()

void fipa::acl::AgentID::setUserdefParams ( const std::vector< UserdefParam > &  params)
inline

Set all userdefined parameters

Definition at line 155 of file agent_id.h.

155 { mParameters = params; }

◆ toString()

std::string fipa::acl::AgentID::toString ( size_t  indent = 0) const

Stringify object

Returns
string representation of agent id

Definition at line 215 of file agent_id.cpp.

216 {
217  std::string hspace(indent,' ');
218  std::stringstream ss;
219  ss << hspace << "AgentID: " << mName << std::endl;
220  ss << hspace << " addresses:" << std::endl;
221  std::vector<std::string>::const_iterator ait = mAddresses.begin();
222  for(; ait != mAddresses.end(); ++ait)
223  {
224  ss << hspace << *ait << std::endl;
225  }
226  ss << hspace << " resolvers:" << std::endl;
227  AgentIDList::const_iterator rit = mResolvers.begin();
228  for(; rit != mResolvers.end(); ++rit)
229  {
230  ss << rit->toString(indent + 4) << std::endl;
231  }
232  ss << hspace << " parameters:" << std::endl;
233  std::vector<UserdefParam>::const_iterator pit = mParameters.begin();
234  for(; pit != mParameters.end(); ++pit)
235  {
236  ss << hspace << pit->toString() << std::endl;
237  }
238  return ss.str();
239 }
std::string mName
Definition: agent_id.h:57

Friends And Related Function Documentation

◆ ACLMessage

friend class ACLMessage
friend

Definition at line 39 of file agent_id.h.

Member Data Documentation

◆ mName

std::string fipa::acl::AgentID::mName
protected

name of the agent

Definition at line 57 of file agent_id.h.

◆ msResolverComparisonDepth

int fipa::acl::AgentID::msResolverComparisonDepth = 1
static

Definition at line 65 of file agent_id.h.

◆ UNDEFINED

const std::string fipa::acl::AgentID::UNDEFINED = "agent_id:undefined"
staticprotected

name representing an undefined agent

Definition at line 60 of file agent_id.h.


The documentation for this class was generated from the following files: