The Battle for Wesnoth  1.17.0-dev
Classes | Public Types | Public Member Functions | Private 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 }
 
typedef std::unordered_map< value, int > locator_finder_t
 

Public Member Functions

 locator ()
 
 locator (const locator &a, const std::string &mods="")
 
 locator (const char *filename)
 
 locator (const std::string &filename)
 
 locator (const std::string &filename, const std::string &modifications)
 
 locator (const std::string &filename, const map_location &loc, int center_x, int center_y, const std::string &modifications="")
 
locatoroperator= (const locator &a)
 
bool operator== (const locator &a) const
 
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 >
void add_to_cache (cache_type< T > &cache, const T &data) const
 

Private Member Functions

void init_index ()
 
void parse_arguments ()
 

Private Attributes

int index_
 
value val_
 

Friends

struct std::hash< value >
 

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 60 of file picture.hpp.

Member Typedef Documentation

◆ locator_finder_t

typedef std::unordered_map<value, int> image::locator::locator_finder_t

Definition at line 144 of file picture.hpp.

Member Enumeration Documentation

◆ type

Enumerator
NONE 
FILE 
SUB_FILE 

Definition at line 63 of file picture.hpp.

Constructor & Destructor Documentation

◆ locator() [1/6]

image::locator::locator ( )

Definition at line 288 of file picture.cpp.

◆ locator() [2/6]

image::locator::locator ( const locator a,
const std::string &  mods = "" 
)

◆ locator() [3/6]

image::locator::locator ( const char *  filename)

Definition at line 307 of file picture.cpp.

References init_index(), and parse_arguments().

◆ locator() [4/6]

image::locator::locator ( const std::string &  filename)

Definition at line 315 of file picture.cpp.

References init_index(), and parse_arguments().

◆ locator() [5/6]

image::locator::locator ( const std::string &  filename,
const std::string &  modifications 
)

Definition at line 323 of file picture.cpp.

References init_index().

◆ locator() [6/6]

image::locator::locator ( const std::string &  filename,
const map_location loc,
int  center_x,
int  center_y,
const std::string &  modifications = "" 
)

Definition at line 330 of file picture.cpp.

References init_index().

Member Function Documentation

◆ access_in_cache()

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

Definition at line 138 of file picture.cpp.

References dummy, and image::cache_type< T >::get_element().

Referenced by image::get_lighted_image(), and is_void().

◆ add_to_cache()

template<typename T >
void image::locator::add_to_cache ( cache_type< T > &  cache,
const T &  data 
) 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 659 of file picture.cpp.

References image::locator::value::filename_, filesystem::get_binary_file_location(), image::locator::value::is_data_uri_, and val_.

Referenced by adjust_profile(), attack_info(), intf_get_image_size(), is_void(), 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 84 of file picture.hpp.

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

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

◆ in_cache()

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

◆ init_index()

void image::locator::init_index ( )
private

Definition at line 248 of file picture.cpp.

References i, and val_.

Referenced by is_void(), and locator().

◆ is_data_uri()

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

Definition at line 79 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

◆ 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 75 of file picture.hpp.

References index_.

◆ operator<()

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

Definition at line 76 of file picture.hpp.

References index_.

◆ operator=()

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

Definition at line 341 of file picture.cpp.

References index_, and val_.

◆ operator==()

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

Definition at line 74 of file picture.hpp.

References index_.

◆ parse_arguments()

void image::locator::parse_arguments ( )
private

Definition at line 260 of file picture.cpp.

References ERR_DP, and val_.

Referenced by is_void(), and locator().

Friends And Related Function Documentation

◆ std::hash< value >

friend struct std::hash< value >
friend

Definition at line 147 of file picture.hpp.

Member Data Documentation

◆ index_

int image::locator::index_
private

Definition at line 149 of file picture.hpp.

Referenced by locator(), operator!=(), operator<(), operator=(), and operator==().

◆ val_

value image::locator::val_
private

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