fipa_acl  1.4
message_generator.cpp
Go to the documentation of this file.
1 #include "message_generator.h"
2 #include <stdexcept>
3 #include <boost/assign/list_of.hpp>
4 #include <base-logging/Logging.hpp>
5 
9 
10 namespace fipa {
11 namespace acl {
12 
13 std::map<representation::Type, MessageFormatPtr > MessageGenerator::msFormats = boost::assign::map_list_of
14  (representation::BITEFFICIENT, boost::shared_ptr<MessageFormat>(new BitefficientMessageFormat()))
15  (representation::XML, boost::shared_ptr<MessageFormat>(new XMLMessageFormat()))
16  (representation::STRING_REP, boost::shared_ptr<MessageFormat>(new StringMessageFormat()));
17 
18 std::string MessageGenerator::create(const ACLMessage& msg, const representation::Type& type)
19 {
20  std::map<representation::Type, MessageFormatPtr >::const_iterator it = msFormats.find(type);
21 
22  if( it != msFormats.end())
23  {
24  return it->second->apply(msg);
25  } else
26  {
27  char buffer[512];
28  snprintf(buffer, 512, "Message format of type '%s' is unknown", representation::TypeTxt[type].c_str());
29  LOG_ERROR("%s", buffer);
30  throw std::runtime_error(buffer);
31  }
32 }
33 
34 } // end namespace acl
35 } // end namespace fipa
static std::string create(const ACLMessage &msg, const representation::Type &acl_representation)
const std::string TypeTxt[]
Definition: types.h:28
This class provides a representation of a message conforming to the FIPA specification SC00061...
Definition: acl_message.h:55
Foundation of Physical Intelligent Agents.
Definition: conversation.cpp:6