Horizon Official Technical Documentation
GridReference.hpp
Go to the documentation of this file.
1/***************************************************
2 * _ _ _ *
3 * | | | | (_) *
4 * | |_| | ___ _ __ _ _______ _ __ *
5 * | _ |/ _ \| '__| |_ / _ \| '_ \ *
6 * | | | | (_) | | | |/ / (_) | | | | *
7 * \_| |_/\___/|_| |_/___\___/|_| |_| *
8 ***************************************************
9 * This file is part of Horizon (c).
10 *
11 * Copyright (c) 2019 Sagun K. (sagunxp@gmail.com).
12 * Copyright (c) 2019 Horizon Dev Team.
13 *
14 * Base Author - Sagun K. (sagunxp@gmail.com)
15 *
16 * This library is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 **************************************************/
29
30#ifndef HORIZON_ZONE_GAME_GRIDREFERENCE_HPP
31#define HORIZON_ZONE_GAME_GRIDREFERENCE_HPP
32
34
36template <class OBJECT>
37class GridRefManager;
38
41template <class OBJECT>
42class GridReference : public Horizon::Structures::LinkedList::Reference<GridRefManager<OBJECT>, OBJECT>
43{
44public:
45 GridReference() : Horizon::Structures::LinkedList::Reference<GridRefManager<OBJECT>, OBJECT>()
46 {
47 //
48 }
49
50 ~GridReference() override { this->remove(); }
51
53 {
55 }
56
57protected:
59 {
60 // called from link()
61 this->target()->push_front(this);
62 this->target()->inc_size();
63 }
64
66 {
67 // called from erase()
68 if (this->is_valid())
69 this->target()->dec_size();
70 }
71
73 {
74 // called from invalidate()
75 this->target()->dec_size();
76 }
77};
78
79#endif /* HORIZON_ZONE_GAME_GRIDREFERENCE_HPP */
Forward declaration of GridRefManager, the class that manages GridReference.
Definition: GridRefManager.hpp:41
GridReference is a reference to an object in GridRefManager. It is used to link objects.
Definition: GridReference.hpp:43
void source_object_destroy_link() override
Definition: GridReference.hpp:72
void target_object_build_link() override
Definition: GridReference.hpp:58
void target_object_destroy_link() override
Definition: GridReference.hpp:65
GridReference * next()
Definition: GridReference.hpp:52
GridReference()
Definition: GridReference.hpp:45
~GridReference() override
Definition: GridReference.hpp:50
Definition: Reference.hpp:28
GridRefManager< OBJECT > * target() const
Definition: Reference.hpp:100
Definition: Element.hpp:7