FireSTARR
Loading...
Searching...
No Matches
FuelLookup.h
1/* Copyright (c) Queen's Printer for Ontario, 2020. */
2/* Copyright (c) His Majesty the King in Right of Canada as represented by the Minister of Natural Resources, 2025. */
3
4/* SPDX-License-Identifier: AGPL-3.0-or-later */
5
6#pragma once
7#include <memory>
8#include <set>
9#include <string>
10#include "FuelType.h"
11#include "Cell.h"
12#include "Util.h"
13namespace fs::fuel
14{
15class FuelLookupImpl;
16
17string simplify_fuel_name(const string& fuel);
18
23{
24public:
25 ~FuelLookup() = default;
30 explicit FuelLookup(const char* filename);
35 FuelLookup(const FuelLookup& rhs) noexcept = default;
40 FuelLookup(FuelLookup&& rhs) noexcept = default;
46 FuelLookup& operator=(const FuelLookup& rhs) noexcept = default;
52 FuelLookup& operator=(FuelLookup&& rhs) noexcept = default;
59 [[nodiscard]] const FuelType* codeToFuel(FuelSize value, FuelSize nodata) const;
63 void listFuels() const;
69 [[nodiscard]] FuelSize fuelToCode(const FuelType* fuel) const;
76 [[nodiscard]] const FuelType* operator()(FuelSize value, FuelSize nodata) const;
81 [[nodiscard]] set<const FuelType*> usedFuels() const;
87 [[nodiscard]] const FuelType* byName(const string& name) const;
93 [[nodiscard]] const FuelType* bySimplifiedName(const string& name) const;
97 static const array<const FuelType*, NUMBER_OF_FUELS> Fuels;
98private:
102 shared_ptr<FuelLookupImpl> impl_;
103};
109[[nodiscard]] constexpr const FuelType* fuel_by_code(const FuelCodeSize& code)
110{
111 return FuelLookup::Fuels.at(code);
112}
118[[nodiscard]] constexpr const FuelType* check_fuel(const topo::Cell& cell)
119{
120 return fuel_by_code(cell.fuelCode());
121}
127[[nodiscard]] constexpr bool is_null_fuel(const FuelType* fuel)
128{
129 return INVALID_FUEL_CODE == FuelType::safeCode(fuel);
130}
136[[nodiscard]] constexpr bool is_null_fuel(const topo::Cell& cell)
137{
138 return is_null_fuel(fuel_by_code(cell.fuelCode()));
139}
140}
Provides ability to look up a fuel type based on name or code.
Definition FuelLookup.h:23
const FuelType * byName(const string &name) const
Look up a FuelType based on the given name.
Definition FuelLookup.cpp:653
const FuelType * codeToFuel(FuelSize value, FuelSize nodata) const
Look up a FuelType based on the given code.
Definition FuelLookup.cpp:633
FuelLookup & operator=(FuelLookup &&rhs) noexcept=default
Move assignment.
void listFuels() const
List all fuels and their codes.
Definition FuelLookup.cpp:637
FuelLookup(FuelLookup &&rhs) noexcept=default
Move constructor.
set< const FuelType * > usedFuels() const
Retrieve set of FuelTypes that are used in the lookup table.
Definition FuelLookup.cpp:649
const FuelType * bySimplifiedName(const string &name) const
Look up a FuelType based on the given simplified name.
Definition FuelLookup.cpp:657
static const array< const FuelType *, NUMBER_OF_FUELS > Fuels
Array of all FuelTypes available to be used in simulations.
Definition FuelLookup.h:97
shared_ptr< FuelLookupImpl > impl_
Implementation class for FuelLookup.
Definition FuelLookup.h:102
FuelLookup(const char *filename)
Construct by reading from a file.
Definition FuelLookup.cpp:661
FuelLookup & operator=(const FuelLookup &rhs) noexcept=default
Copy assignment.
const FuelType * operator()(FuelSize value, FuelSize nodata) const
Look up a FuelType ba1ed on the given code.
Definition FuelLookup.cpp:645
FuelSize fuelToCode(const FuelType *fuel) const
Look up the original code for the given FuelType.
Definition FuelLookup.cpp:641
FuelLookup(const FuelLookup &rhs) noexcept=default
Copy constructor.
An FBP fuel type.
Definition FuelType.h:55
static constexpr FuelCodeSize safeCode(const FuelType *fuel)
Convert FuelType to its code, or 0 if nullptr.
Definition FuelType.h:62
A Position with a Slope, Aspect, and Fuel.
Definition Cell.h:20
static constexpr FuelCodeSize fuelCode(const SpreadKey value) noexcept
Fuel.
Definition Cell.h:136