Skip to content

Commit 2cf24f2

Browse files
authored
Merge pull request #2545 from Luc-Meunier/autopilot-name
core: overload operator<< for Autopilot name
2 parents 93a7eb5 + 0fc3b05 commit 2cf24f2

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

docs/en/cpp/api_reference/namespacemavsdk.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ enum [ForwardingOption](#namespacemavsdk_1a7066729108eae8a605d4dd169e4581b9) | F
6666

6767
Type | Name | Description
6868
--- | --- | ---
69+
std::ostream & | [operator<<](#namespacemavsdk_1ad782054ca8c33116d0210acca8c55ce6) (std::ostream & os, const [Autopilot](namespacemavsdk.md#namespacemavsdk_1aba05635d1785223a4d7b457ae0407297) & autopilot) | Stream operator to print information about an `Autopilot`.
6970
std::string | [base64_encode](#namespacemavsdk_1a57a9962be22a61e5c36a66bc17e6a2a7) (std::vector< uint8_t > & raw) | Encode raw bytes to a base64 string.
7071
std::vector< uint8_t > | [base64_decode](#namespacemavsdk_1a34e7609c9e2ddcc72a74bbc79daf9c19) (const std::string & str) | Decode a base64 string into raw bytes.
7172
std::ostream & | [operator<<](#namespacemavsdk_1a2aa91d8b846b07fe7f305b399375ce5f) (std::ostream & str, const [ConnectionResult](namespacemavsdk.md#namespacemavsdk_1a0bad93f6d037051ac3906a0bcc09f992) & result) | Stream operator to print information about a `ConnectionResult`.
@@ -159,6 +160,28 @@ Value | Description
159160
## Function Documentation
160161

161162

163+
### operator<<() {#namespacemavsdk_1ad782054ca8c33116d0210acca8c55ce6}
164+
165+
```
166+
#include: autopilot.h
167+
```
168+
```cpp
169+
std::ostream & mavsdk::operator<<(std::ostream &os, const Autopilot &autopilot)
170+
```
171+
172+
173+
Stream operator to print information about an `Autopilot`.
174+
175+
176+
**Parameters**
177+
178+
* std::ostream& **os** -
179+
* const [Autopilot](namespacemavsdk.md#namespacemavsdk_1aba05635d1785223a4d7b457ae0407297)& **autopilot** -
180+
181+
**Returns**
182+
183+
&emsp;std::ostream & - A reference to the stream.
184+
162185
### base64_encode() {#namespacemavsdk_1a57a9962be22a61e5c36a66bc17e6a2a7}
163186

164187
```

src/mavsdk/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ configure_file(include/mavsdk/mavlink_include.h.in include/mavsdk/mavlink_includ
1414

1515
target_sources(mavsdk
1616
PRIVATE
17+
autopilot.cpp
1718
base64.cpp
1819
call_every_handler.cpp
1920
connection.cpp

src/mavsdk/core/autopilot.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "autopilot.h"
2+
3+
namespace mavsdk {
4+
5+
std::ostream& operator<<(std::ostream& str, const Autopilot& autopilot)
6+
{
7+
switch (autopilot) {
8+
case Autopilot::Px4:
9+
return str << "Px4";
10+
case Autopilot::ArduPilot:
11+
return str << "ArduPilot";
12+
default:
13+
return str << "Unknown";
14+
}
15+
}
16+
17+
} // namespace mavsdk

src/mavsdk/core/include/mavsdk/autopilot.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <sstream>
4+
35
namespace mavsdk {
46

57
/**
@@ -11,4 +13,11 @@ enum class Autopilot {
1113
ArduPilot, // ArduPilot
1214
};
1315

16+
/**
17+
* @brief Stream operator to print information about an `Autopilot`.
18+
*
19+
* @return A reference to the stream.
20+
*/
21+
std::ostream& operator<<(std::ostream& os, const Autopilot& autopilot);
22+
1423
} // namespace mavsdk

0 commit comments

Comments
 (0)