Skip to content

Commit f4ad0b1

Browse files
committed
YT-CPPGL-48: Add final and virtual markers
- Added the `final` keyword to the following classes: - `{vertex/edge}_descriptor` - `adjacency_{list/matrix}` - `graph` - Marked the destructors of the property classes and the `iterator_range` class as `virtual` (if they are explicitly configured not to be final)
1 parent 59730c7 commit f4ad0b1

9 files changed

Lines changed: 74 additions & 10 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ else()
88
endif()
99

1010
project(cpp-gl
11-
VERSION 1.0.0
11+
VERSION 1.0.1
1212
DESCRIPTION "General purpose header-only template graph library for C++20"
1313
HOMEPAGE_URL "https://github.com/SpectraL519/cpp-gl"
1414
LANGUAGES CXX

docs/core_util_types.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ The table below contains the basic type aliases defined in the library.
196196
- Reads the weight property from an input stream.
197197
- *Constraints*: `weight_type` must be readable (`type_traits::c_readable<weight_type>`).
198198

199+
### Deriving from the property types
200+
201+
> [!IMPORTANT]
202+
> The `name_property`, `dynamic_properties` and `binary_color` classes are marked `final` by default. To be able to use them as base classes you have to add:
203+
>
204+
> ```cpp
205+
> #define GL_CONFIG_PROPERTY_TYPES_NOT_FINAL
206+
> ```
207+
>
208+
> in your program or add a `-DGL_CONFIG_PROPERTY_TYPES_NOT_FINAL` flag when compiling.
209+
199210
### Associated type traits
200211
201212
This section describes the type traits that are associated with the property types defined in the library. These traits help ensure that properties meet specific requirements and can be used correctly within the library.
@@ -291,6 +302,15 @@ This section provides the description of types used to manage range/collection i
291302
- `operator[](types::size_type position) -> value_type&` - Provides access to the element at the specified position (equivalent to `element_at`).
292303
- `operator[](types::size_type position) const -> const value_type&` - Provides access to the element at the specified position (equivalent to `element_at`).
293304
305+
> [!IMPORTANT]
306+
> The `iterator_range` class is marked `final` by default. To use this class as a base class you have to add:
307+
>
308+
> ```cpp
309+
> #define GL_CONFIG_IT_RANGE_NOT_FINAL
310+
> ```
311+
>
312+
> in your program or add a `-DGL_CONFIG_IT_RANGE_NOT_FINAL` flag when compiling.
313+
294314
#### Associated functions
295315
296316
- `gl::make_iterator_range(begin, end)`

include/gl/edge_descriptor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ template <
1414
type_traits::c_instantiation_of<vertex_descriptor> VertexType,
1515
type_traits::c_edge_directional_tag DirectionalTag = directed_t,
1616
type_traits::c_properties Properties = types::empty_properties>
17-
class edge_descriptor {
17+
class edge_descriptor final {
1818
public:
1919
using type = edge_descriptor<VertexType, DirectionalTag, Properties>;
2020
using vertex_type = VertexType;

include/gl/graph.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace gl {
1616

1717
template <type_traits::c_instantiation_of<graph_traits> GraphTraits = graph_traits<>>
18-
class graph {
18+
class graph final {
1919
public:
2020
using traits_type = GraphTraits;
2121

include/gl/impl/adjacency_list.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace gl::impl {
1414

1515
template <type_traits::c_list_graph_traits GraphTraits>
16-
class adjacency_list {
16+
class adjacency_list final {
1717
public:
1818
using vertex_type = typename GraphTraits::vertex_type;
1919

include/gl/impl/adjacency_matrix.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace gl::impl {
1515

1616
template <type_traits::c_matrix_graph_traits GraphTraits>
17-
class adjacency_matrix {
17+
class adjacency_matrix final {
1818
public:
1919
using vertex_type = typename GraphTraits::vertex_type;
2020

include/gl/types/iterator_range.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
#define _GL_IT_RANGE_DEFAULT_CACHE_MODE gl::type_traits::lazy_cache
2222
#endif
2323

24+
#ifdef GL_CONFIG_IT_RANGE_NOT_FINAL
25+
#define _GL_IT_RANGE_NOT_FINAL
26+
#else
27+
#undef _GL_IT_RANGE_NOT_FINAL
28+
#endif
29+
2430
namespace gl {
2531

2632
namespace types {
@@ -33,7 +39,11 @@ Designed to be compatible with the range-based loops and std algorithms.
3339
template <
3440
std::forward_iterator Iterator,
3541
type_traits::c_cache_mode CacheMode = _GL_IT_RANGE_DEFAULT_CACHE_MODE>
36-
class iterator_range {
42+
class iterator_range
43+
#ifndef _GL_IT_RANGE_NOT_FINAL
44+
final
45+
#endif
46+
{
3747
public:
3848
using iterator = Iterator;
3949
#if __cplusplus >= 202302L
@@ -72,7 +82,11 @@ class iterator_range {
7282
iterator_range& operator=(const iterator_range&) = default;
7383
iterator_range& operator=(iterator_range&&) = default;
7484

85+
#ifndef _GL_IT_RANGE_NOT_FINAL
7586
~iterator_range() = default;
87+
#else
88+
virtual ~iterator_range() = default;
89+
#endif
7690

7791
bool operator==(const iterator_range&) const = default;
7892

include/gl/types/properties.hpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
#include <unordered_map>
1414
#include <variant>
1515

16+
#ifdef GL_CONFIG_PROPERTY_TYPES_NOT_FINAL
17+
#define _GL_PROPERTY_TYPES_NOT_FINAL
18+
#else
19+
#undef _GL_PROPERTY_TYPES_NOT_FINAL
20+
#endif
21+
1622
namespace gl {
1723

1824
namespace types {
@@ -21,7 +27,11 @@ namespace types {
2127

2228
using empty_properties = std::monostate;
2329

24-
class name_property {
30+
class name_property
31+
#ifndef _GL_PROPERTY_TYPES_NOT_FINAL
32+
final
33+
#endif
34+
{
2535
public:
2636
using value_type = std::string;
2737

@@ -35,7 +45,11 @@ class name_property {
3545
name_property& operator=(const name_property&) = default;
3646
name_property& operator=(name_property&&) = default;
3747

48+
#ifndef _GL_PROPERTY_TYPES_NOT_FINAL
3849
~name_property() = default;
50+
#else
51+
virtual ~name_property() = default;
52+
#endif
3953

4054
// clang-format off
4155
// gl_attr_force_inline misplacement
@@ -63,7 +77,11 @@ class name_property {
6377
std::string _name;
6478
};
6579

66-
class dynamic_properties {
80+
class dynamic_properties
81+
#ifndef _GL_PROPERTY_TYPES_NOT_FINAL
82+
final
83+
#endif
84+
{
6785
public:
6886
using key_type = std::string;
6987
using value_type = std::any;
@@ -77,7 +95,11 @@ class dynamic_properties {
7795
dynamic_properties& operator=(const dynamic_properties&) = default;
7896
dynamic_properties& operator=(dynamic_properties&&) = default;
7997

98+
#ifndef _GL_PROPERTY_TYPES_NOT_FINAL
8099
~dynamic_properties() = default;
100+
#else
101+
virtual ~dynamic_properties() = default;
102+
#endif
81103

82104
[[nodiscard]] gl_attr_force_inline bool is_present(const key_type& key) const {
83105
return this->_property_map.contains(key);
@@ -119,7 +141,11 @@ class dynamic_properties {
119141

120142
// --- vertex properties ---
121143

122-
class binary_color {
144+
class binary_color
145+
#ifndef _GL_PROPERTY_TYPES_NOT_FINAL
146+
final
147+
#endif
148+
{
123149
public:
124150
enum class value : std::uint16_t {
125151
black = static_cast<std::uint16_t>(0),
@@ -137,7 +163,11 @@ class binary_color {
137163
binary_color& operator=(const binary_color&) = default;
138164
binary_color& operator=(binary_color&&) = default;
139165

166+
#ifndef _GL_PROPERTY_TYPES_NOT_FINAL
140167
~binary_color() = default;
168+
#else
169+
virtual ~binary_color() = default;
170+
#endif
141171

142172
binary_color& operator=(value value) {
143173
this->_value = this->_restrict(value);

include/gl/vertex_descriptor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace gl {
1717

1818
template <type_traits::c_properties Properties = types::empty_properties>
19-
class vertex_descriptor {
19+
class vertex_descriptor final {
2020
public:
2121
using type = std::type_identity_t<vertex_descriptor<Properties>>;
2222
using properties_type = Properties;

0 commit comments

Comments
 (0)