Skip to content

Commit

Permalink
Merge pull request #672 from SignalK/definition_in_cpp
Browse files Browse the repository at this point in the history
Move function definitions from header to cpp file
  • Loading branch information
mairas authored Jan 7, 2024
2 parents e115a06 + 035d1d8 commit b529b83
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
20 changes: 20 additions & 0 deletions src/sensesp/types/position.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "position.h"

#include "ArduinoJson.h"

namespace sensesp {

void convertFromJson(JsonVariantConst src, Position &dst) {
dst.longitude = src["longitude"].as<double>();
dst.latitude = src["latitude"].as<double>();

if (src.containsKey("altitude")) {
dst.altitude = src["altitude"].as<float>();
}
}

bool canConvertFromJson(JsonVariantConst src, const Position &) {
return src.containsKey("latitude") && src.containsKey("longitude");
}

} // namespace sensesp
15 changes: 4 additions & 11 deletions src/sensesp/types/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <limits>

#include "ArduinoJson.h"

namespace sensesp {

/// Value used to indicate an invalid or missing altitude
Expand Down Expand Up @@ -46,14 +48,7 @@ struct ENUVector {
* @param src The JSON document containing the position data
* @param dst The address to a Position struct to write the data to
*/
void convertFromJson(JsonVariantConst src, Position &dst) {
dst.longitude = src["longitude"].as<double>();
dst.latitude = src["latitude"].as<double>();

if (src.containsKey("altitude")) {
dst.altitude = src["altitude"].as<float>();
}
}
void convertFromJson(JsonVariantConst src, Position &dst);

/**
* @brief Tells ArduinoJson whether the given JSON is a Position or not
Expand All @@ -66,9 +61,7 @@ void convertFromJson(JsonVariantConst src, Position &dst) {
* @return false if the given JSON doesn't contain "latitude" or "longitude"
* keys
*/
bool canConvertFromJson(JsonVariantConst src, const Position &) {
return src.containsKey("latitude") && src.containsKey("longitude");
}
bool canConvertFromJson(JsonVariantConst src, const Position &);

} // namespace sensesp

Expand Down

0 comments on commit b529b83

Please sign in to comment.