23 #include <boost/foreach.hpp> 25 #include "goby/acomms/dccl.h" 27 #include "message_publish.h" 29 void goby::transitional::DCCLPublish::initialize(
const DCCLMessage& msg)
31 repeat_ = msg.repeat();
34 BOOST_FOREACH (
const std::string& name, names_)
35 add_message_var(msg.name2message_var(name));
37 BOOST_FOREACH (const
std::vector<
std::
string>& algs, algorithms_)
39 BOOST_FOREACH (
const std::string& alg, algs)
40 ap_->check_algorithm(alg, msg);
46 BOOST_FOREACH (
const boost::shared_ptr<DCCLMessageVar> mv, msg.header_const())
49 if (!mv->name().empty() && !(mv->name()[0] ==
'_') &&
50 !std::count(names_.begin(), names_.end(), mv->name()))
54 add_algorithms(std::vector<std::string>());
58 BOOST_FOREACH (
const boost::shared_ptr<DCCLMessageVar> mv, msg.layout_const())
60 if (!std::count(names_.begin(), names_.end(), mv->name()))
64 add_algorithms(std::vector<std::string>());
73 std::string format_str;
74 for (std::vector<boost::shared_ptr<DCCLMessageVar> >::size_type j = 0,
75 m = message_vars_.size();
84 unsigned size = algorithms_[j].size();
85 if (count(message_vars_.begin(), message_vars_.end(), message_vars_[j]) > 1 && size)
87 for (
unsigned i = 0; i < size; ++i) format_str += algorithms_[j][i];
89 format_str +=
"(" + message_vars_[j]->name() +
")=";
92 format_str += message_vars_[j]->name() +
"=";
95 for (
unsigned i = 0, n = (repeat_ > 1) ? 1 : message_vars_[j]->array_length(); i < n;
101 if (m > 1 && n > 1 && i == 0)
106 ss <<
"%" << format_count <<
"%";
108 if (m > 1 && n > 1 && i + 1 == n)
110 format_str += ss.str();
113 format_ = format_str;