fipa_acl  1.4
string_format.cpp
Go to the documentation of this file.
1 #include "string_format.h"
2 #include <sstream>
3 
4 namespace fipa {
5 namespace acl {
6 
7 std::string StringFormat::getAgentIdentifier(const AgentID& agent)
8 {
9  std::string agentTxt = "(agent-identifier";
10  agentTxt += ":name" + getWord(agent.getName());
11  if(!agent.getAddresses().empty())
12  {
13  agentTxt += ":addresses" + getUrlSequence(agent.getAddresses());
14  }
15  if(!agent.getResolvers().empty())
16  {
17  agentTxt += ":resolvers" + getAgentIdentifierSequence(agent.getResolvers());
18  }
19 
20  std::vector<UserdefParam>::const_iterator cit = agent.getUserdefParams().begin();
21  for(; cit != agent.getUserdefParams().end(); ++cit)
22  {
23  agentTxt += getUserdefinedParameter(cit->getName());
24  agentTxt += getExpression(cit->getValue());
25  }
26  agentTxt += ")";
27 
28  return agentTxt;
29 }
30 
32 {
33  std::string list = "(sequence";
34  list += getAgentIdentifierList(agentList);
35  list += ")";
36  return list;
37 }
38 
39 std::string StringFormat::getAgentIdentifierSet(const AgentIDList& agentList)
40 {
41  std::string list = "(set";
42  list += getAgentIdentifierList(agentList);
43  list += ")";
44  return list;
45 }
46 
48 {
49  std::string list = "";
50  AgentIDList::const_iterator cit = agentList.begin();
51  for(; cit != agentList.end(); ++cit)
52  {
53  list += getAgentIdentifier(*cit);
54  }
55  return list;
56 }
57 
58 std::string StringFormat::getUrlSequence(const Addresses& addresses)
59 {
60  std::string sequence = "(sequence";
61  Addresses::const_iterator cit = addresses.begin();
62  for(; cit != addresses.end(); ++cit)
63  {
64  // For ease of parsing, separate URLs with a space
65  sequence += getUrl(*cit) + " ";
66  }
67  sequence += ")";
68  return sequence;
69 }
70 
71 std::string StringFormat::getString(const std::string& txt)
72 {
73  size_t size = txt.size();
74  std::stringstream ss;
75  ss << "#" << size << "\"" << txt;
76 
77  return ss.str();
78 }
79 
80 
81 } // end namespace acl
82 } // end namespace fipa
static std::string getUrl(const std::string &url)
Definition: string_format.h:45
static std::string getAgentIdentifierList(const AgentIDList &agentList)
static std::string getAgentIdentifierSequence(const AgentIDList &agentList)
static std::string getUrlSequence(const Addresses &addresses)
static std::string getAgentIdentifierSet(const AgentIDList &agentList)
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
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
const std::vector< std::string > & getAddresses() const
Retrieve list of addresses.
Definition: agent_id.h:110
const std::vector< UserdefParam > & getUserdefParams() const
Get the all userdefined parameter.
Definition: agent_id.h:150
std::vector< std::string > Addresses
Definition: agent_id.h:28
const Resolvers & getResolvers() const
Get list of resolvers.
Definition: agent_id.h:127
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 getUserdefinedParameter(const std::string &param)
Definition: string_format.h:43
static std::string getString(const std::string &txt)
static std::string getWord(const std::string &txt)
Definition: string_format.h:39