From b2c3795f11511dc2c959b5fb9a34641e127ad8ad Mon Sep 17 00:00:00 2001 From: scttgs0 Date: Sat, 20 May 2023 17:33:07 -0500 Subject: [PATCH] Maintenance: namespace Clean up namespaces. Don't use broad 'using namespace' context in header files. Header Guards. SPDX tags. --- src/Scripting/NasalFlightPlan.cxx | 33 ++++++------------- src/Scripting/NasalModelData.cxx | 4 +-- src/Scripting/NasalUnitTesting.cxx | 53 ++++++++++++------------------ 3 files changed, 33 insertions(+), 57 deletions(-) diff --git a/src/Scripting/NasalFlightPlan.cxx b/src/Scripting/NasalFlightPlan.cxx index 9ed4131a0..07b2ff208 100644 --- a/src/Scripting/NasalFlightPlan.cxx +++ b/src/Scripting/NasalFlightPlan.cxx @@ -1,22 +1,9 @@ -// NasalFlightPlan.cxx -- expose FlightPlan classes to Nasal -// -// Written by James Turner, started 2020. -// -// Copyright (C) 2020 James Turner -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +/* + * SPDX-FileName: NasalFlightPlan.cxx + * SPDX-FileComment: expose FlightPlan classes to Nasal + * SPDX-FileCopyrightText: Copyright (C) 2020 James Turner + * SPDX-License-Identifier: GPL-2.0-or-later + */ #include "config.h" @@ -812,7 +799,7 @@ static void flightplanGhostSetMember(naContext c, void* g, naRef field, naRef va } if (naIsNil(value)) { - fp->setSID(fp->sid(), string{}); + fp->setSID(fp->sid(), std::string{}); return; } @@ -882,7 +869,7 @@ static void flightplanGhostSetMember(naContext c, void* g, naRef field, naRef va } if (naIsNil(value)) { - fp->setSTAR(fp->star(), string{}); + fp->setSTAR(fp->star(), std::string{}); return; } @@ -947,7 +934,7 @@ static void flightplanGhostSetMember(naContext c, void* g, naRef field, naRef va } if (naIsNil(value)) { - fp->setApproach(fp->approach(), string{}); + fp->setApproach(fp->approach(), std::string{}); return; } @@ -2175,7 +2162,7 @@ static naRef f_procedure_transition(naContext c, naRef me, int argc, naRef* args naRuntimeError(c, "procedure.transition called on non-procedure object"); } - const string ident{naStr_data(args[0])}; + const std::string ident{naStr_data(args[0])}; const auto ty = proc->type(); if (Approach::isApproach(ty)) { const auto app = static_cast(proc); diff --git a/src/Scripting/NasalModelData.cxx b/src/Scripting/NasalModelData.cxx index fc335836a..2068a8c7a 100644 --- a/src/Scripting/NasalModelData.cxx +++ b/src/Scripting/NasalModelData.cxx @@ -113,7 +113,7 @@ void FGNasalModelData::load() SG_LOG(SG_NASAL, SG_DEBUG, "Loading nasal module " << _module.c_str()); - const string s = _load ? _load->getStringValue() : ""; + const std::string s = _load ? _load->getStringValue() : ""; auto nasalSys = globals->get_subsystem(); // Add _module_id to script local hash to allow placing canvasses on objects @@ -149,7 +149,7 @@ void FGNasalModelData::unload() if (_unload) { - const string s = _unload->getStringValue(); + const std::string s = _unload->getStringValue(); nasalSys->createModule(_module.c_str(), _module.c_str(), s.c_str(), s.length(), _root); } diff --git a/src/Scripting/NasalUnitTesting.cxx b/src/Scripting/NasalUnitTesting.cxx index 750bb095b..77d015cdd 100644 --- a/src/Scripting/NasalUnitTesting.cxx +++ b/src/Scripting/NasalUnitTesting.cxx @@ -1,29 +1,18 @@ -// Unit-test API for nasal -// +/* + * SPDX-FileName: NasalUnittesting.cxx + * SPDX-FileComment: Unit-test API for nasal + * SPDX-FileCopyrightText: Copyright (C) 2020 James Turner + * SPDX-License-Identifier: GPL-2.0-or-later + */ + // There are two versions of this module, and we load one or the other // depending on if we're running the test_suite (using CppUnit) or // the normal simulator. The logic is that aircraft-developers and // people hacking Nasal likely don't have a way to run the test-suite, -// whereas core-developers and Jenksin want a way to run all tests -// through the standard CppUnit mechanim. So we have a consistent +// whereas core-developers and Jenkins want a way to run all tests +// through the standard CppUnit mechanism. So we have a consistent // Nasal API, but different implement in fgfs_test_suite vs // normal fgfs executable. -// -// Copyright (C) 2020 James Turner -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "config.h" @@ -58,7 +47,7 @@ static std::unique_ptr static_activeTest; static naRef f_assert(const nasal::CallContext& ctx ) { bool pass = ctx.requireArg(0); - auto msg = ctx.getArg(1); + auto msg = ctx.getArg(1); if (!pass) { if (!static_activeTest) { @@ -71,7 +60,7 @@ static naRef f_assert(const nasal::CallContext& ctx ) static_activeTest->failure = true; static_activeTest->failureMessage = msg; - static_activeTest->failureFileName = ctx.from_nasal(naGetSourceFile(ctx.c_ctx(), 0)); + static_activeTest->failureFileName = ctx.from_nasal(naGetSourceFile(ctx.c_ctx(), 0)); static_activeTest->failLineNumber = naGetLine(ctx.c_ctx(), 0); ctx.runtimeError("Test assert failed"); @@ -82,7 +71,7 @@ static naRef f_assert(const nasal::CallContext& ctx ) static naRef f_fail(const nasal::CallContext& ctx ) { - auto msg = ctx.getArg(0); + auto msg = ctx.getArg(0); if (!static_activeTest) { ctx.runtimeError("No active test in progress"); @@ -94,7 +83,7 @@ static naRef f_fail(const nasal::CallContext& ctx ) static_activeTest->failure = true; static_activeTest->failureMessage = msg; - static_activeTest->failureFileName = ctx.from_nasal(naGetSourceFile(ctx.c_ctx(), 0)); + static_activeTest->failureFileName = ctx.from_nasal(naGetSourceFile(ctx.c_ctx(), 0)); static_activeTest->failLineNumber = naGetLine(ctx.c_ctx(), 0); ctx.runtimeError("Test failed"); @@ -106,16 +95,16 @@ static naRef f_assert_equal(const nasal::CallContext& ctx ) { naRef argA = ctx.requireArg(0); naRef argB = ctx.requireArg(1); - auto msg = ctx.getArg(2, "assert_equal failed"); + auto msg = ctx.getArg(2, "assert_equal failed"); bool same = nasalStructEqual(ctx.c_ctx(), argA, argB); if (!same) { - string aStr = ctx.from_nasal(argA); - string bStr = ctx.from_nasal(argB); + std::string aStr = ctx.from_nasal(argA); + std::string bStr = ctx.from_nasal(argB); msg += "; expected:" + aStr + ", actual:" + bStr; static_activeTest->failure = true; static_activeTest->failureMessage = msg; - static_activeTest->failureFileName = ctx.from_nasal(naGetSourceFile(ctx.c_ctx(), 0)); + static_activeTest->failureFileName = ctx.from_nasal(naGetSourceFile(ctx.c_ctx(), 0)); static_activeTest->failLineNumber = naGetLine(ctx.c_ctx(), 0); ctx.runtimeError(msg.c_str()); } @@ -129,14 +118,14 @@ static naRef f_assert_doubles_equal(const nasal::CallContext& ctx ) double argB = ctx.requireArg(1); double tolerance = ctx.requireArg(2); - auto msg = ctx.getArg(3, "assert_doubles_equal failed"); + auto msg = ctx.getArg(3, "assert_doubles_equal failed"); const bool same = fabs(argA - argB) < tolerance; if (!same) { msg += "; expected:" + std::to_string(argA) + ", actual:" + std::to_string(argB); static_activeTest->failure = true; static_activeTest->failureMessage = msg; - static_activeTest->failureFileName = ctx.from_nasal(naGetSourceFile(ctx.c_ctx(), 0)); + static_activeTest->failureFileName = ctx.from_nasal(naGetSourceFile(ctx.c_ctx(), 0)); static_activeTest->failLineNumber = naGetLine(ctx.c_ctx(), 0); ctx.runtimeError(msg.c_str()); } @@ -247,8 +236,8 @@ bool executeNasalTest(const SGPath& path) sg_ifstream file_in(path); const auto source = file_in.read_all(); - string errors; - string fileName = path.utf8Str(); + std::string errors; + std::string fileName = path.utf8Str(); naRef code = parseTestFile(ctx, fileName.c_str(), source.c_str(), source.size(), errors);