openMSX
RomInfo.hh
Go to the documentation of this file.
1#ifndef ROMINFO_HH
2#define ROMINFO_HH
3
4#include "RomTypes.hh"
5#include "String32.hh"
6#include "view.hh"
7#include <array>
8#include <string_view>
9#include <utility>
10#include <vector>
11
12namespace openmsx {
13
15{
16public:
17 // This contains extra information for each RomType. This structure only
18 // contains the primary (non-alias) rom types.
19 struct RomTypeInfo {
20 unsigned blockSize;
21 std::string_view name;
22 std::string_view description;
23 };
24
25public:
26 RomInfo(String32 title_, String32 year_,
27 String32 company_, String32 country_,
28 bool original_, String32 origType_,
29 String32 remark_, RomType romType_,
30 unsigned genMSXid_)
31 : title (title_)
32 , year (year_)
33 , company (company_)
34 , country (country_)
35 , origType(origType_)
36 , remark (std::move(remark_))
37 , romType(romType_)
38 , genMSXid(genMSXid_)
39 , original(original_)
40 {
41 }
42
43 [[nodiscard]] std::string_view getTitle (const char* buf) const {
44 return fromString32(buf, title);
45 }
46 [[nodiscard]] std::string_view getYear (const char* buf) const {
47 return fromString32(buf, year);
48 }
49 [[nodiscard]] std::string_view getCompany (const char* buf) const {
50 return fromString32(buf, company);
51 }
52 [[nodiscard]] std::string_view getCountry (const char* buf) const {
53 return fromString32(buf, country);
54 }
55 [[nodiscard]] std::string_view getOrigType(const char* buf) const {
56 return fromString32(buf, origType);
57 }
58 [[nodiscard]] std::string_view getRemark (const char* buf) const {
59 return fromString32(buf, remark);
60 }
61 [[nodiscard]] RomType getRomType() const { return romType; }
62 [[nodiscard]] bool getOriginal() const { return original; }
63 [[nodiscard]] unsigned getGenMSXid() const { return genMSXid; }
64
65 [[nodiscard]] static RomType nameToRomType(std::string_view name);
66 [[nodiscard]] static std::string_view romTypeToName (RomType type);
67 [[nodiscard]] static std::string_view getDescription(RomType type);
68 [[nodiscard]] static unsigned getBlockSize (RomType type);
69 [[nodiscard]] static auto getAllRomTypes() {
70 return view::transform(getRomTypeInfo(), &RomTypeInfo::name);
71 }
72
73private:
74 static const std::array<RomInfo::RomTypeInfo, RomType::ROM_LAST>& getRomTypeInfo();
75
76private:
77 String32 title;
78 String32 year;
79 String32 company;
80 String32 country;
81 String32 origType;
82 String32 remark;
83 RomType romType;
84 unsigned genMSXid;
85 bool original;
86};
87
88} // namespace openmsx
89
90#endif
constexpr const char * fromString32(const char *buffer, uint32_t str32)
Definition: String32.hh:35
std::conditional_t<(sizeof(char *) > sizeof(uint32_t)), uint32_t, const char * > String32
Definition: String32.hh:22
std::string_view getYear(const char *buf) const
Definition: RomInfo.hh:46
bool getOriginal() const
Definition: RomInfo.hh:62
static unsigned getBlockSize(RomType type)
Definition: RomInfo.cc:195
unsigned getGenMSXid() const
Definition: RomInfo.hh:63
std::string_view getTitle(const char *buf) const
Definition: RomInfo.hh:43
static std::string_view getDescription(RomType type)
Definition: RomInfo.cc:190
std::string_view getCompany(const char *buf) const
Definition: RomInfo.hh:49
std::string_view getRemark(const char *buf) const
Definition: RomInfo.hh:58
static auto getAllRomTypes()
Definition: RomInfo.hh:69
RomInfo(String32 title_, String32 year_, String32 company_, String32 country_, bool original_, String32 origType_, String32 remark_, RomType romType_, unsigned genMSXid_)
Definition: RomInfo.hh:26
static std::string_view romTypeToName(RomType type)
Definition: RomInfo.cc:185
std::string_view getCountry(const char *buf) const
Definition: RomInfo.hh:52
RomType getRomType() const
Definition: RomInfo.hh:61
static RomType nameToRomType(std::string_view name)
Definition: RomInfo.cc:174
std::string_view getOrigType(const char *buf) const
Definition: RomInfo.hh:55
This file implemented 3 utility functions:
Definition: Autofire.cc:9
STL namespace.
constexpr auto transform(Range &&range, UnaryOp op)
Definition: view.hh:458
std::string_view description
Definition: RomInfo.hh:22
std::string_view name
Definition: RomInfo.hh:21