My code on virual inheritance

I am new to virtual inheritance and I beware of doing something wrong

There are 3 important classes:
- Object<Division, Bracket>
- Bracket<Object>
- Division<Bracket>
I will talk about Object mostly, as I have this code done for now

Object is what you can put in a Bracket of some Division
Real objects are created upon Object template, like
class Truck :
virtual Object<Category, Machine>,
virtual Object<Process, Render>,
virtual Object<Process, Update>,
virtual Object<RTS, RTS::SelectedUnits>,
virtual Object<AI, AI::UnitsInDanger>,
etc,
so they can be put in or removed from mentioned Brackets with some methods.

Here is my Object code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef OBJECT_HPP_INCLUDED
#define OBJECT_HPP_INCLUDED

namespace Construct_Object {
template<class Division>
class Block_Division {
public:
    inline Division& __division() {
        return *__var_division;
    }
private:
    Division* __var_division;
    friend class Interface;
};
template<class Division, class Bracket>
class Block_Bracket : public virtual Block_Division<Division> {
public:
    Block_Bracket() :
        __var_position(Block_Division<Division>::__division().template get<Bracket>().end())
    {}
    inline typename Bracket::Position __position() {
        return __var_position;
    }
private:
    typename Bracket::Position __var_position;
    friend class Interface;
};
class Interface {
public:
    template<class Division>
    inline void set(Division& division) {
        reinterpret_cast<Block_Division<Division>*>(this)
        ->__var_division = &division;
    }
    template<class Division>
    inline Division& get() {
        return reinterpret_cast<Block_Division<Division>*>(this)
        ->__division();
    }
    template<class Division, class Bracket>
    inline Bracket& get() {
        return get<Division>().template get<Bracket>();
    }
    template<class Division, class Bracket>
    inline typename Bracket::Position begin() {
        return get<Division, Bracket>().begin();
    }
    template<class Division, class Bracket>
    inline typename Bracket::Position end() {
        return get<Division, Bracket>().end();
    }
    template<class Division, class Bracket>
    inline typename Bracket::Position position() {
        return reinterpret_cast<Block_Bracket<Division, Bracket>*>(this)
        ->__position();
    }
    template<class Division, class Bracket>
    inline typename Bracket::Position belong() {
        return position<Division, Bracket>() != end<Division, Bracket>();
    }
    template<class Division, class Bracket>
    inline void add(typename Bracket::Position position) {
        reinterpret_cast<Block_Bracket<Division, Bracket>*>(this)
        ->__var_position = get<Division, Bracket>().add(this, position);
    }
    template<class Division, class Bracket>
    inline void remove() {
        get<Division, Bracket>().remove(position<Division, Bracket>());
        reinterpret_cast<Block_Bracket<Division, Bracket>*>(this)
        ->__var_position = end<Division, Bracket>();
    }
};
template<class Division, class Bracket>
class Final :
    public virtual Block_Bracket<Division, Bracket>,
    public virtual Interface
{};
} // namespace Construct_Object

// Default definition, open up for specialization
template<class Division, class Bracket>
class Object : public virtual Construct_Object::Final<Division, Bracket> {
public:
private:
    friend Construct_Object::Interface;
};

#endif // OBJECT_HPP_INCLUDED 


I separate my class on virtual blocks to make some parts multiple and some not (those parts of different template parameters are multiple).
Take a look at how I get the final class.
Is it legit?

Thank you beforehand
Last edited on
Topic archived. No new replies allowed.