xtd 0.2.0
css_writer.h
Go to the documentation of this file.
1 #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 
12 namespace 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::ustring& 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:
51  xtd::web::css::selector_map selectors_;
52  xtd::io::text_writer* text_writer_ = nullptr;
53  bool delete_when_destroy_ = true;
54  };
55  }
56  }
57 }
Definition: css_writer.h:15
Definition: property.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
Represents a writer that can write a sequential series of characters.
Definition: text_writer.h:34
Implements a xtd::io::text_writer for writing characters to a stream.
Definition: stream_writer.h:26
The xtd::uri::local_path data.
Contains xtd::web::css::selector_map alias.
std::map< xtd::ustring, xtd::web::css::selector > selector_map
Represents the map of a selector name - selector pair.
Definition: selector_map.h:13
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
void write_line()
Writes new line to the text stream.
Definition: selector.h:12