Webdar 1.0.0
Web user interface to libdar
reference.hpp
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 REFERENCE_HPP
25#define REFERENCE_HPP
26
27 // C system header files
28#include "my_config.h"
29extern "C"
30{
31
32}
33
34 // C++ system header files
35#include <list>
36#include <set>
37
38 // webdar headers
39
41
47{
48public:
49
51 reference() { reset(); };
52
54
56 reference(const reference & ref) { reset(); };
57
59
62 reference(reference && ref) noexcept(false);
63
65
67 reference & operator = (const reference & ref);
68
70
72 reference & operator = (reference && ref) noexcept(false);
73
75 virtual ~reference() { shut_all_peerings(); };
76
78
85 void peer_with(reference *obj);
86
88 void break_peer_with(reference *obj);
89
91 bool is_peer(reference *obj) const { return peers.find(obj) != peers.end(); };
92
94 bool is_empty() const { return peers.empty(); };
95
97 unsigned int size() const { return peers.size(); };
98
99protected:
100
102 virtual void broken_peering_from(reference *obj) {};
103
104
106 void reset_read_peers() const { next_to_read = peers.begin(); };
107
113 bool read_next_peer(reference * & peer) const;
114
115private:
116 mutable std::set<reference *>::iterator next_to_read;
117 std::set<reference *> peers;
118
119 void reset();
120 void shut_all_peerings();
121 void erase_with_coherence(reference* ptr);
122};
123
124#endif
class reference gives a mean to link objects by a peering method
Definition: reference.hpp:47
virtual void broken_peering_from(reference *obj)
to be informed when a peer has broke the peering with me
Definition: reference.hpp:102
reference()
usual constructor
Definition: reference.hpp:51
reference & operator=(const reference &ref)
assignment operator (only operational for objects without peering)
Definition: reference.cpp:52
void reset_read_peers() const
reset the peers reading
Definition: reference.hpp:106
bool is_peer(reference *obj) const
whether a peering exists with that object
Definition: reference.hpp:91
bool is_empty() const
whether the current object has peering
Definition: reference.hpp:94
reference(const reference &ref)
copy constructor
Definition: reference.hpp:56
void break_peer_with(reference *obj)
break the peering with the object given as argument
Definition: reference.cpp:97
bool read_next_peer(reference *&peer) const
Definition: reference.cpp:121
virtual ~reference()
destructor
Definition: reference.hpp:75
unsigned int size() const
the number of peers
Definition: reference.hpp:97
void peer_with(reference *obj)
method used to create a relation between two objects
Definition: reference.cpp:72