48#include <snapdev/poison.h>
86 ss <<
"trying to access (read/write) the integer of a node of type " << type <<
", which does not support integers.";
106 std::stringstream ss;
107 ss <<
"trying to access (read/write) the boolean of a node of type " << type <<
", which does not support booleans.";
125 std::stringstream ss;
126 ss <<
"trying to access (read/write) the decimal number of a node of type " << type <<
", which does not support decimal numbers.";
155 std::stringstream ss;
156 ss <<
"trying to access (read/write) the string of a node of type " << type <<
", which does not support strings.";
172 std::stringstream ss;
173 ss <<
"trying to access (read/write) the color of a node of type " << type <<
", which does not support colors.";
189 std::stringstream ss;
190 ss <<
"trying to access (read/write) the line height of a node of type " << type <<
", which does not support line heights.";
217 std::stringstream ss;
218 ss <<
"trying to access (read/write) the children of a node of type " << type <<
", which does not support children.";
232 if(g_node_max_count != 0
233 && g_node_count >= g_node_max_count)
240 std::cerr <<
"error: node of type " << type <<
" cannot be allocated.\n";
241 throw csspp_exception_overflow(
"node.cpp: node::node() too many nodes allocated at the same time, we are probably having a leak.");
264 result->f_children.push_back(c->clone());
267 result->copy_variable(
const_cast<node *
>(
this)->shared_from_this());
306#pragma GCC diagnostic push
307#pragma GCC diagnostic ignored "-Wfloat-equal"
309#pragma GCC diagnostic pop
345 type_supports_string(
f_type);
351 type_supports_string(
f_type);
357 type_supports_string(
f_type);
363 type_supports_string(
f_type);
369 type_supports_integer(
f_type);
375 type_supports_integer(
f_type);
381 type_supports_boolean(
f_type);
387 type_supports_boolean(
f_type);
393 type_supports_decimal_number(
f_type);
399 type_supports_decimal_number(
f_type);
405 type_supports_color(
f_type);
407 union color_transfer_t
414 color_transfer_t c1, c2;
419 c.
set_color(c1.f_flt[0], c1.f_flt[1], c2.f_flt[0], c2.f_flt[1]);
426 type_supports_color(
f_type);
428 union color_transfer_t
435 color_transfer_t c1, c2;
436 c.
get_color(c1.f_flt[0], c1.f_flt[1], c2.f_flt[0], c2.f_flt[1]);
444 type_supports_font_metrics(
f_type);
451 type_supports_font_metrics(
f_type);
458 type_supports_font_metrics(
f_type);
467 type_supports_font_metrics(
f_type);
470 c.f_flt = line_height;
476 type_supports_font_metrics(
f_type);
478 std::string::size_type pos(
f_string.find(
'/'));
479 if(pos == std::string::npos)
491 type_supports_font_metrics(
f_type);
499 std::string::size_type pos(
f_string.find(
'/'));
500 if(pos == std::string::npos)
513 type_supports_font_metrics(
f_type);
515 std::string::size_type pos(
f_string.find(
'/'));
516 if(pos == std::string::npos)
528 type_supports_font_metrics(
f_type);
530 if(dimension.empty())
532 std::string::size_type pos(
f_string.find(
'/'));
533 if(pos != std::string::npos)
547 std::string::size_type pos(
f_string.find(
'/'));
548 if(pos == std::string::npos)
561 type_supports_children(
f_type);
568 type_supports_children(
f_type);
575 type_supports_children(
f_type);
582 type_supports_children(
f_type);
595 type_supports_children(
f_type);
621 type_supports_children(
f_type);
637 type_supports_children(
f_type);
650 type_supports_children(
f_type);
662 type_supports_children(
f_type);
680 type_supports_children(
f_type);
681 type_supports_children(n->f_type);
699 throw csspp_exception_logic(
"replace_child() called with a node which is not a child of this node.");
721 for(
auto v : source->f_variables)
767 std::stringstream out;
819 std::string::size_type start(0);
820 std::string::size_type end(
f_string.find(
'\n'));
821 while(end != std::string::npos)
823 out <<
"// " <<
f_string.substr(start, end - start) << std::endl;
829 out <<
"// " <<
f_string.substr(start) << std::endl;
882#if __cplusplus >= 201700
899 out << c->to_string(flags);
966 out << c->to_string(flags);
975 out << c->to_string(flags);
984 out << c->to_string(flags);
1030 for(
char const *s(
f_string.c_str()); *s !=
'\0'; ++s)
1045 for(
char const *s(
f_string.c_str()); *s !=
'\0'; ++s)
1062 for(
char const *s(
f_string.c_str()); *s !=
'\0'; ++s)
1079 for(
char const *s(
f_string.c_str()); *s !=
'\0'; ++s)
1132 switch(
static_cast<node_type_t>(c->get_integer()))
1148 out << c->to_string(flags);
1154 out << c->to_string(flags);
1170 out << c->to_string(flags);
1179 for(
size_t idx(0); idx <
f_children.size(); ++idx)
1198 for(
size_t idx(0); idx <
f_children.size(); ++idx)
1281 out << c->to_string(flags);
1305 std::string indent_str;
1306 for(uint32_t i(0); i < indent; ++i)
1310 out << indent_str <<
f_type;
1340 out <<
" B:" << (
f_boolean ?
"true" :
"false");
1367 out <<
" H:" << std::hex << c.
get_color() << std::dec;
1417 out <<
" F:" << f.first;
1424 out << indent_str <<
" V:" << v.first <<
"\n";
1425 v.second->display(out, indent + 6);
1460 g_node_max_count = count;
1482 out <<
"ASSIGNMENT";
1486 out <<
"AT_KEYWORD";
1502 out <<
"CLOSE_CURLYBRACKET";
1506 out <<
"CLOSE_PARENTHESIS";
1510 out <<
"CLOSE_SQUAREBRACKET";
1534 out <<
"CONDITIONAL";
1538 out <<
"DASH_MATCH";
1542 out <<
"DECIMAL_NUMBER";
1562 out <<
"EXCLAMATION";
1566 out <<
"FONT_METRICS";
1574 out <<
"GREATER_EQUAL";
1578 out <<
"GREATER_THAN";
1586 out <<
"IDENTIFIER";
1590 out <<
"INCLUDE_MATCH";
1598 out <<
"LESS_EQUAL";
1618 out <<
"NULL_TOKEN";
1622 out <<
"OPEN_CURLYBRACKET";
1626 out <<
"OPEN_PARENTHESIS";
1630 out <<
"OPEN_SQUAREBRACKET";
1642 out <<
"PLACEHOLDER";
1654 out <<
"PREFIX_MATCH";
1674 out <<
"SUBSTRING_MATCH";
1682 out <<
"SUFFIX_MATCH";
1686 out <<
"UNICODE_RANGE";
1698 out <<
"VARIABLE_FUNCTION";
1702 out <<
"WHITESPACE";
1719 out <<
"COMPONENT_VALUE";
1723 out <<
"DECLARATION";
1755 std::stringstream ss;
rgba_color_t get_color() const
void set_color(rgba_color_t const rgba)
std::string to_string() const
void add_child(pointer_t child)
integer_t get_integer() const
void copy_variable(node::pointer_t source)
variable_table_t f_variables
void take_over_children_of(pointer_t n)
void remove_child(pointer_t child)
void set_flag(std::string const &name, bool value)
pointer_t get_last_child() const
position const & get_position() const
void set_line_height(decimal_number_t line_height)
pointer_t get_child(size_t idx) const
bool get_flag(std::string const &name)
void display(std::ostream &out, uint32_t indent) const
pointer_t get_variable(std::string const &name)
void set_dim1(std::string const &font_size)
static int const g_to_string_flag_add_spaces
bool is(node_type_t const type) const
void set_boolean(bool integer)
node_type_t get_type() const
std::string const & get_lowercase_string() const
void set_string(std::string const &str)
void set_dim2(std::string const &line_height)
decimal_number_t get_font_size() const
std::string get_dim1() const
decimal_number_t get_decimal_number() const
void insert_child(size_t idx, pointer_t child)
size_t child_position(pointer_t child)
std::string to_string(int flags) const
void set_decimal_number(decimal_number_t decimal_number)
std::string f_lowercase_string
std::string get_dim2() const
std::string const & get_string() const
boolean_t to_boolean() const
static int const g_to_string_flag_show_quotes
static void limit_nodes_to(uint32_t count)
void replace_child(pointer_t o, pointer_t n)
node(node_type_t const type, position const &pos)
void set_font_size(decimal_number_t font_size)
void set_integer(integer_t integer)
decimal_number_t get_line_height() const
void set_lowercase_string(std::string const &str)
std::shared_ptr< node > pointer_t
decimal_number_t f_decimal_number
void set_variable(std::string const &name, pointer_t value)
std::string to_string() const
std::string to_string() const
void type_supports_color(node_type_t const type)
void type_supports_font_metrics(node_type_t const type)
void type_supports_integer(node_type_t const type)
void type_supports_decimal_number(node_type_t const type)
uint32_t g_node_max_count
void type_supports_children(node_type_t const type)
void type_supports_boolean(node_type_t const type)
void type_supports_string(node_type_t const type)
The namespace of all the classes in the CSS Preprocessor.
std::string decimal_number_to_string(decimal_number_t d, bool remove_leading_zero)
std::ostream & operator<<(std::ostream &out, csspp::node_type_t const type)