mavtables  0.2.1
MAVLink router and firewall.
Rule.cpp
Go to the documentation of this file.
1 // MAVLink router and firewall.
2 // Copyright (C) 2018 Michael R. Shannon <mrshannon.aerospace@gmail.com>
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 
18 #include <optional>
19 #include <ostream>
20 #include <utility>
21 
22 #include "Rule.hpp"
23 
24 
25 /** Base constructor for Rule classes.
26  *
27  * \param condition The condition used to determine if the rule matches a
28  * particular packet/address combination given to the \ref action method.
29  * The default is {} which indicates the rule matches any packet/address
30  * combination.
31  * \sa action
32  */
33 Rule::Rule(std::optional<If> condition)
34  : condition_(std::move(condition))
35 {
36 }
37 
38 
39 // GCC generates a seemingly uncallable destructor for pure virtual classes.
40 // Therefore, it must be excluded from test coverage.
41 // LCOV_EXCL_START
43 {
44 }
45 // LCOV_EXCL_STOP
46 
47 
48 /** Print the given rule to the given output stream.
49  *
50  * \note This is a polymorphic print, it will work on any child of \ref Rule
51  * even if the pointer/reference is to the base class \ref Rule.
52  *
53  * Some examples are:
54  * - `accept`
55  * - `accept with priority 3`
56  * - `reject if ENCAPSULATED_DATA`
57  * - `call gcs_in if from 192.168`
58  * - `goto autopilot_out`
59  *
60  * \relates Rule
61  * \param os The output stream to print to.
62  * \param rule The rule (or any child of \ref Rule) to print.
63  * \returns The output stream.
64  */
65 std::ostream &operator<<(std::ostream &os, const Rule &rule)
66 {
67  return rule.print_(os);
68 }
STL namespace.
std::ostream & operator<<(std::ostream &os, const Action &action)
Definition: Action.cpp:188
Definition: Rule.hpp:38
virtual std::ostream & print_(std::ostream &os) const =0
virtual ~Rule()
Definition: Rule.cpp:42
Rule(std::optional< If > condition={})
Definition: Rule.cpp:33
Rule & rule
Definition: test_Call.cpp:231