23 #include <boost/foreach.hpp> 25 #include "goby/acomms/dccl.h" 27 #include "message_algorithms.h" 28 #include "message_val.h" 30 #include "goby/util/as.h" 36 goby::transitional::DCCLAlgorithmPerformer::getInstance()
39 inst_ =
new DCCLAlgorithmPerformer();
44 void goby::transitional::DCCLAlgorithmPerformer::deleteInstance() {
delete inst_; }
46 void goby::transitional::DCCLAlgorithmPerformer::algorithm(
47 DCCLMessageVal& in,
unsigned array_index,
const std::string& algorithm,
48 const std::map<std::string, std::vector<DCCLMessageVal> >& vals)
55 std::vector<std::string> ref_vars;
56 std::string algorithm_deblanked = boost::erase_all_copy(algorithm,
" ");
57 boost::split(ref_vars, algorithm_deblanked, boost::is_any_of(
":"));
60 std::vector<DCCLMessageVal> tied_vals;
62 for (std::vector<std::string>::size_type i = 1, n = ref_vars.size(); i < n; ++i)
64 std::map<std::string, std::vector<DCCLMessageVal> >::const_iterator it =
65 vals.find(ref_vars[i]);
68 if (array_index < it->second.size())
69 tied_vals.push_back(it->second[array_index]);
71 tied_vals.push_back(it->second[0]);
75 if (ref_vars.size() > 0)
78 run_algorithm(alg, in, tied_vals);
81 void goby::transitional::DCCLAlgorithmPerformer::run_algorithm(
82 const std::string& algorithm, DCCLMessageVal& in,
const std::vector<DCCLMessageVal>& ref)
85 if (adv_map1_.count(algorithm))
87 adv_map1_.find(algorithm)->second(in);
90 else if (adv_map2_.count(algorithm))
92 adv_map2_.find(algorithm)->second(in, ref);
97 void goby::transitional::DCCLAlgorithmPerformer::check_algorithm(
const std::string& alg,
98 const DCCLMessage& msg)
103 std::vector<std::string> ref_vars;
104 std::string algorithm_deblanked = boost::erase_all_copy(alg,
" ");
105 boost::split(ref_vars, algorithm_deblanked, boost::is_any_of(
":"));
109 if ((adv_map1_.size() || adv_map2_.size()) && !adv_map1_.count(ref_vars.at(0)) &&
110 !adv_map2_.count(ref_vars.at(0)))
111 throw(goby::acomms::DCCLException(
"unknown algorithm defined: " + ref_vars.at(0)));
113 for (std::vector<std::string>::size_type i = 1, n = ref_vars.size(); i < n; ++i)
115 bool ref_found =
false;
116 BOOST_FOREACH (
const boost::shared_ptr<DCCLMessageVar> mv, msg.header_const())
118 if (ref_vars[i] == mv->name())
125 BOOST_FOREACH (
const boost::shared_ptr<DCCLMessageVar> mv, msg.layout_const())
127 if (ref_vars[i] == mv->name())
135 throw(goby::acomms::DCCLException(
136 std::string(
"no such reference message variable " + ref_vars.at(i) +
137 " used in algorithm: " + ref_vars.at(0))));