4 #include <boost/regex.hpp> 5 #include <base-logging/Logging.hpp> 14 : mId(
Role::UNDEFINED_ID)
44 std::map<Role, AgentIDList>::iterator it = mExpectedAgentMapping.find(
SelfRole());
46 assert(!it->second.empty());
53 std::string msg =
"Self is already set";
55 throw std::runtime_error(msg);
61 std::map<Role, AgentIDList>::const_iterator it = mExpectedAgentMapping.find(
SelfRole());
62 if(it != mExpectedAgentMapping.end())
64 return it->second.front();
75 return getSelf() == id;
80 mExpectedAgentMapping.insert( std::pair<Role, AgentIDList>(role,
AgentIDList()));
85 std::map<Role, AgentIDList>::iterator it = mExpectedAgentMapping.find(role);
86 if(it == mExpectedAgentMapping.end())
88 std::string msg =
"Unexpected role '" + role.
toString() +
"'.";
89 LOG_ERROR(
"%s", msg.c_str());
90 throw std::runtime_error(msg);
94 AgentIDList::iterator eit = std::find(expectedAgents.begin(), expectedAgents.end(), agent);
95 if(eit == expectedAgents.end())
97 expectedAgents.push_back(agent);
105 std::map<Role, AgentIDList>::iterator it = mExpectedAgentMapping.find(role);
106 if(it != mExpectedAgentMapping.end())
114 mExpectedAgentMapping.clear();
124 boost::regex roleRegex(role.
getId());
125 if(regex_match(agent.
getName(), roleRegex))
130 const AgentIDList& expectedAgents = getExpectedAgents(role);
132 bool expected =
false;
134 if(expectedAgents.empty())
140 AgentIDList::const_iterator eit = expectedAgents.begin();
141 for(; eit != expectedAgents.end(); ++eit)
143 boost::regex regex(eit->getName() +
"$");
144 if(regex_match(agent.
getName(), regex))
155 std::map<Role, AgentIDList>::const_iterator it = mExpectedAgentMapping.find(role);
156 if(it == mExpectedAgentMapping.end())
158 std::string msg =
"Unexpected role '" + role.
toString() +
"'.";
159 LOG_ERROR(
"%s", msg.c_str());
160 throw std::runtime_error(msg);
167 std::stringstream ss;
168 std::map<Role, AgentIDList>::const_iterator cit = mExpectedAgentMapping.begin();
169 for(; cit != mExpectedAgentMapping.end(); ++cit)
171 ss <<
"'" << cit->first.toString() <<
"': ";
void clearExpectedAgents(const Role &role)
bool isExpected(const Role &role, const AgentID &agent) const
bool isSelf(const AgentID &id) const
void setSelf(const AgentID &id)
std::vector< AgentID > AgentIDList
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
void resetExpectedAgents()
std::string toString() const
void addRole(const Role &role)
std::string toString() const
const AgentIDList & getExpectedAgents(const Role &role) const
static const RoleId UNDEFINED_ID
static const RoleId SELF_ID
void addExpectedAgent(const Role &role, const AgentID &agent)
Implements the general AgentID functionality, which is present throughout the fipa specifications(FIP...
Foundation of Physical Intelligent Agents.