~tes/goby/2.0-drc

« back to all changes in this revision

Viewing changes to src/moos/frontseat/frontseat_exception.h

  • Committer: Toby Schneider
  • Date: 2014-04-22 20:34:48 UTC
  • mfrom: (458.1.81 2.0)
  • Revision ID: tes.aubergine@gmail.com-20140422203448-e1yw2rdhtugywj8z
MergeĀ fromĀ 2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2009-2014 Toby Schneider (https://launchpad.net/~tes)
 
2
//                     GobySoft, LLC (2013-)
 
3
//                     Massachusetts Institute of Technology (2007-2014)
 
4
//                     Goby Developers Team (https://launchpad.net/~goby-dev)
 
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
 
 
24
#ifndef FrontSeatException20130221H
 
25
#define FrontSeatException20130221H
 
26
 
 
27
class FrontSeatException : std::runtime_error
 
28
{
 
29
  public:
 
30
    FrontSeatException()
 
31
        : std::runtime_error("Unknown FrontSeatException"),
 
32
        helm_err_(goby::moos::protobuf::ERROR_HELM_NONE),
 
33
        is_helm_error_(false),
 
34
        fs_err_(goby::moos::protobuf::ERROR_FRONTSEAT_NONE),
 
35
        is_fs_error_(false)
 
36
        { }
 
37
    
 
38
    FrontSeatException(goby::moos::protobuf::HelmError err)
 
39
        : std::runtime_error(goby::moos::protobuf::HelmError_Name(err)),
 
40
        helm_err_(err),
 
41
        is_helm_error_(true),
 
42
        fs_err_(goby::moos::protobuf::ERROR_FRONTSEAT_NONE),
 
43
        is_fs_error_(false)
 
44
    { }
 
45
    FrontSeatException(goby::moos::protobuf::FrontSeatError err)
 
46
        : std::runtime_error(goby::moos::protobuf::FrontSeatError_Name(err)),
 
47
        helm_err_(goby::moos::protobuf::ERROR_HELM_NONE),
 
48
        is_helm_error_(false),
 
49
        fs_err_(err),
 
50
        is_fs_error_(true)
 
51
 
 
52
    { }
 
53
 
 
54
    goby::moos::protobuf::HelmError helm_err() const { return helm_err_; }
 
55
    bool is_helm_error() const { return is_helm_error_; }
 
56
    
 
57
    goby::moos::protobuf::FrontSeatError fs_err() const { return fs_err_; }
 
58
    bool is_fs_error() const { return is_fs_error_; }
 
59
    
 
60
  private:
 
61
    goby::moos::protobuf::HelmError helm_err_;
 
62
    bool is_helm_error_;
 
63
    
 
64
    goby::moos::protobuf::FrontSeatError fs_err_;
 
65
    bool is_fs_error_;
 
66
};
 
67
 
 
68
inline std::ostream& operator<< (std::ostream& os, const FrontSeatException& e)
 
69
{
 
70
    if(e.is_helm_error())
 
71
        os << "Error in the Helm: " << goby::moos::protobuf::HelmError_Name(e.helm_err());
 
72
    else if(e.is_fs_error())
 
73
        os <<  "Error in the Frontseat: " << goby::moos::protobuf::FrontSeatError_Name(e.fs_err());
 
74
    else
 
75
        os << "Unknown error.";
 
76
    return os;
 
77
};
 
78
 
 
79
#endif