xtd 1.0.0
Loading...
Searching...
No Matches
css_writer.hpp
Go to the documentation of this file.
1
4#pragma once
7#include "../../object.hpp"
8
10namespace xtd {
11 namespace web {
12 namespace css {
13 class css_writer : public object {
14 public:
16
18 css_writer(std::ostream& stream) : text_writer_(new xtd::io::stream_writer(stream)) {}
19 css_writer(xtd::io::text_writer& text_writer) : text_writer_(&text_writer), delete_when_destroy_(false) {}
20 css_writer(const xtd::string& path) : text_writer_(new xtd::io::stream_writer(path)) {}
23 ~css_writer() {if (delete_when_destroy_) delete text_writer_;}
25
27
29 [[nodiscard]] auto selectors() const noexcept -> const xtd::web::css::selector_dictionary& {return selectors_;}
30 [[nodiscard]] auto selectors() noexcept -> xtd::web::css::selector_dictionary& {return selectors_;}
31 auto selectors(const xtd::web::css::selector_dictionary& selector) -> void {selectors_ = selector;}
33
35
37 auto write() -> void {
38 if (!text_writer_) return;
39 for (const auto& selector : selectors_) {
40 text_writer_->write_line("{} {{", selector.first);
41 for (const auto& property : selector.second.properties())
42 text_writer_->write_line(" {}: {};", property.first, property.second);
43 text_writer_->write_line("}");
44 }
45 }
47
48 private:
50 xtd::io::text_writer* text_writer_ = nullptr;
51 bool delete_when_destroy_ = true;
52 };
53 }
54 }
55}
Implements a xtd::io::text_writer for writing characters to a stream.
Definition stream_writer.hpp:28
Represents a writer that can write a sequential series of characters.
Definition text_writer.hpp:36
object()=default
Create a new instance of the ultimate base class object.
Definition property.hpp:14
Definition selector.hpp:12
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
@ path
The xtd::uri::local_path data.
Definition uri_components.hpp:27
Contains classes and interfaces that enable browser-server communication. This namespace includes the...
Definition css_reader.hpp:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::object class.
Contains xtd::web::css::selector_dictionary alias.
xtd::collections::generic::sorted_dictionary< xtd::string, xtd::web::css::selector > selector_dictionary
Represents the dictionary of a selector name - selector pair.
Definition selector_dictionary.hpp:13
Contains xtd::io::stream_writer class.