lxgui
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
lxgui::gui::layout_node Class Reference

An node in a layout file. More...

#include <gui_layout_node.hpp>

Inheritance diagram for lxgui::gui::layout_node:
lxgui::gui::layout_attribute

Classes

struct  name_filter
 

Public Types

using child_list = std::vector< layout_node >
 
using children_view = utils::view::adaptor< const child_list, utils::view::standard_dereferencer, utils::view::no_filter >
 
using filtered_children_view = utils::view::adaptor< const child_list, utils::view::standard_dereferencer, name_filter >
 
using attribute_list = std::vector< layout_attribute >
 
using attribute_view = utils::view::adaptor< const attribute_list, utils::view::standard_dereferencer, utils::view::no_filter >
 

Public Member Functions

 layout_node ()=default
 
 layout_node (const layout_node &)=default
 
 layout_node (layout_node &&)=default
 
layout_nodeoperator= (const layout_node &)=default
 
layout_nodeoperator= (layout_node &&)=default
 
std::size_t get_child_count () const noexcept
 Returns the number of children of this node. More...
 
const layout_nodeget_child (std::size_t index) const noexcept
 Returns a specific child of this node, by index. More...
 
children_view get_children () const noexcept
 Returns a view to the list of children. More...
 
filtered_children_view get_children (std::string_view name) const noexcept
 Returns a view to the list of children with a given name. More...
 
const layout_nodetry_get_child (std::string_view name) const noexcept
 Returns the first child with a given name, or null if none. More...
 
const layout_nodeget_child (std::string_view name) const
 Returns the first child with a given name, and throws if none. More...
 
bool has_child (std::string_view name) const noexcept
 Checks if at least one child exists with the given name. More...
 
const layout_attributetry_get_attribute (std::string_view name) const noexcept
 Returns the attribute with the provided name, or null if none. More...
 
const layout_attributeget_attribute (std::string_view name) const
 Returns the value of the first child with the provided name, throws if none. More...
 
bool has_attribute (std::string_view name) const noexcept
 Checks if a given attribute has been specified. More...
 
std::optional< std::string_view > try_get_attribute_value (std::string_view name) const noexcept
 Returns the value of the attribute with the provided name, nullopt if not found. More...
 
template<typename T >
std::optional< T > try_get_attribute_value (std::string_view name) const noexcept
 Returns the value of the attribute with the provided name, nullopt if not found or parsing failed. More...
 
template<typename T >
get_attribute_value_or (std::string_view name, T fallback) const noexcept
 Returns the value of the attribute with the provided name, or a default if not found or parsing failed. More...
 
std::string_view get_attribute_value (std::string_view name) const
 Returns the value of the attribute with the provided name, throws if none. More...
 
template<typename T >
get_attribute_value (std::string_view name) const
 Returns the value of the attribute with the provided name, throws if not found or parsing failed. More...
 
attribute_view get_attributes () const noexcept
 Returns a view to the list of attributes. More...
 
layout_nodeadd_child ()
 Add a new child to this node. More...
 
layout_attributeadd_attribute ()
 Add a new attribute to this node. More...
 
std::string_view get_or_set_attribute_value (std::string_view name, std::string_view value)
 Returns the value of the attribute with the provided name, or set it if none. More...
 
std::string_view get_location () const noexcept
 Returns this node's location in the file as {file}:{line}. More...
 
std::string_view get_value_location () const noexcept
 Returns this node's value location in the file as {file}:{line}. More...
 
std::string_view get_filename () const noexcept
 Returns the file in which this node is located. More...
 
std::size_t get_line_number () const noexcept
 Returns the line number on which this node is located. More...
 
std::size_t get_value_line_number () const noexcept
 Returns the line number on which this node's value is located. More...
 
std::string_view get_name () const noexcept
 Returns this node's name. More...
 
std::string_view get_value () const noexcept
 Returns this node's value as string. More...
 
template<typename T >
get_value () const
 Returns this node's value converted to a specific type. More...
 
template<typename T >
std::optional< T > try_get_value () const noexcept
 Returns this node's value converted to a specific type, or nullopt if conversion failed. More...
 
template<typename T >
get_value_or (T fallback) const noexcept
 Returns this node's value converted to a specific type, or a default value. More...
 
void set_location (std::string location) noexcept
 Set this node's location. More...
 
void set_value_location (std::string location) noexcept
 Set this node's value location. More...
 
void set_name (std::string name) noexcept
 Set this node's name. More...
 
void set_value (std::string value) noexcept
 Set this node's value. More...
 
void mark_as_not_accessed () const noexcept
 Flag this node as "not accessed" for later warnings. More...
 
void bypass_access_check () const noexcept
 Flag this node as "fully accessed" for later warnings; no check will be done. More...
 
bool was_accessed () const noexcept
 Check if this node was accessed by the parser. More...
 
bool is_access_check_bypassed () const noexcept
 Check if this node should be bypassed for access checks. More...
 

Protected Attributes

std::string name_
 
std::string value_
 
std::string location_
 
std::string value_location_
 
bool accessed_ = false
 
bool access_bypass_ = false
 

Detailed Description

An node in a layout file.

This is a format-agnostic representation of a GUI layout, as read for example from an XML or YAML file. The GUI uses this class to de-couple the layout parsing format (XML, YAML, etc) from the actual parsed layout.

Definition at line 229 of file gui_layout_node.hpp.

Member Typedef Documentation

◆ attribute_list

Definition at line 436 of file gui_layout_node.hpp.

◆ attribute_view

Definition at line 437 of file gui_layout_node.hpp.

◆ child_list

Definition at line 237 of file gui_layout_node.hpp.

◆ children_view

Definition at line 238 of file gui_layout_node.hpp.

◆ filtered_children_view

Definition at line 277 of file gui_layout_node.hpp.

Constructor & Destructor Documentation

◆ layout_node() [1/3]

lxgui::gui::layout_node::layout_node ( )
default

◆ layout_node() [2/3]

lxgui::gui::layout_node::layout_node ( const layout_node )
default

◆ layout_node() [3/3]

lxgui::gui::layout_node::layout_node ( layout_node &&  )
default

Member Function Documentation

◆ add_attribute()

layout_attribute& lxgui::gui::layout_node::add_attribute ( )
inline

Add a new attribute to this node.

Returns
A reference to the added attribute

Definition at line 461 of file gui_layout_node.hpp.

◆ add_child()

layout_node& lxgui::gui::layout_node::add_child ( )
inline

Add a new child to this node.

Returns
A reference to the added child

Definition at line 453 of file gui_layout_node.hpp.

◆ bypass_access_check()

void lxgui::gui::layout_attribute::bypass_access_check ( ) const
inlinenoexceptinherited

Flag this node as "fully accessed" for later warnings; no check will be done.

Definition at line 193 of file gui_layout_node.hpp.

◆ get_attribute()

const layout_attribute& lxgui::gui::layout_node::get_attribute ( std::string_view  name) const
inline

Returns the value of the first child with the provided name, throws if none.

Parameters
nameThe name to look for
Returns
The value of the first child with the provided name.
Note
Will throw if no attribute is found with this name. Use try_get_attribute() to avoid throwing.

Definition at line 351 of file gui_layout_node.hpp.

◆ get_attribute_value() [1/2]

std::string_view lxgui::gui::layout_node::get_attribute_value ( std::string_view  name) const
inline

Returns the value of the attribute with the provided name, throws if none.

Parameters
nameThe name to look for
Returns
The value of the attribute with the provided name.
Note
Will throw if no attribute is found with this name. Use get_attribute_value_or() or try_get_attribute_value() to avoid throwing.

Definition at line 419 of file gui_layout_node.hpp.

◆ get_attribute_value() [2/2]

template<typename T >
T lxgui::gui::layout_node::get_attribute_value ( std::string_view  name) const
inline

Returns the value of the attribute with the provided name, throws if not found or parsing failed.

Parameters
nameThe name to look for
Returns
The value of the attribute with the provided name.
Note
Will throw if no attribute is found with this name or if parsing failed. Use get_attribute_value_or() or try_get_attribute_value() to avoid throwing.

Definition at line 432 of file gui_layout_node.hpp.

◆ get_attribute_value_or()

template<typename T >
T lxgui::gui::layout_node::get_attribute_value_or ( std::string_view  name,
fallback 
) const
inlinenoexcept

Returns the value of the attribute with the provided name, or a default if not found or parsing failed.

Parameters
nameThe name to look for
fallbackThe fallback value
Returns
The value of the attribute with the provided name, or a default if not found or parsing failed.

Definition at line 405 of file gui_layout_node.hpp.

◆ get_attributes()

attribute_view lxgui::gui::layout_node::get_attributes ( ) const
inlinenoexcept

Returns a view to the list of attributes.

Returns
A view to the list of attributes

Definition at line 444 of file gui_layout_node.hpp.

◆ get_child() [1/2]

const layout_node& lxgui::gui::layout_node::get_child ( std::size_t  index) const
inlinenoexcept

Returns a specific child of this node, by index.

Parameters
indexThe index (starting from 0) of this child
Returns
The child at the specified index

Definition at line 254 of file gui_layout_node.hpp.

◆ get_child() [2/2]

const layout_node& lxgui::gui::layout_node::get_child ( std::string_view  name) const
inline

Returns the first child with a given name, and throws if none.

Parameters
nameThe name to look for
Returns
The first child with a given name, and throws if none
Note
Will throw if no child is found with this name. Use try_get_child() to avoid throwing.

Definition at line 311 of file gui_layout_node.hpp.

◆ get_child_count()

std::size_t lxgui::gui::layout_node::get_child_count ( ) const
inlinenoexcept

Returns the number of children of this node.

Returns
The number of children of this node

Definition at line 245 of file gui_layout_node.hpp.

◆ get_children() [1/2]

children_view lxgui::gui::layout_node::get_children ( ) const
inlinenoexcept

Returns a view to the list of children.

Returns
A view to the list of children

Definition at line 263 of file gui_layout_node.hpp.

◆ get_children() [2/2]

filtered_children_view lxgui::gui::layout_node::get_children ( std::string_view  name) const
inlinenoexcept

Returns a view to the list of children with a given name.

Parameters
nameThe name to look for
Returns
A view to the list of children with a given name

Definition at line 285 of file gui_layout_node.hpp.

◆ get_filename()

std::string_view lxgui::gui::layout_attribute::get_filename ( ) const
inlinenoexceptinherited

Returns the file in which this node is located.

Returns
The file in which this node is located

Definition at line 52 of file gui_layout_node.hpp.

◆ get_line_number()

std::size_t lxgui::gui::layout_attribute::get_line_number ( ) const
inlinenoexceptinherited

Returns the line number on which this node is located.

Returns
The line number on which this node is located

Definition at line 61 of file gui_layout_node.hpp.

◆ get_location()

std::string_view lxgui::gui::layout_attribute::get_location ( ) const
inlinenoexceptinherited

Returns this node's location in the file as {file}:{line}.

Returns
This node's location in the file as {file}:{line}

Definition at line 36 of file gui_layout_node.hpp.

◆ get_name()

std::string_view lxgui::gui::layout_attribute::get_name ( ) const
inlinenoexceptinherited

Returns this node's name.

Returns
This node's name

Definition at line 87 of file gui_layout_node.hpp.

◆ get_or_set_attribute_value()

std::string_view lxgui::gui::layout_node::get_or_set_attribute_value ( std::string_view  name,
std::string_view  value 
)
inline

Returns the value of the attribute with the provided name, or set it if none.

Parameters
nameThe name to look for
valueThe value to set if the attribute is missing
Returns
The value of the attribute with the provided name.
Note
This will modify the layout node object if the value is missing. If you need a non-modifying alternative, use get_attribute_value_or().

Definition at line 473 of file gui_layout_node.hpp.

◆ get_value() [1/2]

template<typename T >
T lxgui::gui::layout_attribute::get_value ( ) const
inlineinherited

Returns this node's value converted to a specific type.

Returns
This node's value converted to a specific type
Note
Will throw if the value could not be converted. Use get_value_or() to avoid throwing.

Definition at line 124 of file gui_layout_node.hpp.

◆ get_value() [2/2]

std::string_view lxgui::gui::layout_attribute::get_value ( ) const
inlinenoexceptinherited

Returns this node's value as string.

Returns
This node's value as string
Note
Returns an empty string if none

Definition at line 96 of file gui_layout_node.hpp.

◆ get_value_line_number()

std::size_t lxgui::gui::layout_attribute::get_value_line_number ( ) const
inlinenoexceptinherited

Returns the line number on which this node's value is located.

Returns
The line number on which this node's value is located

Definition at line 74 of file gui_layout_node.hpp.

◆ get_value_location()

std::string_view lxgui::gui::layout_attribute::get_value_location ( ) const
inlinenoexceptinherited

Returns this node's value location in the file as {file}:{line}.

Returns
This node's value location in the file as {file}:{line}

Definition at line 44 of file gui_layout_node.hpp.

◆ get_value_or()

template<typename T >
T lxgui::gui::layout_attribute::get_value_or ( fallback) const
inlinenoexceptinherited

Returns this node's value converted to a specific type, or a default value.

Returns
This node's value converted to a specific type, or a default value
Note
Will return the default value if the value could not be converted.

Definition at line 142 of file gui_layout_node.hpp.

◆ has_attribute()

bool lxgui::gui::layout_node::has_attribute ( std::string_view  name) const
inlinenoexcept

Checks if a given attribute has been specified.

Parameters
nameThe name to look for
Returns
'true' if attribute is specified, 'false' otherwise

Definition at line 365 of file gui_layout_node.hpp.

◆ has_child()

bool lxgui::gui::layout_node::has_child ( std::string_view  name) const
inlinenoexcept

Checks if at least one child exists with the given name.

Parameters
nameThe name to look for
Returns
'true' if at least one child exists, 'false' otherwise

Definition at line 325 of file gui_layout_node.hpp.

◆ is_access_check_bypassed()

bool lxgui::gui::layout_attribute::is_access_check_bypassed ( ) const
inlinenoexceptinherited

Check if this node should be bypassed for access checks.

Returns
'true' if this node should be bypassed, 'false' otherwise.

Definition at line 209 of file gui_layout_node.hpp.

◆ mark_as_not_accessed()

void lxgui::gui::layout_attribute::mark_as_not_accessed ( ) const
inlinenoexceptinherited

Flag this node as "not accessed" for later warnings.

Definition at line 188 of file gui_layout_node.hpp.

◆ operator=() [1/2]

layout_node& lxgui::gui::layout_node::operator= ( const layout_node )
default

◆ operator=() [2/2]

layout_node& lxgui::gui::layout_node::operator= ( layout_node &&  )
default

◆ set_location()

void lxgui::gui::layout_attribute::set_location ( std::string  location)
inlinenoexceptinherited

Set this node's location.

Parameters
locationThe new location

Definition at line 159 of file gui_layout_node.hpp.

◆ set_name()

void lxgui::gui::layout_attribute::set_name ( std::string  name)
inlinenoexceptinherited

Set this node's name.

Parameters
nameThe new name

Definition at line 175 of file gui_layout_node.hpp.

◆ set_value()

void lxgui::gui::layout_attribute::set_value ( std::string  value)
inlinenoexceptinherited

Set this node's value.

Parameters
valueThe new value

Definition at line 183 of file gui_layout_node.hpp.

◆ set_value_location()

void lxgui::gui::layout_attribute::set_value_location ( std::string  location)
inlinenoexceptinherited

Set this node's value location.

Parameters
locationThe new value location

Definition at line 167 of file gui_layout_node.hpp.

◆ try_get_attribute()

const layout_attribute* lxgui::gui::layout_node::try_get_attribute ( std::string_view  name) const
inlinenoexcept

Returns the attribute with the provided name, or null if none.

Parameters
nameThe name to look for
Returns
The attribute with the provided name, or null if none

Definition at line 334 of file gui_layout_node.hpp.

◆ try_get_attribute_value() [1/2]

std::optional<std::string_view> lxgui::gui::layout_node::try_get_attribute_value ( std::string_view  name) const
inlinenoexcept

Returns the value of the attribute with the provided name, nullopt if not found.

Parameters
nameThe name to look for
Returns
The value of the attribute with the provided name, or nullopt if not found.

Definition at line 374 of file gui_layout_node.hpp.

◆ try_get_attribute_value() [2/2]

template<typename T >
std::optional<T> lxgui::gui::layout_node::try_get_attribute_value ( std::string_view  name) const
inlinenoexcept

Returns the value of the attribute with the provided name, nullopt if not found or parsing failed.

Parameters
nameThe name to look for
Returns
The value of the attribute with the provided name, nullopt if not found or parsing failed.

Definition at line 389 of file gui_layout_node.hpp.

◆ try_get_child()

const layout_node* lxgui::gui::layout_node::try_get_child ( std::string_view  name) const
inlinenoexcept

Returns the first child with a given name, or null if none.

Parameters
nameThe name to look for
Returns
The first child with a given name, or null if none

Definition at line 295 of file gui_layout_node.hpp.

◆ try_get_value()

template<typename T >
std::optional<T> lxgui::gui::layout_attribute::try_get_value ( ) const
inlinenoexceptinherited

Returns this node's value converted to a specific type, or nullopt if conversion failed.

Returns
This node's value converted to a specific type, or nullopt if conversion failed

Definition at line 106 of file gui_layout_node.hpp.

◆ was_accessed()

bool lxgui::gui::layout_attribute::was_accessed ( ) const
inlinenoexceptinherited

Check if this node was accessed by the parser.

Returns
'true' if this node was accessed by the parser, 'false' otherwise.

Definition at line 201 of file gui_layout_node.hpp.

Member Data Documentation

◆ access_bypass_

bool lxgui::gui::layout_attribute::access_bypass_ = false
mutableprotectedinherited

Definition at line 220 of file gui_layout_node.hpp.

◆ accessed_

bool lxgui::gui::layout_attribute::accessed_ = false
mutableprotectedinherited

Definition at line 219 of file gui_layout_node.hpp.

◆ location_

std::string lxgui::gui::layout_attribute::location_
protectedinherited

Definition at line 216 of file gui_layout_node.hpp.

◆ name_

std::string lxgui::gui::layout_attribute::name_
protectedinherited

Definition at line 214 of file gui_layout_node.hpp.

◆ value_

std::string lxgui::gui::layout_attribute::value_
protectedinherited

Definition at line 215 of file gui_layout_node.hpp.

◆ value_location_

std::string lxgui::gui::layout_attribute::value_location_
protectedinherited

Definition at line 217 of file gui_layout_node.hpp.


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