Goby v2
dynamic_moos_vars.h
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 // Community contributors (see AUTHORS file)
5 //
6 //
7 // This file is part of the Goby Underwater Autonomy Project Libraries
8 // ("The Goby Libraries").
9 //
10 // The Goby Libraries are free software: you can redistribute them and/or modify
11 // them under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 2.1 of the License, or
13 // (at your option) any later version.
14 //
15 // The Goby Libraries are distributed in the hope that they will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
22 
23 #ifndef DYNAMICMOOSVARSH
24 #define DYNAMICMOOSVARSH
25 
26 #include "goby/moos/moos_header.h"
27 
28 namespace goby
29 {
30 namespace moos
31 {
33 {
34  public:
35  const CMOOSMsg& get_moos_var(const std::string& s) { return vars[s]; }
36 
37  const CMOOSMsg& operator[](const std::string& s) { return vars[s]; }
38 
39  // read the whole list
40  void update_moos_vars(const MOOSMSG_LIST& NewMail)
41  {
42  for (MOOSMSG_LIST::const_iterator p = NewMail.begin(), n = NewMail.end(); p != n; ++p)
43  vars[p->GetKey()] = *p;
44  }
45 
46  // update a single variable at a time
47  void update_moos_vars(const CMOOSMsg& msg) { vars[msg.GetKey()] = msg; }
48 
49  std::map<std::string, CMOOSMsg>& all() { return vars; }
50 
51  private:
52  std::map<std::string, CMOOSMsg> vars;
53 };
54 } // namespace moos
55 } // namespace goby
56 
57 inline bool valid(const CMOOSMsg& m) { return m.GetTime() != -1; }
58 
59 #endif
The global namespace for the Goby project.