From ef3edc531c164d4e75cdc9b61d9ebd21de1d94c7 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Mon, 28 Aug 2017 17:42:33 -0700 Subject: [PATCH] AP_BoardConfig: add static create method --- libraries/AP_BoardConfig/AP_BoardConfig.h | 16 +++++++++++----- libraries/AP_BoardConfig/AP_BoardConfig_CAN.h | 17 ++++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/libraries/AP_BoardConfig/AP_BoardConfig.h b/libraries/AP_BoardConfig/AP_BoardConfig.h index 302422b889..07f0cb8ab7 100644 --- a/libraries/AP_BoardConfig/AP_BoardConfig.h +++ b/libraries/AP_BoardConfig/AP_BoardConfig.h @@ -9,11 +9,13 @@ extern "C" typedef int (*main_fn_t)(int argc, char **); class AP_BoardConfig { public: - // constructor - AP_BoardConfig(void) - { - AP_Param::setup_object_defaults(this, var_info); - }; + static AP_BoardConfig create() { return AP_BoardConfig{}; } + + constexpr AP_BoardConfig(AP_BoardConfig &&other) = default; + + /* Do not allow copies */ + AP_BoardConfig(const AP_BoardConfig &other) = delete; + AP_BoardConfig &operator=(const AP_BoardConfig&) = delete; void init(void); void init_safety(void); @@ -68,6 +70,10 @@ public: #endif private: + AP_BoardConfig() { + AP_Param::setup_object_defaults(this, var_info); + }; + AP_Int16 vehicleSerialNumber; #if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN diff --git a/libraries/AP_BoardConfig/AP_BoardConfig_CAN.h b/libraries/AP_BoardConfig/AP_BoardConfig_CAN.h index 827ef5cab5..f71dfa012d 100644 --- a/libraries/AP_BoardConfig/AP_BoardConfig_CAN.h +++ b/libraries/AP_BoardConfig/AP_BoardConfig_CAN.h @@ -11,11 +11,13 @@ class AP_BoardConfig_CAN { public: - // constructor - AP_BoardConfig_CAN(void) - { - AP_Param::setup_object_defaults(this, var_info); - }; + static AP_BoardConfig_CAN create() { return AP_BoardConfig_CAN{}; } + + constexpr AP_BoardConfig_CAN(AP_BoardConfig_CAN &&other) = default; + + /* Do not allow copies */ + AP_BoardConfig_CAN(const AP_BoardConfig_CAN &other) = delete; + AP_BoardConfig_CAN &operator=(const AP_BoardConfig_CAN&) = delete; void init(void); @@ -96,5 +98,10 @@ public: #if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN void px4_setup_canbus(void); #endif // HAL_BOARD_PX4 || HAL_BOARD_VRBRAIN + +private: + AP_BoardConfig_CAN() { + AP_Param::setup_object_defaults(this, var_info); + }; }; #endif