6 #include <boost/assign/list_of.hpp> 7 #include <boost/date_time.hpp> 8 #include <boost/foreach.hpp> 15 std::map<ACLMessage::Performative, std::string>
PerformativeTxt = boost::assign::map_list_of
44 std::map<ACLMessage::Performative, std::string>::const_iterator it = PerformativeTxt.begin();
45 for(; it != PerformativeTxt.end(); ++it)
47 if(it->second == performative)
52 std::string msg =
"String '" + performative +
"' does not match any existing performative definition";
53 throw std::runtime_error(msg);
58 mPerformative = PerformativeTxt[
INFORM];
63 mPerformative = PerformativeTxt[performative];
68 if ( (perf.find_first_of(illegalWordChars) != std::string::npos) || (illegalWordStart.find_first_of(perf.c_str()[0]) != std::string::npos) )
71 snprintf(buffer, 512,
"Illegal characters in given performative: %s", perf.c_str());
72 throw std::runtime_error(buffer);
123 std::map<Performative, std::string>::iterator it;
124 it = PerformativeTxt.find(perf);
125 if(it == PerformativeTxt.end())
127 throw std::runtime_error(
"Cannot set performative. Performative unknown");
130 mPerformative = it->second;
135 if ( (str.find_first_of(illegalWordChars) != std::string::npos) || (illegalWordStart.find_first_of(str.c_str()[0]) != std::string::npos) )
139 snprintf(buffer, 512,
"Illegal characters in given performative: %s", str.c_str());
140 throw std::runtime_error(buffer);
150 if ( find(mReceivers.begin(), mReceivers.end(),aid) == mReceivers.end() )
152 mReceivers.insert(mReceivers.begin(),aid);
160 std::vector<AgentID>::iterator it = find(mReceivers.begin(), mReceivers.end(),aid);
161 if ( it != mReceivers.end())
163 mReceivers.erase(it);
176 if ( find(mReplyTo.begin(), mReplyTo.end(),aid) == mReplyTo.end() )
178 mReplyTo.insert(mReplyTo.begin(),aid);
186 std::vector<AgentID>::iterator it = find(mReplyTo.begin(), mReplyTo.end(),aid);
187 if (it != mReplyTo.end() )
200 if ( (str.find_first_of(illegalWordChars) != std::string::npos) || (illegalWordStart.find_first_of(str.c_str()[0]) != std::string::npos) )
203 snprintf(buffer, 512,
"Protocol name contains illegal characters: %s", str.c_str());
204 throw std::runtime_error(buffer);
213 return ( strlen(mContent.c_str()) != mContent.size() );
218 if (find (mParameters.begin(),mParameters.end(),p) == mParameters.end() )
220 mParameters.insert(mParameters.begin(),p);
227 mParameters.insert(mParameters.begin(),p.begin(),p.end());
258 AgentIDList::iterator ait = agentsA.begin();
259 AgentIDList::iterator bit = agentsB.begin();
263 while (ait != agentsA.end())
266 bit = agentsB.begin();
267 while (bit != agentsB.end())
272 ait = agentsA.begin();
288 if (!agentsA.empty() || !agentsB.empty())
294 ait = agentsA.begin();
295 bit = agentsB.begin();
296 while (ait != agentsA.end())
299 bit = agentsB.begin();
300 while (bit != agentsB.end())
305 ait = agentsA.begin();
320 if (!agentsA.empty())
322 if (!agentsB.empty())
328 std::vector<UserdefParam>::iterator pita = paramsA.begin();
329 std::vector<UserdefParam>::iterator pitb = paramsB.begin();
331 while (pita != paramsA.end())
334 pitb = paramsB.begin();
335 while (pitb != paramsB.end())
340 pita = paramsA.begin();
342 pitb = paramsB.end();
354 if (!paramsA.empty())
357 if (!paramsB.empty())
365 std::stringstream ss;
367 ss << mPerformative << std::endl;
368 ss <<
":sender (agent-identifier :name " << mSender.
getName() <<
" )" << std::endl;
370 if(!mReceivers.empty())
372 ss <<
":receiver (set "<< std::endl;
373 BOOST_FOREACH(
const AgentID& agent, mReceivers)
375 ss <<
"\t(agent-identifier ";
376 ss <<
":name " << agent.
getName();
377 ss <<
") " << std::endl;
379 ss <<
")" << std::endl;
382 if(!mLanguage.empty())
384 ss <<
":language " << mLanguage << std::endl;
387 if(!mEncoding.empty())
389 ss <<
":encoding " << mEncoding << std::endl;
392 if(!mOntology.empty())
394 ss <<
":ontology " << mOntology << std::endl;
397 if(!mProtocol.empty())
399 ss <<
":protocol " << mProtocol << std::endl;
402 if(!mConversationId.empty())
404 ss <<
":conversation-id " << mConversationId << std::endl;
407 if(!mReplyWith.empty())
409 ss <<
":reply-with " << mReplyWith << std::endl;
412 if(!mInReplyTo.empty())
414 ss <<
":in-reply-to " << mInReplyTo << std::endl;
417 if(!mReplyBy.isNull())
419 ss <<
":reply-by " << mReplyBy.toString() << std::endl;
422 if(!mParameters.empty())
430 if(!mContent.empty())
432 ss <<
":content " << mContent << std::endl;
436 ss <<
")" << std::endl;
const std::string & getValue() const
std::string getLanguage() const
std::string getConversationID() const
const std::string & getName() const
AgentID getSender() const
bool operator==(const ACLMessage &other) const
AgentIDList getAllReplyTo() const
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 ...
std::string toString() const
std::string getContent() const
void setUserdefParams(const std::vector< UserdefParam > &p)
void deleteReplyTo(const AgentID &aid)
std::vector< UserdefParam > getUserdefParams() const
std::string getReplyWith() const
std::vector< AgentID > AgentIDList
void addReplyTo(const AgentID &aid)
bool hasBinaryContent() const
const std::string illegalWordStart
AgentIDList getAllReceivers() const
Performative
an enum of all the predefined fipa message performatives so far, presented in the order used in the m...
std::string getEncoding() const
describes the general data structure of a message in conformity with the fipa specifications. The methods are pretty straight forward getter and setter methods. The set container is used for various colective fields, in order to avoid duplicates
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 addUserdefParam(const UserdefParam &p)
static int msResolverComparisonDepth
std::map< ACLMessage::Performative, std::string > PerformativeTxt
std::string getPerformative() const
This class provides a representation of a message conforming to the FIPA specification SC00061...
static Performative performativeFromString(const std::string &performative)
overloaded equality operator for UserdefParam class objects
void addReceiver(const AgentID &aid)
std::string getInReplyTo() const
void deleteReceiver(const AgentID &aid)
std::string getProtocol() const
void setPerformative(Performative perf)
Set performative.
const std::string illegalWordChars
Implements the general AgentID functionality, which is present throughout the fipa specifications(FIP...
Foundation of Physical Intelligent Agents.
void setProtocol(const std::string &str)
the method checks whether the passed protocol string is a word or not(according to the fipa spec) ...
ACLMessage()
Default constructor.
base::Time getReplyBy() const
std::string getOntology() const