neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
css.hpp
Go to the documentation of this file.
1// css.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
26
27namespace neogfx
28{
29 class css
30 {
31 public:
33 {
34 public:
35 typedef std::string element;
36 typedef std::optional<element> optional_element;
84 typedef std::variant<std::monostate, std::string> pseudo_class_argument;
85 typedef std::variant<std::monostate, std::string, std::pair<pseudo_class_e, pseudo_class_argument>> argument;
87 typedef std::pair<type_e, arguments_type> value_type;
88 public:
89 selector(type_e aType, const arguments_type& aArguments = arguments_type());
90 public:
91 type_e type() const;
92 const arguments_type& arguments() const;
93 private:
94 type_e iType;
95 arguments_type iArguments;
96 };
98 {
99 public:
101 };
102 typedef std::vector<declaration> declaration_block;
103 typedef std::list<selector> selector_list;
104 typedef std::list<declaration_block> declaration_block_list;
105 typedef std::vector<std::pair<selector_list::const_iterator, declaration_block_list::const_iterator>> rule_list;
106 public:
108 {
109 public:
110 virtual std::string const& element_name() = 0;
111 virtual std::string const& id() = 0;
112 virtual bool has_parent() = 0;
113 virtual i_visitor& parent() = 0;
114 public:
115 virtual void apply(const declaration_block& aDeclarations) = 0;
116 };
117 public:
118 struct failed_to_open_style_sheet : std::runtime_error { failed_to_open_style_sheet() : std::runtime_error("neogfx::css::failed_to_open_style_sheet") {} };
119 public:
120 css(std::string const& aStyle);
121 css(std::istream& aStyleSheet);
122 public:
123 void accept(i_visitor& aVisitor) const;
124 const rule_list& rules() const;
125 std::string to_string() const;
126 private:
127 void parse();
128 private:
129 std::shared_ptr<std::istream> iStyleSheet;
130 rule_list iRules;
131 };
132}
virtual void apply(const declaration_block &aDeclarations)=0
virtual bool has_parent()=0
virtual i_visitor & parent()=0
virtual std::string const & id()=0
virtual std::string const & element_name()=0
@ ArbitrarySubstringAttributeValue
Definition css.hpp:52
@ EndingSubstringAttributeValue
Definition css.hpp:51
@ BeginniingSubstringAttributeValue
Definition css.hpp:50
std::pair< type_e, arguments_type > value_type
Definition css.hpp:87
selector(type_e aType, const arguments_type &aArguments=arguments_type())
std::string element
Definition css.hpp:35
std::optional< element > optional_element
Definition css.hpp:36
neolib::vecarray< argument, 4, -1 > arguments_type
Definition css.hpp:86
const arguments_type & arguments() const
type_e type() const
std::variant< std::monostate, std::string > pseudo_class_argument
Definition css.hpp:84
std::variant< std::monostate, std::string, std::pair< pseudo_class_e, pseudo_class_argument > > argument
Definition css.hpp:85
std::vector< std::pair< selector_list::const_iterator, declaration_block_list::const_iterator > > rule_list
Definition css.hpp:105
css(std::string const &aStyle)
std::list< selector > selector_list
Definition css.hpp:103
void accept(i_visitor &aVisitor) const
std::string to_string() const
std::vector< declaration > declaration_block
Definition css.hpp:102
css(std::istream &aStyleSheet)
std::list< declaration_block > declaration_block_list
Definition css.hpp:104
const rule_list & rules() const