xtd - Reference Guide  0.1.2
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
css_writer.h
Go to the documentation of this file.
1
4#pragma once
5#include "selector_map.h"
6#include "../../argument_exception.h"
7#include "../../format_exception.h"
8#include "../../object.h"
9#include "../../io/stream_writer.h"
10
12namespace xtd {
13 namespace web {
14 namespace css {
15 class css_writer : public object {
16 public:
17 css_writer(std::ostream& stream) : text_writer_(new xtd::io::stream_writer(stream)) {}
18 css_writer(xtd::io::text_writer& text_writer) : text_writer_(&text_writer), delete_when_destroy_(false) {}
19 css_writer(const xtd::ustring& path) : text_writer_(new xtd::io::stream_writer(path)) {}
20 ~css_writer() {
21 if (delete_when_destroy_ && text_writer_) delete text_writer_;
22 }
23
24 const xtd::web::css::selector_map& selectors() const {return selectors_;}
25 xtd::web::css::selector_map& selectors() {return selectors_;}
26 void selectors(const xtd::web::css::selector_map& selector) {selectors_ = selector;}
27
28 void write() {
29 if (!text_writer_) return;
30 for (auto selector : selectors_) {
31 text_writer_->write_line("{} {{", selector.first);
32 for (auto property : selector.second.properties())
33 text_writer_->write_line(" {}: {};", property.first, property.second);
34 text_writer_->write_line("}");
35 }
36 }
37
38 private:
39 xtd::web::css::selector_map selectors_;
40 xtd::io::text_writer* text_writer_ = nullptr;
41 bool delete_when_destroy_ = true;
42 };
43 }
44 }
45}
Implements a xtd::io::text_writer for writing characters to a stream.
Definition stream_writer.h:20
Represents a writer that can write a sequential series of characters.
Definition text_writer.h:29
void write_line()
Writes new line to the text stream.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:26
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:48
Definition css_writer.h:15
Definition property.h:13
Definition selector.h:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition system_report.h:17
Contains xtd::web::css::selector_map typedef.