aboutsummaryrefslogtreecommitdiff
path: root/src/client/mesh.cpp
diff options
context:
space:
mode:
authorMaksim <MoNTE48@mail.ua>2020-09-26 18:42:22 +0200
committerGitHub <noreply@github.com>2020-09-26 18:42:22 +0200
commit4298d95b16ab9a795b912f3d911c7b9ad2e3b03d (patch)
treeadca656c8c4afb5e7e71ff2d1ed50dff8259f1f7 /src/client/mesh.cpp
parent65c15e137fe584edb38edea21c49873be00d554c (diff)
downloadminetest-4298d95b16ab9a795b912f3d911c7b9ad2e3b03d.tar.gz
minetest-4298d95b16ab9a795b912f3d911c7b9ad2e3b03d.tar.bz2
minetest-4298d95b16ab9a795b912f3d911c7b9ad2e3b03d.zip
Android: replace InputDialogActivity on simple dialog window (#10034)
Diffstat (limited to 'src/client/mesh.cpp')
0 files changed, 0 insertions, 0 deletions
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
/*
Minetest
Copyright (C) 2018 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once
#include <type_traits>
#include "irrlichttypes.h"
#include "IReferenceCounted.h"

/** Shared pointer for IrrLicht objects.
 *
 * It should only be used for user-managed objects, i.e. those created with
 * the @c new operator or @c create* functions, like:
 * `irr_ptr<scene::IMeshBuffer> buf{new scene::SMeshBuffer()};`
 * The reference counting is *not* balanced as new objects have reference
 * count set to one, and the @c irr_ptr constructor (and @c reset) assumes
 * ownership of that reference.
 *
 * It shouldn’t be used for engine-managed objects, including those created
 * with @c addTexture and similar methods. Constructing @c irr_ptr directly
 * from such object is a bug and may lead to a crash. Indirect construction
 * is possible though; see the @c grab free function for details and use cases.
 */
template <class ReferenceCounted,
		class = typename std::enable_if<std::is_base_of<IReferenceCounted,
				ReferenceCounted>::value>::type>
class irr_ptr
{
	ReferenceCounted *value = nullptr;

public:
	irr_ptr() {}

	irr_ptr(std::nullptr_t) noexcept {}

	irr_ptr(const irr_ptr &b) noexcept { grab(b.get()); }

	irr_ptr(irr_ptr &&b) noexcept { reset(b.release()); }

	template <typename B, class = typename std::enable_if<std::is_convertible<B *,
					      ReferenceCounted *>::value>::type>
	irr_ptr(const irr_ptr<B> &b) noexcept
	{
		grab(b.get());
	}

	template <typename B, class = typename std::enable_if<std::is_convertible<B *,
					      ReferenceCounted *>::value>::type>
	irr_ptr(irr_ptr<B> &&b) noexcept
	{
		reset(b.release());
	}

	/** Constructs a shared pointer out of a plain one to control object lifetime.
	 * @param object The object, usually returned by some @c create* function.
	 * @note Move semantics: reference counter is *not* increased.
	 * @warning Never wrap any @c add* function with this!
	 */
	explicit irr_ptr(ReferenceCounted *object) noexcept { reset(object); }

	~irr_ptr() { reset(); }

	irr_ptr &operator=(const irr_ptr &b) noexcept
	{
		grab(b.get());
		return *this;
	}

	irr_ptr &operator=(irr_ptr &&b) noexcept
	{
		reset(b.release());
		return *this;
	}

	template <typename B, class = typename std::enable_if<std::is_convertible<B *,
					      ReferenceCounted *>::value>::type>
	irr_ptr &operator=(const irr_ptr<B> &b) noexcept
	{
		grab(b.get());
		return *this;
	}

	template <typename B, class = typename std::enable_if<std::is_convertible<B *,
					      ReferenceCounted *>::value>::type>