xtd 0.2.0
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 "../../io/stream_writer.h"
7#include "../../argument_exception.h"
8#include "../../format_exception.h"
9#include "../../object.h"
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.h:79
Implements a xtd::io::text_writer for writing characters to a stream.
Definition stream_writer.h:28
Represents a writer that can write a sequential series of characters.
Definition text_writer.h: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.h:42
Definition css_writer.h:15
Definition property.h:13
Definition selector.h:12
@ path
The xtd::uri::local_path data.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h: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.h:13