xtd 0.2.0
Loading...
Searching...
No Matches
css_writer.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "selector_map.hpp"
6#include "../../io/stream_writer.hpp"
7#include "../../argument_exception.hpp"
8#include "../../format_exception.hpp"
9#include "../../object.hpp"
10
12namespace xtd {
13 namespace web {
14 namespace css {
15 class css_writer : public object {
16 public:
18
20 css_writer(std::ostream& stream) : text_writer_(new xtd::io::stream_writer(stream)) {}
21 css_writer(xtd::io::text_writer& text_writer) : text_writer_(&text_writer), delete_when_destroy_(false) {}
22 css_writer(const xtd::string& path) : text_writer_(new xtd::io::stream_writer(path)) {}
25 ~css_writer() {if (delete_when_destroy_) delete text_writer_;}
27
29
31 const xtd::web::css::selector_map& selectors() const noexcept {return selectors_;}
32 xtd::web::css::selector_map& selectors() noexcept {return selectors_;}
33 void selectors(const xtd::web::css::selector_map& selector) {selectors_ = selector;}
35
37
39 void write() {
40 if (!text_writer_) return;
41 for (auto selector : selectors_) {
42 text_writer_->write_line("{} {{", selector.first);
43 for (auto property : selector.second.properties())
44 text_writer_->write_line(" {}: {};", property.first, property.second);
45 text_writer_->write_line("}");
46 }
47 }
49
50 private:
52 xtd::io::text_writer* text_writer_ = nullptr;
53 bool delete_when_destroy_ = true;
54 };
55 }
56 }
57}
Represents text as a sequence of character units.
Definition basic_string.hpp:79
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
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.hpp:42
Definition css_writer.hpp:15
Definition property.hpp:13
Definition selector.hpp:12
@ path
The xtd::uri::local_path data.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::web::css::selector_map alias.
std::map< xtd::string, xtd::web::css::selector > selector_map
Represents the map of a selector name - selector pair.
Definition selector_map.hpp:13