fipa_acl  1.4
Public Member Functions | List of all members
fipa::acl::StringMessageFormat Class Reference

#include <string_message_format.h>

Inherits fipa::acl::MessageFormat.

Public Member Functions

virtual ~StringMessageFormat ()
 
std::string apply (const ACLMessage &msg) const
 
- Public Member Functions inherited from fipa::acl::MessageFormat
 MessageFormat ()
 
virtual ~MessageFormat ()
 
void setUseCodeTables (bool x)
 
bool getUseCodeTables () const
 
void setUpdateCodeTables (bool x)
 
bool getUpdateCodeTables () const
 
void setResolverDepth (int depth)
 
int getResolverDepth () const
 
void setVersion (const std::string &version)
 
std::string getVersion () const
 

Detailed Description

Definition at line 8 of file string_message_format.h.

Constructor & Destructor Documentation

virtual fipa::acl::StringMessageFormat::~StringMessageFormat ( )
inlinevirtual

Definition at line 11 of file string_message_format.h.

11 {}

Member Function Documentation

std::string fipa::acl::StringMessageFormat::apply ( const ACLMessage msg) const
virtual

Applies the string format to the message

Returns
the formatted message

Implements fipa::acl::MessageFormat.

Definition at line 11 of file string_message_format.cpp.

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 
36  msg += ":" + MessageFieldTxt[CONTENT] + StringFormat::getString(*aclMsg.getContentPtr());
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 }
static std::string getAgentIdentifierSet(const AgentIDList &agentList)
std::map< MessageField::Type, std::string > MessageFieldTxt
static std::string getExpression(const std::string &txt)
Definition: string_format.h:37
static std::string getAgentIdentifier(const AgentID &agentID)
std::vector< AgentID > AgentIDList
Definition: agent_id.h:20
static std::string getString(const std::string &txt)
static std::string getWord(const std::string &txt)
Definition: string_format.h:39

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