24 #include <boost/tokenizer.hpp> 44 std::ostringstream ss;
46 << std::uppercase << std::hex << mask << std::nouppercase
47 <<
") is outside of the allowed range (0x0000 - 0xFFFF).";
48 throw std::out_of_range(ss.str());
69 unsigned int component_mask)
73 if (system_mask > 0xFF)
75 std::ostringstream ss;
76 ss <<
"System mask (0x" 77 << std::uppercase << std::hex << system_mask << std::nouppercase
78 <<
") is outside of the allowed range (0x00 - 0xFF).";
79 throw std::out_of_range(ss.str());
83 if (component_mask > 0xFF)
85 std::ostringstream ss;
86 ss <<
"Component mask (0x" << std::hex << component_mask <<
87 ") is outside of the allowed range (0x00 - 0xFF).";
88 throw std::out_of_range(ss.str());
91 mask_ = ((system_mask << 8) & 0xFF00) | (component_mask & 0x00FF);
171 catch (std::exception)
177 std::vector<std::string> parts;
178 boost::char_separator<char> sep(
"",
":/\\");
179 boost::tokenizer<boost::char_separator<char>> tokens(subnet, sep);
181 for (
auto i : tokens)
187 if (parts.size() != 3)
189 throw std::invalid_argument(
190 "Invalid MAVLink subnet: \"" + subnet +
"\".");
198 switch (parts[1].at(0))
206 catch (std::invalid_argument)
208 throw std::invalid_argument(
209 "Invalid MAVLink subnet: \"" + subnet +
"\".");
216 std::istringstream(parts.at(2)) >> slashmask;
218 if (slashmask < 0 || slashmask > 16)
220 throw std::out_of_range(
221 "Forward slash mask (" + std::to_string(slashmask)
222 +
") is outside of allowed range (0 - 16).");
225 mask_ = (0xFFFF << (16 - slashmask)) & 0xFFFF;
230 std::istringstream(parts.at(2)) >> slashmask;
232 if (slashmask < 0 || slashmask > 8)
234 throw std::out_of_range(
235 "Backslash mask (" + std::to_string(slashmask)
236 +
") is outside of allowed range (0 - 8).");
239 mask_ = (0xFFFF << (8 - slashmask)) & 0x00FF;
252 return (address.
address() & mask_) == (address_.
address() & mask_);
268 return (lhs.address_ == rhs.address_) && (lhs.mask_ == rhs.mask_);
284 return (lhs.address_ != rhs.address_) || (lhs.mask_ != rhs.mask_);
313 os << mavsubnet.address_;
315 switch (mavsubnet.mask_)
317 case 0b1111111111111111:
322 case 0b1111111111111110:
325 case 0b1111111111111100:
328 case 0b1111111111111000:
331 case 0b1111111111110000:
334 case 0b1111111111100000:
337 case 0b1111111111000000:
340 case 0b1111111110000000:
343 case 0b1111111100000000:
346 case 0b1111111000000000:
349 case 0b1111110000000000:
352 case 0b1111100000000000:
355 case 0b1111000000000000:
358 case 0b1110000000000000:
361 case 0b1100000000000000:
364 case 0b1000000000000000:
367 case 0b0000000000000000:
370 case 0b0000000011111111:
373 case 0b0000000011111110:
376 case 0b0000000011111100:
379 case 0b0000000011111000:
382 case 0b0000000011110000:
385 case 0b0000000011100000:
388 case 0b0000000011000000:
391 case 0b0000000010000000:
395 return os <<
":" <<
MAVAddress(mavsubnet.mask_);
MAVSubnet(const MAVSubnet &other)=default
std::ostream & operator<<(std::ostream &os, const Action &action)
unsigned int address() const
bool operator==(const Action &lhs, const Action &rhs)
bool operator!=(const Action &lhs, const Action &rhs)
bool contains(const MAVAddress &address) const