fipa_acl  1.4
string_message_format.cpp
Go to the documentation of this file.
2 #include "string_format.h"
3 
4 #include <sstream>
5 #include <boost/algorithm/string.hpp>
6 
7 namespace fipa {
8 namespace acl {
9 
10 
11 std::string StringMessageFormat::apply(const ACLMessage& aclMsg) const
12 {
13  using namespace MessageField;
14 
15  std::string msg = "(";
16  msg += aclMsg.getPerformative();
17 
18  const AgentID& sender = aclMsg.getSender();
19  if(sender.isValid())
20  {
22  }
23 
24  const AgentIDList& receivers = aclMsg.getAllReceivers();
25  if(!receivers.empty())
26  {
28  }
29 
30  if(!aclMsg.getContentPtr()->empty())
31  {
32  size_t size = aclMsg.getContentPtr()->size();
33  std::stringstream ss;
34  ss << size;
35 
37  }
38 
39  const std::string& replyWith = aclMsg.getReplyWith();
40  if(!replyWith.empty())
41  {
42  msg += ":" + MessageFieldTxt[REPLY_WITH] + StringFormat::getExpression(replyWith);
43  }
44 
45 
46  base::Time replyBy = aclMsg.getReplyBy();
47  if(!replyBy.isNull())
48  {
49  std::string replyByString = replyBy.toString(base::Time::Milliseconds, "%Y%m%dT%H%M%S");
50  boost::erase_all(replyByString,":");
51 
52  msg += ":" + MessageFieldTxt[REPLY_BY] + replyByString;
53  }
54 
55  const std::string& inReplyTo = aclMsg.getInReplyTo();
56  if(!inReplyTo.empty())
57  {
58  msg += ":" + MessageFieldTxt[IN_REPLY_TO] + StringFormat::getExpression(inReplyTo);
59  }
60 
61  const AgentIDList& replyTo = aclMsg.getAllReplyTo();
62  if(!replyTo.empty())
63  {
65  }
66 
67  const std::string& language = aclMsg.getLanguage();
68  if(!language.empty())
69  {
70  msg += ":" + MessageFieldTxt[LANGUAGE] + StringFormat::getExpression(language);
71  }
72 
73  const std::string& encoding = aclMsg.getEncoding();
74  if(!encoding.empty())
75  {
76  msg += ":" + MessageFieldTxt[ENCODING] + StringFormat::getExpression(encoding);
77  }
78 
79  const std::string& ontology = aclMsg.getOntology();
80  if(!ontology.empty())
81  {
82  msg += ":" + MessageFieldTxt[ONTOLOGY] + StringFormat::getExpression(ontology);
83  }
84 
85  const std::string& protocol = aclMsg.getProtocol();
86  if(!protocol.empty())
87  {
88  msg += ":" + MessageFieldTxt[PROTOCOL] + StringFormat::getWord(protocol);
89  }
90 
91  const std::string& conversationId = aclMsg.getConversationID();
92  if(!conversationId.empty())
93  {
94  msg += ":" + MessageFieldTxt[CONVERSATION_ID] + StringFormat::getExpression(conversationId);
95  }
96 
97  const std::vector<fipa::acl::UserdefParam>& parameters = aclMsg.getUserdefParams();
98  std::vector<fipa::acl::UserdefParam>::const_iterator cit = parameters.begin();
99  for(; cit != parameters.end(); ++cit)
100  {
101  // As user defined parameters are Words, they can contain spaces and it is not clear,
102  // where the actual parameter starts. Therefore, we use parentheses around the expression.
103  msg += ":X-" + cit->getName() + "(" + StringFormat::getExpression(cit->getValue()) + ")";
104  }
105  msg += ")";
106 
107  return msg;
108 }
109 
110 
111 } // end namespace acl
112 } // end namespace fipa
std::string getEncoding() const
Definition: acl_message.h:258
std::vector< UserdefParam > getUserdefParams() const
Definition: acl_message.h:323
static std::string getAgentIdentifierSet(const AgentIDList &agentList)
base::Time getReplyBy() const
Definition: acl_message.h:334
std::string getPerformative() const
Definition: acl_message.h:139
std::map< MessageField::Type, std::string > MessageFieldTxt
static std::string getExpression(const std::string &txt)
Definition: string_format.h:37
std::string getReplyWith() const
Definition: acl_message.h:217
static std::string getAgentIdentifier(const AgentID &agentID)
std::vector< AgentID > AgentIDList
Definition: agent_id.h:20
std::string getOntology() const
Definition: acl_message.h:248
AgentIDList getAllReplyTo() const
Definition: acl_message.h:192
bool isValid() const
Definition: agent_id.cpp:31
const std::string * getContentPtr() const
Definition: acl_message.h:299
std::string getLanguage() const
Definition: acl_message.h:268
std::string getInReplyTo() const
Definition: acl_message.h:207
std::string apply(const ACLMessage &msg) const
AgentID getSender() const
Definition: acl_message.h:311
std::string getProtocol() const
Definition: acl_message.h:238
This class provides a representation of a message conforming to the FIPA specification SC00061...
Definition: acl_message.h:55
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
static std::string getString(const std::string &txt)
AgentIDList getAllReceivers() const
Definition: acl_message.h:166
std::string getConversationID() const
Definition: acl_message.h:227
static std::string getWord(const std::string &txt)
Definition: string_format.h:39