Goby v2
frontseat_exception.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 FrontSeatException20130221H
24 #define FrontSeatException20130221H
25 
26 #include "goby/moos/protobuf/frontseat.pb.h"
27 
28 class FrontSeatException : std::runtime_error
29 {
30  public:
32  : std::runtime_error("Unknown FrontSeatException"),
33  helm_err_(goby::moos::protobuf::ERROR_HELM_NONE), is_helm_error_(false),
34  fs_err_(goby::moos::protobuf::ERROR_FRONTSEAT_NONE), is_fs_error_(false)
35  {
36  }
37 
38  FrontSeatException(goby::moos::protobuf::HelmError err)
39  : std::runtime_error(goby::moos::protobuf::HelmError_Name(err)), helm_err_(err),
40  is_helm_error_(true), fs_err_(goby::moos::protobuf::ERROR_FRONTSEAT_NONE),
41  is_fs_error_(false)
42  {
43  }
44  FrontSeatException(goby::moos::protobuf::FrontSeatError err)
45  : std::runtime_error(goby::moos::protobuf::FrontSeatError_Name(err)),
46  helm_err_(goby::moos::protobuf::ERROR_HELM_NONE), is_helm_error_(false), fs_err_(err),
47  is_fs_error_(true)
48 
49  {
50  }
51 
52  goby::moos::protobuf::HelmError helm_err() const { return helm_err_; }
53  bool is_helm_error() const { return is_helm_error_; }
54 
55  goby::moos::protobuf::FrontSeatError fs_err() const { return fs_err_; }
56  bool is_fs_error() const { return is_fs_error_; }
57 
58  private:
59  goby::moos::protobuf::HelmError helm_err_;
60  bool is_helm_error_;
61 
62  goby::moos::protobuf::FrontSeatError fs_err_;
63  bool is_fs_error_;
64 };
65 
66 inline std::ostream& operator<<(std::ostream& os, const FrontSeatException& e)
67 {
68  if (e.is_helm_error())
69  os << "Error in the Helm: " << goby::moos::protobuf::HelmError_Name(e.helm_err());
70  else if (e.is_fs_error())
71  os << "Error in the Frontseat: " << goby::moos::protobuf::FrontSeatError_Name(e.fs_err());
72  else
73  os << "Unknown error.";
74  return os;
75 };
76 
77 #endif