Goby3  3.1.5
2024.05.14
message_algorithms.h
Go to the documentation of this file.
1 // Copyright 2009-2021:
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 // File authors:
6 // Toby Schneider <toby@gobysoft.org>
7 //
8 //
9 // This file is part of the Goby Underwater Autonomy Project Libraries
10 // ("The Goby Libraries").
11 //
12 // The Goby Libraries are free software: you can redistribute them and/or modify
13 // them under the terms of the GNU Lesser General Public License as published by
14 // the Free Software Foundation, either version 2.1 of the License, or
15 // (at your option) any later version.
16 //
17 // The Goby Libraries are distributed in the hope that they will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public License
23 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef GOBY_MOOS_TRANSITIONAL_MESSAGE_ALGORITHMS_H
26 #define GOBY_MOOS_TRANSITIONAL_MESSAGE_ALGORITHMS_H
27 
28 #include <map> // for map, map<>::mapped_type
29 #include <string> // for string
30 #include <utility> // for move
31 #include <vector> // for vector
32 
33 #include <boost/function.hpp> // for function
34 
35 namespace goby
36 {
37 namespace moos
38 {
39 namespace transitional
40 {
41 class DCCLMessageVal;
42 class DCCLMessage;
43 
47 using AlgFunction1 = boost::function<void(DCCLMessageVal&)>;
51 using AlgFunction2 = boost::function<void(DCCLMessageVal&, const std::vector<DCCLMessageVal>&)>;
52 
54 {
55  public:
57  static void deleteInstance();
58 
59  void algorithm(DCCLMessageVal& in, unsigned array_index, const std::string& algorithm,
60  const std::map<std::string, std::vector<DCCLMessageVal> >& vals);
61 
62  void run_algorithm(const std::string& algorithm, DCCLMessageVal& in,
63  const std::vector<DCCLMessageVal>& ref);
64 
65  void add_algorithm(const std::string& name, AlgFunction1 func)
66  {
67  adv_map1_[name] = std::move(func);
68  }
69 
70  void add_adv_algorithm(const std::string& name, AlgFunction2 func)
71  {
72  adv_map2_[name] = std::move(func);
73  }
74 
75  void check_algorithm(const std::string& alg, const DCCLMessage& msg);
76 
77  private:
78  static DCCLAlgorithmPerformer* inst_;
79  std::map<std::string, AlgFunction1> adv_map1_;
80  std::map<std::string, AlgFunction2> adv_map2_;
81 
82  DCCLAlgorithmPerformer() = default;
83 
85  DCCLAlgorithmPerformer& operator=(const DCCLAlgorithmPerformer&) = delete;
86 };
87 } // namespace transitional
88 } // namespace moos
89 } // namespace goby
90 
91 #endif
goby::moos::transitional::AlgFunction2
boost::function< void(DCCLMessageVal &, const std::vector< DCCLMessageVal > &)> AlgFunction2
boost::function for a function taking a dccl::MessageVal reference, and the MessageVal of a second pa...
Definition: message_algorithms.h:51
goby::moos::transitional::DCCLAlgorithmPerformer
Definition: message_algorithms.h:53
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::moos::transitional::AlgFunction1
boost::function< void(DCCLMessageVal &)> AlgFunction1
boost::function for a function taking a single DCCLMessageVal reference. Used for algorithm callbacks...
Definition: message_algorithms.h:47
goby::moos::transitional::DCCLAlgorithmPerformer::getInstance
static DCCLAlgorithmPerformer * getInstance()
goby::moos::transitional::DCCLAlgorithmPerformer::run_algorithm
void run_algorithm(const std::string &algorithm, DCCLMessageVal &in, const std::vector< DCCLMessageVal > &ref)
goby::moos::transitional::DCCLAlgorithmPerformer::algorithm
void algorithm(DCCLMessageVal &in, unsigned array_index, const std::string &algorithm, const std::map< std::string, std::vector< DCCLMessageVal > > &vals)
detail::void
j template void())
Definition: json.hpp:4822
goby::moos::transitional::DCCLAlgorithmPerformer::add_algorithm
void add_algorithm(const std::string &name, AlgFunction1 func)
Definition: message_algorithms.h:65
goby::moos::transitional::DCCLAlgorithmPerformer::check_algorithm
void check_algorithm(const std::string &alg, const DCCLMessage &msg)
goby::moos::transitional::DCCLMessageVal
defines a DCCL value
Definition: message_val.h:41
goby::msg
extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MessageOptions, ::google::protobuf::internal::MessageTypeTraits< ::goby::GobyMessageOptions >, 11, false > msg
Definition: option_extensions.pb.h:1327
goby::moos::transitional::DCCLAlgorithmPerformer::add_adv_algorithm
void add_adv_algorithm(const std::string &name, AlgFunction2 func)
Definition: message_algorithms.h:70
goby::moos::transitional::DCCLMessage
Definition: message.h:61
goby::moos::transitional::DCCLAlgorithmPerformer::deleteInstance
static void deleteInstance()