From a0047120507aa511c48feb4f85d86d89b7fa771b Mon Sep 17 00:00:00 2001 From: rlagneau Date: Tue, 28 May 2024 09:21:15 +0200 Subject: [PATCH] [TUTO][FIX] Fix to_json compilation error in tutorial-ibvs-4pts-json --- .../ibvs/tutorial-ibvs-4pts-json.cpp | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tutorial/visual-servo/ibvs/tutorial-ibvs-4pts-json.cpp b/tutorial/visual-servo/ibvs/tutorial-ibvs-4pts-json.cpp index 0ae28d634a..e9c0724ced 100644 --- a/tutorial/visual-servo/ibvs/tutorial-ibvs-4pts-json.cpp +++ b/tutorial/visual-servo/ibvs/tutorial-ibvs-4pts-json.cpp @@ -11,10 +11,8 @@ #include using json = nlohmann::json; //! json namespace shortcut - #if defined(ENABLE_VISP_NAMESPACE) -namespace VISP_NAMESPACE_NAME -{ +using namespace VISP_NAMESPACE_NAME; #endif //! [Enum] @@ -75,6 +73,9 @@ class Arguments // the default value defined in the constructor is kept void from_json(const json &j, Arguments &a) { +#ifdef ENABLE_VISP_NAMESPACE + using VISP_NAMESPACE_ADDRESSING from_json; +#endif a.lambda = j.value("lambda", a.lambda); if (a.lambda <= 0) { throw vpException(vpException::badValue, "Lambda should be > 0"); @@ -101,6 +102,9 @@ void from_json(const json &j, Arguments &a) void to_json(json &j, const Arguments &a) { +#ifdef ENABLE_VISP_NAMESPACE + using VISP_NAMESPACE_ADDRESSING to_json; +#endif j = json { {"lambda", a.lambda}, {"cMo", a.cMo}, @@ -147,6 +151,11 @@ Arguments readArguments(const std::string &path) //! [JSON input conversion] //! [Custom ViSP object conversion] +#ifdef ENABLE_VISP_NAMESPACE +// Required to have the to_json method in the same namespace than vpFeaturePoint +namespace VISP_NAMESPACE_NAME +{ +#endif void to_json(json &j, const vpFeaturePoint &p) { j = json { @@ -155,6 +164,9 @@ void to_json(json &j, const vpFeaturePoint &p) {"z", p.get_Z()} }; } +#ifdef ENABLE_VISP_NAMESPACE +} +#endif //! [Custom ViSP object conversion] @@ -190,6 +202,9 @@ class ServoingExperimentData void to_json(json &j, const ServoingExperimentData &res) { +#ifdef ENABLE_VISP_NAMESPACE + using VISP_NAMESPACE_ADDRESSING to_json; +#endif j = json { {"parameters", res.m_arguments}, {"trajectory", res.m_trajectory}, @@ -211,15 +226,9 @@ void saveResults(const ServoingExperimentData &results, const std::string &path) file.close(); } //! [write json to file] -#if defined(ENABLE_VISP_NAMESPACE) -} -#endif int main(int argc, char *argv[]) { -#if defined(ENABLE_VISP_NAMESPACE) - using namespace VISP_NAMESPACE_NAME; -#endif //! [Main parsing] std::string arguments_path = ""; std::string output_path = "";