17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 19:09:25 +02:00
Files
maszyna/vehicle/graph/graph_block.cpp

55 lines
1.3 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
#include "vehicle/graph/graph_block.h"
#include "vehicle/graph/graph_catalog.h"
namespace vgraph
{
block::block(block_setup const &Setup) : m_type(Setup.type), m_slots(Setup.slots) {}
double block::number(block_setup const &Setup, std::size_t const Param)
{
return Setup.params[Param].number;
}
bool block::boolean(block_setup const &Setup, std::size_t const Param)
{
return Setup.params[Param].boolean;
}
std::string const &block::text(block_setup const &Setup, std::size_t const Param)
{
return Setup.params[Param].text;
}
std::vector<std::vector<double>> const &block::table(block_setup const &Setup, std::size_t const Param)
{
return Setup.params[Param].rows;
}
int block::choice(block_setup const &Setup, std::size_t const Param)
{
auto const &choices{Setup.param_defs[Param].choices};
auto const &value{Setup.params[Param].text};
for (std::size_t idx = 0; idx < choices.size(); ++idx)
{
if (choices[idx] == value)
{
return static_cast<int>(idx);
}
}
// the loader rejects values outside of the list, so this only happens with a broken catalog
return 0;
}
} // namespace vgraph