The Battle for Wesnoth  1.19.1+dev
Classes | Public Types | Public Member Functions | Private Attributes | Friends | List of all members
image::locator Class Reference

Generic locator abstracting the location of an image. More...

#include <picture.hpp>

Classes

struct  value
 

Public Types

enum  type { NONE , FILE , SUB_FILE }
 

Public Member Functions

 locator ()=default
 
 locator (locator &&) noexcept=default
 
 locator (const locator &)=default
 
template<typename... Args>
 locator (Args &&... args)
 
locatoroperator= (const locator &a)=default
 
locatoroperator= (locator &&)=default
 
locator clone (const std::string &mods) const
 Returns a copy of this locator with the given IPF. More...
 
bool operator== (const locator &a) const
 
bool operator!= (const locator &a) const
 
const std::string & get_filename () const
 
bool is_data_uri () const
 
const map_locationget_loc () const
 
int get_center_x () const
 
int get_center_y () const
 
const std::string & get_modifications () const
 
type get_type () const
 
bool is_void () const
 Returns true if the locator does not correspond to an actual image. More...
 
bool file_exists () const
 Tests whether the file the locator points at exists. More...
 
template<typename T >
bool in_cache (cache_type< T > &cache) const
 
template<typename T >
T & access_in_cache (cache_type< T > &cache) const
 
template<typename T >
const T & locate_in_cache (cache_type< T > &cache) const
 
template<typename T >
std::optional< T > copy_from_cache (cache_type< T > &cache) const
 
template<typename T >
void add_to_cache (cache_type< T > &cache, T data) const
 
std::size_t hash () const
 

Private Attributes

value val_
 

Friends

struct std::hash< value >
 
template<typename T >
class cache_type
 

Detailed Description

Generic locator abstracting the location of an image.

Constructing locators is somewhat slow, while accessing images through locators is fast. The general idea is that callers should store locators and not strings to construct new ones. (The latter will still work, of course, even if it is slower.)

Definition at line 62 of file picture.hpp.

Member Enumeration Documentation

◆ type

Enumerator
NONE 
FILE 
SUB_FILE 

Definition at line 65 of file picture.hpp.

Constructor & Destructor Documentation

◆ locator() [1/4]

image::locator::locator ( )
default

◆ locator() [2/4]

image::locator::locator ( locator &&  )
defaultnoexcept

◆ locator() [3/4]

image::locator::locator ( const locator )
default

◆ locator() [4/4]

template<typename... Args>
image::locator::locator ( Args &&...  args)
inline

Definition at line 72 of file picture.hpp.

Member Function Documentation

◆ access_in_cache()

template<typename T >
T & image::locator::access_in_cache ( cache_type< T > &  cache) const

◆ add_to_cache()

template<typename T >
void image::locator::add_to_cache ( cache_type< T > &  cache,
data 
) const

◆ clone()

locator image::locator::clone ( const std::string &  mods) const

Returns a copy of this locator with the given IPF.

Definition at line 234 of file picture.cpp.

References image::locator::value::modifications, SUB_FILE, image::locator::value::type, and val_.

Referenced by unit_frame::get_overlaped_hex(), and unit_frame::redraw().

◆ copy_from_cache()

template<typename T >
std::optional< T > image::locator::copy_from_cache ( cache_type< T > &  cache) const

◆ file_exists()

bool image::locator::file_exists ( ) const

Tests whether the file the locator points at exists.

is_void does not work before the image is loaded, and also a placeholder is returned instead in debug mode. Thus it's not possible to test for the existence of an actual file without this function.

Note
This does not test whether the image is valid or not.
Returns
Whether or not the file exists.

Definition at line 564 of file picture.cpp.

References image::locator::value::filename, filesystem::get_binary_file_location(), image::locator::value::is_data_uri, and val_.

Referenced by attack_info(), intf_get_image_size(), and gui2::unit_preview_pane::print_attack_details().

◆ get_center_x()

int image::locator::get_center_x ( ) const
inline

◆ get_center_y()

int image::locator::get_center_y ( ) const
inline

◆ get_filename()

const std::string& image::locator::get_filename ( ) const
inline

◆ get_loc()

const map_location& image::locator::get_loc ( ) const
inline

◆ get_modifications()

const std::string& image::locator::get_modifications ( ) const
inline

◆ get_type()

type image::locator::get_type ( ) const
inline

Definition at line 91 of file picture.hpp.

References image::locator::value::type, and val_.

Referenced by image::exists(), and image::load_from_disk().

◆ hash()

std::size_t image::locator::hash ( ) const

Definition at line 110 of file picture.cpp.

References val_.

◆ in_cache()

template<typename T >
bool image::locator::in_cache ( cache_type< T > &  cache) const

◆ is_data_uri()

bool image::locator::is_data_uri ( ) const
inline

Definition at line 86 of file picture.hpp.

References image::locator::value::is_data_uri, and val_.

Referenced by image::exists(), and image::load_from_disk().

◆ is_void()

bool image::locator::is_void ( ) const
inline

Returns true if the locator does not correspond to an actual image.

Definition at line 96 of file picture.hpp.

References NONE, image::locator::value::type, and val_.

Referenced by image::get_lighted_image(), image::get_lighted_texture(), unit_frame::get_overlaped_hex(), image::get_surface(), image::get_texture(), unit_frame::merge_parameters(), and unit_frame::redraw().

◆ locate_in_cache()

template<typename T >
const T & image::locator::locate_in_cache ( cache_type< T > &  cache) const

◆ operator!=()

bool image::locator::operator!= ( const locator a) const
inline

Definition at line 83 of file picture.hpp.

References a, and operator==().

◆ operator=() [1/2]

locator& image::locator::operator= ( const locator a)
default

◆ operator=() [2/2]

locator& image::locator::operator= ( locator &&  )
default

◆ operator==()

bool image::locator::operator== ( const locator a) const
inline

Definition at line 82 of file picture.hpp.

References a, and val_.

Referenced by operator!=().

Friends And Related Function Documentation

◆ cache_type

template<typename T >
friend class cache_type
friend

Definition at line 153 of file picture.hpp.

◆ std::hash< value >

friend struct std::hash< value >
friend

Definition at line 147 of file picture.hpp.

Member Data Documentation

◆ val_

value image::locator::val_
private

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