1 #ifndef LXGUI_GUI_LAYOUT_NODE_HPP
2 #define LXGUI_GUI_LAYOUT_NODE_HPP
4 #include "lxgui/gui_out.hpp"
5 #include "lxgui/lxgui.hpp"
6 #include "lxgui/utils.hpp"
7 #include "lxgui/utils_exception.hpp"
8 #include "lxgui/utils_string.hpp"
9 #include "lxgui/utils_view.hpp"
13 #include <string_view>
62 std::size_t line = std::numeric_limits<std::size_t>::max();
65 line = utils::from_string<std::size_t>(
location_.substr(pos + 1)).value_or(line);
75 std::size_t line = std::numeric_limits<std::size_t>::max();
78 line = utils::from_string<std::size_t>(
value_location_.substr(pos + 1)).value_or(line);
108 auto value = utils::from_string<T>(
value_);
109 if (!value.has_value()) {
111 <<
": could not parse value for '" << std::string(
name_) <<
"': '"
112 << std::string(
value_) <<
"'; ignoring" << std::endl;
126 auto value = utils::from_string<T>(
value_);
127 if (!value.has_value()) {
129 std::string(
get_location()) +
": could not parse value for '" + std::string(
name_) +
130 "': '" + std::string(
value_) +
"'");
133 return value.value();
144 auto value = utils::from_string<T>(
value_);
145 if (!value.has_value()) {
147 <<
": could not parse value for '" << std::string(
name_) <<
"': '"
148 << std::string(
value_) <<
"'; using '" << utils::to_string(fallback) <<
"'"
152 return value.value();
176 name_ = std::move(name);
184 value_ = std::move(value);
239 adaptor<const child_list, utils::view::standard_dereferencer, utils::view::no_filter>;
246 return child_list_.size();
256 return child_list_[index];
268 template<
typename BaseIterator>
273 return iter->get_name() ==
filter;
316 std::string(
get_location()) +
": no child found with name '" + std::string(name) +
317 "' in '" + std::string(
name_) +
"'");
337 if (node.get_name() == name)
356 std::string(
get_location()) +
": no attribute found with name '" + std::string(name) +
357 "' in '" + std::string(
name_) +
"'");
376 return attr->get_value();
391 return attr->try_get_value<T>();
407 return attr->get_value_or<T>(fallback);
438 adaptor<const attribute_list, utils::view::standard_dereferencer, utils::view::no_filter>;
454 return child_list_.emplace_back();
462 return attr_list_.emplace_back();
476 return attr->get_value();
479 attr.set_name(std::string(name));
480 attr.set_value(std::string(value));
490 inline std::optional<std::string> layout_attribute::try_get_value<std::string>() const noexcept {
496 inline std::string layout_attribute::get_value<std::string>()
const {
502 inline std::string layout_attribute::get_value_or<std::string>(std::string)
const noexcept {
An attribute in a layout file.
std::size_t get_value_line_number() const noexcept
Returns the line number on which this node's value is located.
std::string_view get_value() const noexcept
Returns this node's value as string.
T get_value() const
Returns this node's value converted to a specific type.
void mark_as_not_accessed() const noexcept
Flag this node as "not accessed" for later warnings.
layout_attribute & operator=(layout_attribute &&)=default
bool is_access_check_bypassed() const noexcept
Check if this node should be bypassed for access checks.
std::string_view get_name() const noexcept
Returns this node's name.
void set_value(std::string value) noexcept
Set this node's value.
bool was_accessed() const noexcept
Check if this node was accessed by the parser.
void set_name(std::string name) noexcept
Set this node's name.
std::string value_location_
std::string_view get_value_location() const noexcept
Returns this node's value location in the file as {file}:{line}.
layout_attribute(const layout_attribute &)=default
std::string_view get_filename() const noexcept
Returns the file in which this node is located.
std::string_view get_location() const noexcept
Returns this node's location in the file as {file}:{line}.
T get_value_or(T fallback) const noexcept
Returns this node's value converted to a specific type, or a default value.
void bypass_access_check() const noexcept
Flag this node as "fully accessed" for later warnings; no check will be done.
layout_attribute & operator=(const layout_attribute &)=default
void set_value_location(std::string location) noexcept
Set this node's value location.
std::size_t get_line_number() const noexcept
Returns the line number on which this node is located.
layout_attribute()=default
layout_attribute(layout_attribute &&)=default
std::optional< T > try_get_value() const noexcept
Returns this node's value converted to a specific type, or nullopt if conversion failed.
void set_location(std::string location) noexcept
Set this node's location.
An node in a layout file.
layout_node(const layout_node &)=default
std::vector< layout_attribute > attribute_list
utils::view::adaptor< const attribute_list, utils::view::standard_dereferencer, utils::view::no_filter > attribute_view
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.
const layout_node & get_child(std::size_t index) const noexcept
Returns a specific child of this node, by index.
bool has_attribute(std::string_view name) const noexcept
Checks if a given attribute has been specified.
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.
layout_node & add_child()
Add a new child to this node.
children_view get_children() const noexcept
Returns a view to the list of children.
layout_node & operator=(layout_node &&)=default
const layout_attribute * try_get_attribute(std::string_view name) const noexcept
Returns the attribute with the provided name, or null if none.
std::size_t get_child_count() const noexcept
Returns the number of children of this node.
const layout_node * try_get_child(std::string_view name) const noexcept
Returns the first child with a given name, or null if none.
utils::view::adaptor< const child_list, utils::view::standard_dereferencer, utils::view::no_filter > children_view
filtered_children_view get_children(std::string_view name) const noexcept
Returns a view to the list of children with a given name.
attribute_view get_attributes() const noexcept
Returns a view to the list of attributes.
std::string_view get_attribute_value(std::string_view name) const
Returns the value of the attribute with the provided name, throws if none.
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.
const layout_node & get_child(std::string_view name) const
Returns the first child with a given name, and throws if none.
const layout_attribute & get_attribute(std::string_view name) const
Returns the value of the first child with the provided name, throws if none.
utils::view::adaptor< const child_list, utils::view::standard_dereferencer, name_filter > filtered_children_view
layout_attribute & add_attribute()
Add a new attribute to this node.
layout_node & operator=(const layout_node &)=default
layout_node(layout_node &&)=default
std::vector< layout_node > child_list
bool has_child(std::string_view name) const noexcept
Checks if at least one child exists with the given name.
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 faile...
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.
Allow iterating over a container without access to the container itself.
const std::string warning
bool is_included(const BaseIterator &iter) const noexcept