Webdar 1.0.0
Web user interface to libdar
html_aiguille.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// webdar - a web server and interface program to libdar
3// Copyright (C) 2013-2025 Denis Corbin
4//
5// This file is part of Webdar
6//
7// Webdar is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Webdar is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Webdar. If not, see <http://www.gnu.org/licenses/>
19//
20//----
21// to contact the author: dar.linux@free.fr
22/*********************************************************************/
23
24#ifndef HTML_AIGUILLE_HPP
25#define HTML_AIGUILLE_HPP
26
31
32 // C system header files
33#include "my_config.h"
34extern "C"
35{
36
37}
38
39 // C++ system header files
40#include <string>
41#include <list>
42#include <map>
43
44 // webdar headers
45#include "body_builder.hpp"
46#include "actor.hpp"
47#include "html_void.hpp"
48
50
58
61{
62public:
63 static constexpr const signed int noactive = -1;
64
65 html_aiguille() { clear(); };
66 html_aiguille(const html_aiguille & ref) = delete;
67 html_aiguille(html_aiguille && ref) noexcept = delete;
68 html_aiguille & operator = (const html_aiguille & ref) = delete;
69 html_aiguille & operator = (html_aiguille && ref) noexcept = delete;
70 ~html_aiguille() = default;
71
73 void clear();
74
76
84 void add_section(const std::string & name, const std::string & title);
85
87
90 void adopt_in_section(const std::string & section_name, body_builder* obj);
91
93 void adopt_in_section(signed int num, body_builder* obj);
94
96 void clear_section(const std::string & section_name);
97
99 void clear_section(signed int num);
100
102 void remove_section(const std::string & section_name);
103
105 void remove_section(signed int num);
106
108 void set_active_section(const std::string & name);
109
111 void set_active_section(signed int num);
112
114 signed int get_active_section() const { return active_section; };
115
117 unsigned int size() const { return order.size(); };
118
120 unsigned int section_name_to_num(const std::string & name) const;
121
123 std::string num_to_section_name(unsigned int num) const { return order[num]; };
124
126 virtual void void_child_will_foresake(body_builder* voidobj, body_builder* obj) override;
127
128protected:
129
130 // inherited from body_builder
131 virtual std::string inherited_get_body_part(const chemin & path,
132 const request & req) override;
133
134 // hiding adopt() as it is replaced by adopt_in_section()
136
137 // for inherited class to act upon new section addition
138 virtual void section_added(const std::string & name, const std::string & title) {};
139
140 // for inherited class to act upon section removal
141 virtual void section_removed(const std::string & name) {};
142
143
144private:
145
147 struct section
148 {
149 std::string title;
150 html_void global_visibility; // parent of all objects from the adopted list, and child of "this"
151 std::list<body_builder*> adopted;
152 };
153
154 std::deque<std::string> order;
155 std::map<std::string, section> sections;
156 std::map<body_builder*, std::string> obj_to_section;
157 signed int active_section;
158 bool selfcleaning;
159
160 void set_visibility(signed int section_num, bool visible);
161};
162
163#endif
class body_builder is the root class of object generating HTML body
Definition: body_builder.hpp:99
void adopt(body_builder *obj)
Definition: body_builder.cpp:117
class chemin definition
Definition: chemin.hpp:51
class html_aiguille is a pure virtual class
Definition: html_aiguille.hpp:61
virtual std::string inherited_get_body_part(const chemin &path, const request &req) override
implementation of get_body_part() method for inherited classes
Definition: html_aiguille.cpp:256
void clear()
clear all adopted data and remove all sections
Definition: html_aiguille.cpp:42
virtual void void_child_will_foresake(body_builder *voidobj, body_builder *obj) override
inherited from html_void_parent_notifier
Definition: html_aiguille.cpp:231
unsigned int size() const
return the total number of section
Definition: html_aiguille.hpp:117
void set_active_section(const std::string &name)
manually set the visible section, based on section name
Definition: html_aiguille.cpp:188
std::string num_to_section_name(unsigned int num) const
return the name of the section knowing its index
Definition: html_aiguille.hpp:123
void adopt_in_section(const std::string &section_name, body_builder *obj)
adopt another objet in the section which name is provided
Definition: html_aiguille.cpp:90
signed int get_active_section() const
get the current active section
Definition: html_aiguille.hpp:114
void add_section(const std::string &name, const std::string &title)
add a new sections
Definition: html_aiguille.cpp:51
unsigned int section_name_to_num(const std::string &name) const
return the index of the provided section name
Definition: html_aiguille.cpp:217
void remove_section(const std::string &section_name)
foresake objects and remove section of that name
Definition: html_aiguille.cpp:156
void clear_section(const std::string &section_name)
foresake all adopted objets in the given section
Definition: html_aiguille.cpp:113
to be used eventually by class of object adopting an html_void object
Definition: html_void.hpp:57
class html_void is only used to provide global visibility switch to all its adopted children
Definition: html_void.hpp:88
class holding fields of an HTTP request (method, URI, header, cookies, and so on)
Definition: request.hpp:45
defines two classes html_void and html_void_parent_notifier