neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_object.hpp
Go to the documentation of this file.
1// i_object.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2018, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <boost/algorithm/string/replace.hpp>
23#include <neolib/neolib.hpp>
27
28#define meta_object( ... ) \
29 typedef __VA_ARGS__ base_type; \
30 public: \
31 void class_name(neolib::i_string& aClassName) const override \
32 { \
33 auto temp = boost::typeindex::type_id<decltype(*this)>().pretty_name(); \
34 boost::replace_all(temp, "::", "--"); \
35 aClassName.append(temp); \
36 aClassName.append(":"sv); \
37 base_type::class_name(aClassName); \
38 }
39
40namespace neogfx
41{
43 {
44 public:
45 virtual ~i_object() = default;
46 public:
47 virtual i_object& as_object() = 0;
48 public:
49 virtual void class_name(neolib::i_string& aClassName) const = 0;
50 virtual neogfx::object_type object_type() const = 0;
51 };
52
53 inline std::string class_names(i_object const& aObject)
54 {
55 neolib::string temp;
56 aObject.class_name(temp);
57 auto result = temp.to_std_string();
58 boost::replace_all(result, "neogfx--", "");
59 boost::replace_all(result, "class ", "");
60 boost::replace_all(result, " ", "");
61 std::size_t templateCounter = 0;
62 for (auto i = result.begin(); i != result.end();)
63 {
64 if (*i == '<')
65 {
66 ++templateCounter;
67 i = result.erase(i);
68 }
69 else if (*i == '>')
70 {
71 --templateCounter;
72 i = result.erase(i);
73 }
74 else if (templateCounter != 0)
75 i = result.erase(i);
76 else
77 ++i;
78 }
79 return result;
80 }
81}
virtual void class_name(neolib::i_string &aClassName) const =0
virtual i_object & as_object()=0
virtual neogfx::object_type object_type() const =0
virtual ~i_object()=default
std::string to_std_string() const
Definition string.hpp:85
std::string class_names(i_object const &aObject)
Definition i_object.hpp:53