1
0
Fork 0

Maintenance: initialstate

SPDX tags.
header guard.
explicit ctor.
This commit is contained in:
scttgs0 2023-05-22 20:16:18 -05:00
parent 57a818ee10
commit b6ed14b0d9
2 changed files with 49 additions and 82 deletions

View file

@ -1,72 +1,58 @@
// initialstate.cxx -- setup initial state of the aircraft
//
// Written by James Turner
//
// Copyright (C) 2016 James Turner <zakalawe@mac.com>
//
// 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.
//
// $Id$
/*
* SPDX-FileName: initialstate.cxx
* SPDX-FileComment: setup initial state of the aircraft
* SPDX-FileCopyrightText: Copyright (C) 2016 James Turner <zakalawe@mac.com>
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "config.h"
#include "initialstate.hxx"
#include <algorithm>
#include <simgear/debug/logstream.hxx>
#include <simgear/props/props_io.hxx>
#include <Main/fg_props.hxx>
#include <GUI/MessageBox.hxx>
#include <Main/fg_props.hxx>
#include "initialstate.hxx"
using namespace simgear;
namespace {
class NodeValue
class NodeValue
{
public:
explicit NodeValue(const std::string& s) : v(s) {}
bool operator()(const SGPropertyNode_ptr n) const
{
public:
NodeValue(const std::string& s) : v(s) {}
bool operator()(const SGPropertyNode_ptr n) const
{
return (v == n->getStringValue());
}
private:
std::string v;
};
SGPropertyNode_ptr nodeForState(const std::string& nm)
{
SGPropertyNode_ptr sim = fgGetNode("/sim");
const PropertyList& states = sim->getChildren("state");
PropertyList::const_iterator it;
for (it = states.begin(); it != states.end(); ++it) {
const PropertyList& names = (*it)->getChildren("name");
if (std::find_if(names.begin(), names.end(), NodeValue(nm)) != names.end()) {
return *it;
}
}
return SGPropertyNode_ptr();
return (v == n->getStringValue());
}
} // of anonymous namespace
private:
std::string v;
};
namespace flightgear
SGPropertyNode_ptr nodeForState(const std::string& nm)
{
SGPropertyNode_ptr sim = fgGetNode("/sim");
const PropertyList& states = sim->getChildren("state");
PropertyList::const_iterator it;
for (it = states.begin(); it != states.end(); ++it) {
const PropertyList& names = (*it)->getChildren("name");
if (std::find_if(names.begin(), names.end(), NodeValue(nm)) != names.end()) {
return *it;
}
}
return SGPropertyNode_ptr();
}
} // namespace
namespace flightgear {
bool isInitialStateName(const std::string& name)
{
@ -86,7 +72,7 @@ void applyInitialState()
SG_LOG(SG_AIRCRAFT, SG_WARN, "missing state node for:" << nm);
std::string aircraft = fgGetString("/sim/aircraft");
modalMessageBox("Unknown aircraft state",
"The selected aircraft (" + aircraft + ") does not have a state '" + nm + "'");
"The selected aircraft (" + aircraft + ") does not have a state '" + nm + "'");
return;
}
@ -97,4 +83,4 @@ void applyInitialState()
copyProperties(stateNode->getChild("overlay"), globals->get_props());
}
} // of namespace flightgear
} // namespace flightgear

View file

@ -1,41 +1,22 @@
// initialstate.hxx -- setup initial state of the aircraft
//
// Written by James Turner
//
// Copyright (C) 2016 James Turner <zakalawe@mac.com>
//
// 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.
//
// $Id$
/*
* SPDX-FileName: initialstate.hxx
* SPDX-FileComment: setup initial state of the aircraft
* SPDX-FileCopyrightText: Copyright (C) 2016 James Turner <zakalawe@mac.com>
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef FG_AIRCRAFT_INITIAL_STATE_HXX
#define FG_AIRCRAFT_INITIAL_STATE_HXX
#pragma once
#include <string>
namespace flightgear
{
namespace flightgear {
/**
* @brief is the supplied name a defined initial-state, or alias of one
*/
bool isInitialStateName(const std::string& name);
void applyInitialState();
void applyInitialState();
} // of namespace flightgear
#endif // FG_AIRCRAFT_INITIAL_STATE_HXX
} // namespace flightgear