nginxconfig
C++libraryforparsingandprintingnginx.conf
nginxconfig/encode.hpp
Go to the documentation of this file.
00001 
00012 #ifndef __NGINXCONFIG_ENCODE_HPP_INCLUDED__
00013 #define __NGINXCONFIG_ENCODE_HPP_INCLUDED__
00014 
00015 #include <nginxconfig/config.hpp>
00016 
00017 #include <deque>
00018 #include <iosfwd>
00019 #include <string>
00020 
00021 namespace nginxconfig
00022 {
00023 
00024 class ast_entry;
00025 
00029 NGINXCONFIG_PUBLIC void encode(const ast_entry& ast, std::ostream& output, std::string indent);
00030 NGINXCONFIG_PUBLIC void encode(const ast_entry& ast, std::ostream& output);
00031 
00033 class NGINXCONFIG_PUBLIC encoder
00034 {
00035 public:
00036     virtual ~encoder() noexcept;
00037     
00038     void encode(const ast_entry& ast);
00039     
00040 protected:
00041     class context
00042     {
00043     public:
00044         using path_type = std::deque<const ast_entry*>;
00045         using size_type = path_type::size_type;
00046         
00047     public:
00048         const path_type& path() const;
00049         
00050         size_type indent_level() const;
00051         
00052     private:
00053         friend class encoder;
00054         
00055         path_type _path;
00056     };
00057     
00058     virtual void write_simple(const context& cxt, const ast_entry& ast) = 0;
00059     
00060     virtual void write_complex_begin(const context& cxt, const ast_entry& ast) = 0;
00061     
00062     virtual void write_complex_end(const context& cxt, const ast_entry& ast) = 0;
00063     
00064     virtual void write_document_begin(const context& cxt, const ast_entry& ast);
00065     
00066     virtual void write_document_end(const context& cxt, const ast_entry& ast);
00067     
00068     virtual void write_comment(const context& cxt, const ast_entry& ast) = 0;
00069     
00070 private:
00071     void encode_impl(context& cxt, const ast_entry& ast);
00072 };
00073 
00074 class NGINXCONFIG_PUBLIC ostream_encoder :
00075         public encoder
00076 {
00077 public:
00078     explicit ostream_encoder(std::ostream& output);
00079     explicit ostream_encoder(std::ostream& output, std::string indent);
00080     
00081     virtual ~ostream_encoder() noexcept;
00082     
00083 protected:
00084     virtual void write_simple(const context& cxt, const ast_entry& ast) override;
00085     
00086     virtual void write_complex_begin(const context& cxt, const ast_entry& ast) override;
00087     
00088     virtual void write_complex_end(const context& cxt, const ast_entry& ast) override;
00089     
00090     virtual void write_comment(const context& cxt, const ast_entry& ast) override;
00091     
00092 private:
00093     void write_indent(const context& cxt);
00094     
00095     void write_attributes(const ast_entry& ast);
00096     
00097 private:
00098     std::ostream& _output;
00099     std::string   _indent;
00100 };
00101 
00102 }
00103 
00104 #endif/*__NGINXCONFIG_ENCODE_HPP_INCLUDED__*/
 All Classes Files Functions Variables Friends Defines