OpenTTD Source 20250520-master-gecadf1b322
BaseSet< T > Struct Template Reference

Information about a single base set. More...

#include <base_media_base.h>

Public Types

typedef std::unordered_map< std::string, std::string, StringHash, std::equal_to<> > TranslatedStrings
 

Public Member Functions

 ~BaseSet ()
 Free everything we allocated.
 
int GetNumMissing () const
 Get the number of missing files.
 
int GetNumInvalid () const
 Get the number of invalid files.
 
void LogError (std::string_view full_filename, std::string_view detail, int level=0) const
 Log error from reading basesets.
 
const IniItemGetMandatoryItem (std::string_view full_filename, const IniGroup &group, std::string_view name) const
 Try to read a single piece of metadata and return nullptr if it doesn't exist.
 
bool FillSetDetails (const IniFile &ini, const std::string &path, const std::string &full_filename, bool allow_empty_filename=true)
 Read the set information from a loaded ini.
 
void CopyCompatibleConfig (const T &src)
 
const std::string & GetDescription (std::string_view isocode) const
 Get the description for the given ISO code.
 
std::optional< std::string > GetTextfile (TextfileType type) const
 Search a textfile file next to this base media.
 

Static Public Member Functions

static MD5File::ChecksumResult CheckMD5 (const MD5File *file, Subdirectory subdir)
 Calculate and check the MD5 hash of the supplied file.
 
static std::span< const std::string_view > GetFilenames ()
 Get the internal names of the files in this set.
 

Data Fields

std::string name
 The name of the base set.
 
std::string url
 URL for information about the base set.
 
TranslatedStrings description
 Description of the base set.
 
uint32_t shortname = 0
 Four letter short variant of the name.
 
std::vector< uint32_t > version
 The version of this base set.
 
bool fallback = false
 This set is a fallback set, i.e. it should be used only as last resort.
 
std::array< MD5File, BaseSet< T >::NUM_FILESfiles {}
 All files part of this set.
 
uint found_files = 0
 Number of the files that could be found.
 
uint valid_files = 0
 Number of the files that could be found and are valid.
 
T * next = nullptr
 The next base set in this list.
 

Static Public Attributes

static constexpr size_t NUM_FILES = BaseSetTraits<T>::num_files
 Number of files in this set.
 
static constexpr bool SEARCH_IN_TARS = BaseSetTraits<T>::search_in_tars
 Whether to search in the tars or not.
 
static constexpr std::string_view SET_TYPE = BaseSetTraits<T>::set_type
 BaseSet type name.
 

Detailed Description

template<class T>
struct BaseSet< T >

Information about a single base set.

Template Parameters
Tthe real class we're going to be

Definition at line 50 of file base_media_base.h.

Member Typedef Documentation

◆ TranslatedStrings

template<class T >
typedef std::unordered_map<std::string, std::string, StringHash, std::equal_to<> > BaseSet< T >::TranslatedStrings

Definition at line 51 of file base_media_base.h.

Constructor & Destructor Documentation

◆ ~BaseSet()

template<class T >
BaseSet< T >::~BaseSet ( )
inline

Free everything we allocated.

Definition at line 76 of file base_media_base.h.

References BaseSet< T >::next.

Member Function Documentation

◆ CheckMD5()

template<class T >
static MD5File::ChecksumResult BaseSet< T >::CheckMD5 ( const MD5File file,
Subdirectory  subdir 
)
inlinestatic

Calculate and check the MD5 hash of the supplied file.

Parameters
fileThe file get the hash of.
subdirThe sub directory to get the files from.
Returns
  • #CR_MATCH if the MD5 hash matches
  • #CR_MISMATCH if the MD5 does not match
  • #CR_NO_FILE if the file misses

Definition at line 138 of file base_media_base.h.

References MD5File::CheckMD5().

◆ CopyCompatibleConfig()

template<class T >
void BaseSet< T >::CopyCompatibleConfig ( const T &  src)
inline

Definition at line 104 of file base_media_base.h.

◆ FillSetDetails()

template<class T >
bool BaseSet< T >::FillSetDetails ( const IniFile ini,
const std::string &  path,
const std::string &  full_filename,
bool  allow_empty_filename = true 
)

Read the set information from a loaded ini.

Parameters
inithe ini to read from
paththe path to this ini file (for filenames)
full_filenamethe full filename of the loaded file (for error reporting purposes)
allow_empty_filenameempty filenames are valid
Returns
true if loading was successful.

Definition at line 60 of file base_media_func.h.

References IniLoadFile::GetGroup(), IniGroup::GetItem(), IniGroup::items, and IniItem::value.

◆ GetDescription()

template<class T >
const std::string & BaseSet< T >::GetDescription ( std::string_view  isocode) const
inline

Get the description for the given ISO code.

It falls back to the first two characters of the ISO code in case no match could be made with the full ISO code. If even then the matching fails the default is returned.

Parameters
isocodethe isocode to search for
Returns
the description

Definition at line 114 of file base_media_base.h.

◆ GetFilenames()

template<class T >
static std::span< const std::string_view > BaseSet< T >::GetFilenames ( )
static

Get the internal names of the files in this set.

Returns
the internal filenames

◆ GetMandatoryItem()

template<class T >
const IniItem * BaseSet< T >::GetMandatoryItem ( std::string_view  full_filename,
const IniGroup group,
std::string_view  name 
) const

Try to read a single piece of metadata and return nullptr if it doesn't exist.

Log error, if the data is missing.

Parameters
full_filenamethe full filename of the loaded file (for error reporting purposes)
groupini group to read from
namethe name of the item to fetch.

Definition at line 43 of file base_media_func.h.

References IniGroup::GetItem(), and IniGroup::name.

◆ GetNumInvalid()

template<class T >
int BaseSet< T >::GetNumInvalid ( ) const
inline

Get the number of invalid files.

Note
a missing file is invalid too!
Returns
the number

Definition at line 95 of file base_media_base.h.

References BaseSet< T >::valid_files.

Referenced by CheckExternalFiles().

◆ GetNumMissing()

template<class T >
int BaseSet< T >::GetNumMissing ( ) const
inline

Get the number of missing files.

Returns
the number

Definition at line 85 of file base_media_base.h.

References BaseSet< T >::found_files.

◆ GetTextfile()

template<class T >
std::optional< std::string > BaseSet< T >::GetTextfile ( TextfileType  type) const
inline

Search a textfile file next to this base media.

Parameters
typeThe type of the textfile to search for.
Returns
The filename for the textfile.

Definition at line 148 of file base_media_base.h.

References BASESET_DIR, BaseSet< T >::files, and BaseSet< T >::GetTextfile().

Referenced by BaseSet< T >::GetTextfile().

◆ LogError()

template<class T >
void BaseSet< T >::LogError ( std::string_view  full_filename,
std::string_view  detail,
int  level = 0 
) const

Log error from reading basesets.

Parameters
full_filenamethe full filename of the loaded file
detaildetail log message
leveldebug level

Definition at line 29 of file base_media_func.h.

References Debug.

Field Documentation

◆ description

template<class T >
TranslatedStrings BaseSet< T >::description

Description of the base set.

Definition at line 64 of file base_media_base.h.

◆ fallback

template<class T >
bool BaseSet< T >::fallback = false

This set is a fallback set, i.e. it should be used only as last resort.

Definition at line 67 of file base_media_base.h.

◆ files

template<class T >
std::array<MD5File, BaseSet<T>::NUM_FILES> BaseSet< T >::files {}

All files part of this set.

Definition at line 69 of file base_media_base.h.

Referenced by CheckExternalFiles(), BaseSet< T >::GetTextfile(), and LoadSpriteTables().

◆ found_files

template<class T >
uint BaseSet< T >::found_files = 0

Number of the files that could be found.

Definition at line 70 of file base_media_base.h.

Referenced by BaseSet< T >::GetNumMissing().

◆ name

template<class T >
std::string BaseSet< T >::name

The name of the base set.

Definition at line 62 of file base_media_base.h.

Referenced by CheckExternalFiles(), and GraphicsSetSaveConfig().

◆ next

template<class T >
T* BaseSet< T >::next = nullptr

The next base set in this list.

Definition at line 73 of file base_media_base.h.

Referenced by BaseSet< T >::~BaseSet().

◆ NUM_FILES

template<class T >
constexpr size_t BaseSet< T >::NUM_FILES = BaseSetTraits<T>::num_files
staticconstexpr

Number of files in this set.

Definition at line 54 of file base_media_base.h.

◆ SEARCH_IN_TARS

template<class T >
constexpr bool BaseSet< T >::SEARCH_IN_TARS = BaseSetTraits<T>::search_in_tars
staticconstexpr

Whether to search in the tars or not.

Definition at line 57 of file base_media_base.h.

◆ SET_TYPE

template<class T >
constexpr std::string_view BaseSet< T >::SET_TYPE = BaseSetTraits<T>::set_type
staticconstexpr

BaseSet type name.

Definition at line 60 of file base_media_base.h.

◆ shortname

template<class T >
uint32_t BaseSet< T >::shortname = 0

Four letter short variant of the name.

Definition at line 65 of file base_media_base.h.

Referenced by GraphicsSetSaveConfig().

◆ url

template<class T >
std::string BaseSet< T >::url

URL for information about the base set.

Definition at line 63 of file base_media_base.h.

◆ valid_files

template<class T >
uint BaseSet< T >::valid_files = 0

Number of the files that could be found and are valid.

Definition at line 71 of file base_media_base.h.

Referenced by BaseSet< T >::GetNumInvalid().

◆ version

template<class T >
std::vector<uint32_t> BaseSet< T >::version

The version of this base set.

Definition at line 66 of file base_media_base.h.


The documentation for this struct was generated from the following files: