Drawable Renderer (#1570), [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
committed by
Bart Louwers
parent
b2a3e518c7
commit
caee9cc12f
@@ -35,7 +35,7 @@ public:
|
||||
const util::SimpleIdentity& getId() const { return uniqueID; }
|
||||
|
||||
/// Draw the drawable
|
||||
virtual void draw(const PaintParameters &) const = 0;
|
||||
virtual void draw(const PaintParameters&) const = 0;
|
||||
|
||||
/// Drawable name is used for debugging and troubleshooting
|
||||
const std::string& getName() const { return name; }
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
|
||||
DepthMaskType getDepthType() const { return depthType; }
|
||||
void setDepthType(DepthMaskType value) { depthType = value; }
|
||||
|
||||
|
||||
/// Get the number of vertexes
|
||||
std::size_t getVertexCount() const { return getVertexAttributes().getMaxCount(); }
|
||||
|
||||
@@ -71,7 +71,9 @@ public:
|
||||
/// Attach a tweaker to be run on this drawable for each frame
|
||||
void addTweaker(DrawableTweakerPtr tweaker) { tweakers.emplace_back(std::move(tweaker)); }
|
||||
template <typename TIter>
|
||||
void addTweakers(TIter beg, TIter end) { tweakers.insert(tweakers.end(), beg, end); }
|
||||
void addTweakers(TIter beg, TIter end) {
|
||||
tweakers.insert(tweakers.end(), beg, end);
|
||||
}
|
||||
|
||||
/// Get the tweakers attached to this drawable
|
||||
const std::vector<DrawableTweakerPtr>& getTweakers() const { return tweakers; }
|
||||
@@ -86,7 +88,7 @@ protected:
|
||||
mat4 matrix; //= matrix::identity4();
|
||||
std::optional<OverscaledTileID> tileID;
|
||||
DrawPriority drawPriority = 0;
|
||||
DepthMaskType depthType;// = DepthMaskType::ReadOnly;
|
||||
DepthMaskType depthType; // = DepthMaskType::ReadOnly;
|
||||
|
||||
std::vector<DrawableTweakerPtr> tweakers;
|
||||
};
|
||||
|
||||
@@ -60,7 +60,10 @@ public:
|
||||
const Color& getColor() const;
|
||||
void setColor(const Color& value);
|
||||
|
||||
enum class ColorMode { PerDrawable, PerVertex };
|
||||
enum class ColorMode {
|
||||
PerDrawable,
|
||||
PerVertex
|
||||
};
|
||||
/// Set how the color value is used
|
||||
/// This should not be changed while a build is in progress
|
||||
void setColorMode(ColorMode mode) { colorMode = mode; }
|
||||
|
||||
@@ -62,4 +62,3 @@ enum class AttributeDataType : uint8_t {
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mbgl
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ inline constexpr bool is_shader_v = std::is_base_of_v<gfx::Shader, T> &&
|
||||
/// @brief A shader is used as the base class for all programs across any supported
|
||||
/// backend API. Shaders are registered with a `gfx::ShaderRegistry` instance.
|
||||
class Shader {
|
||||
public:
|
||||
virtual ~Shader() noexcept = default;
|
||||
public:
|
||||
virtual ~Shader() noexcept = default;
|
||||
|
||||
/// @brief Get the type name of this shader
|
||||
/// @return Shader type name
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
using mat2 = std::array<double, 2*2>;
|
||||
using mat3 = std::array<double, 3*3>;
|
||||
using mat4 = std::array<double, 4*4>;
|
||||
using mat2 = std::array<double, 2 * 2>;
|
||||
using mat3 = std::array<double, 3 * 3>;
|
||||
using mat4 = std::array<double, 4 * 4>;
|
||||
|
||||
namespace gfx {
|
||||
|
||||
@@ -27,34 +27,29 @@ public:
|
||||
using float2 = std::array<float, 2>;
|
||||
using float3 = std::array<float, 3>;
|
||||
using float4 = std::array<float, 4>;
|
||||
using matf2 = std::array<float, 2*2>;
|
||||
using matf3 = std::array<float, 3*3>;
|
||||
using matf4 = std::array<float, 4*4>;
|
||||
using matf2 = std::array<float, 2 * 2>;
|
||||
using matf3 = std::array<float, 3 * 3>;
|
||||
using matf4 = std::array<float, 4 * 4>;
|
||||
using int2 = std::array<std::int32_t, 2>;
|
||||
using int3 = std::array<std::int32_t, 3>;
|
||||
using int4 = std::array<std::int32_t, 4>;
|
||||
|
||||
using ElementType = std::variant<std::int32_t, int2, int3, int4,
|
||||
float, float2, float3, float4,
|
||||
matf3, matf4>;
|
||||
using ElementType = std::variant<std::int32_t, int2, int3, int4, float, float2, float3, float4, matf3, matf4>;
|
||||
|
||||
// Can only be created by VertexAttributeArray implementations
|
||||
protected:
|
||||
VertexAttribute(int index_, AttributeDataType dataType_,
|
||||
int size_, std::size_t count_, std::size_t stride_)
|
||||
VertexAttribute(int index_, AttributeDataType dataType_, int size_, std::size_t count_, std::size_t stride_)
|
||||
: index(index_),
|
||||
size(size_),
|
||||
stride((int)stride_),
|
||||
dataType(dataType_),
|
||||
items(count_) {
|
||||
}
|
||||
VertexAttribute(const VertexAttribute &) = default;
|
||||
items(count_) {}
|
||||
VertexAttribute(const VertexAttribute&) = default;
|
||||
VertexAttribute(VertexAttribute&& other)
|
||||
: index(other.index),
|
||||
size(other.size),
|
||||
dataType(other.dataType),
|
||||
items(std::move(other.items)) {
|
||||
}
|
||||
items(std::move(other.items)) {}
|
||||
|
||||
public:
|
||||
~VertexAttribute() = default;
|
||||
@@ -77,7 +72,7 @@ public:
|
||||
const ElementType& set(std::size_t i, T value) {
|
||||
if (items.size() < i + 1) {
|
||||
items.resize(std::max(items.size(), i + 1));
|
||||
setDirty(); // need to rebuild the raw data next time
|
||||
setDirty(); // need to rebuild the raw data next time
|
||||
}
|
||||
if (!isDirty()) {
|
||||
if (std::holds_alternative<T>(items[i])) {
|
||||
@@ -135,7 +130,7 @@ public:
|
||||
using AttributeMap = std::unordered_map<std::string, std::unique_ptr<VertexAttribute>>;
|
||||
|
||||
VertexAttributeArray(int initCapacity = 10);
|
||||
VertexAttributeArray(VertexAttributeArray &&);
|
||||
VertexAttributeArray(VertexAttributeArray&&);
|
||||
// Would need to use the virtual assignment operator
|
||||
VertexAttributeArray(const VertexAttributeArray&) = delete;
|
||||
virtual ~VertexAttributeArray() = default;
|
||||
@@ -175,7 +170,7 @@ public:
|
||||
// Set a value if the element is present
|
||||
template <typename T>
|
||||
bool set(const std::string& name, std::size_t i, T value) {
|
||||
if (auto *item = get(name)) {
|
||||
if (auto* item = get(name)) {
|
||||
return item->set(i, value);
|
||||
}
|
||||
return false;
|
||||
@@ -183,8 +178,8 @@ public:
|
||||
|
||||
/// Indicates whether any values have changed
|
||||
bool isDirty() const {
|
||||
return std::any_of(attrs.begin(), attrs.end(),
|
||||
[](const auto& kv){ return kv.second && kv.second->isDirty(); });
|
||||
return std::any_of(
|
||||
attrs.begin(), attrs.end(), [](const auto& kv) { return kv.second && kv.second->isDirty(); });
|
||||
}
|
||||
|
||||
using ResolveDelegate = std::function<void(const std::string&, const VertexAttribute&, const VertexAttribute*)>;
|
||||
@@ -193,8 +188,8 @@ public:
|
||||
|
||||
/// Apply to the active program
|
||||
virtual void applyUniforms(const ShaderProgramBase&) = 0;
|
||||
|
||||
VertexAttributeArray& operator=(VertexAttributeArray &&);
|
||||
|
||||
VertexAttributeArray& operator=(VertexAttributeArray&&);
|
||||
VertexAttributeArray& operator=(const VertexAttributeArray&);
|
||||
|
||||
protected:
|
||||
@@ -208,8 +203,10 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<VertexAttribute> create(int index, AttributeDataType dataType,
|
||||
int size, std::size_t count) = 0;
|
||||
virtual std::unique_ptr<VertexAttribute> create(int index,
|
||||
AttributeDataType dataType,
|
||||
int size,
|
||||
std::size_t count) = 0;
|
||||
virtual std::unique_ptr<VertexAttribute> copy(const VertexAttribute& attr) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -25,11 +25,9 @@ public:
|
||||
DrawableGL(std::string name);
|
||||
~DrawableGL() override;
|
||||
|
||||
void draw(const PaintParameters &) const override;
|
||||
void draw(const PaintParameters&) const override;
|
||||
|
||||
void setIndexData(std::vector<uint16_t> indexes,
|
||||
std::size_t indexOffset = 0,
|
||||
std::size_t indexLength = 0);
|
||||
void setIndexData(std::vector<uint16_t> indexes, std::size_t indexOffset = 0, std::size_t indexLength = 0);
|
||||
std::vector<std::uint16_t>& getIndexData() const override;
|
||||
|
||||
const gfx::VertexAttributeArray& getVertexAttributes() const override;
|
||||
@@ -49,18 +47,19 @@ public:
|
||||
|
||||
static gfx::VertexAttribute::float4 colorAttrValue(const Color& color) {
|
||||
const auto components = color.toArray();
|
||||
return { static_cast<float>(components[0]/255.0),
|
||||
static_cast<float>(components[1]/255.0),
|
||||
static_cast<float>(components[2]/255.0),
|
||||
static_cast<float>(components[3]) };
|
||||
return {static_cast<float>(components[0] / 255.0),
|
||||
static_cast<float>(components[1] / 255.0),
|
||||
static_cast<float>(components[2] / 255.0),
|
||||
static_cast<float>(components[3])};
|
||||
}
|
||||
|
||||
protected:
|
||||
class Impl;
|
||||
const std::unique_ptr<Impl> impl;
|
||||
|
||||
// For testing only.
|
||||
DrawableGL(std::unique_ptr<Impl>);
|
||||
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
@@ -11,20 +11,20 @@ namespace gl {
|
||||
*/
|
||||
class DrawableGLBuilder final : public gfx::DrawableBuilder {
|
||||
public:
|
||||
DrawableGLBuilder(std::string name_) : gfx::DrawableBuilder(std::move(name_)) {
|
||||
}
|
||||
DrawableGLBuilder(std::string name_)
|
||||
: gfx::DrawableBuilder(std::move(name_)) {}
|
||||
~DrawableGLBuilder() override = default;
|
||||
|
||||
const gfx::VertexAttributeArray& getVertexAttributes() const override { return vertexAttributes; }
|
||||
void setVertexAttributes(const VertexAttributeArrayGL& value) { vertexAttributes = value; }
|
||||
void setVertexAttributes(VertexAttributeArrayGL&& value) { vertexAttributes = std::move(value); }
|
||||
|
||||
|
||||
protected:
|
||||
gfx::DrawablePtr createDrawable() const override;
|
||||
|
||||
|
||||
/// Setup the SDK-specific aspects after all the values are present
|
||||
void init() override;
|
||||
|
||||
|
||||
private:
|
||||
VertexAttributeArrayGL vertexAttributes;
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace mbgl {
|
||||
|
||||
namespace gfx {
|
||||
class Drawable;
|
||||
class Drawable;
|
||||
}
|
||||
|
||||
namespace gl {
|
||||
|
||||
@@ -14,17 +14,14 @@ class VertexAttributeGL final : public gfx::VertexAttribute {
|
||||
private:
|
||||
friend VertexAttributeArrayGL;
|
||||
VertexAttributeGL(int index_, gfx::AttributeDataType dataType_, int size_, std::size_t count_)
|
||||
: VertexAttribute(index_, dataType_, size_, count_, /*stride_=*/0) {
|
||||
}
|
||||
: VertexAttribute(index_, dataType_, size_, count_, /*stride_=*/0) {}
|
||||
VertexAttributeGL(const VertexAttributeGL& other)
|
||||
: VertexAttribute(other),
|
||||
glType(other.glType) {
|
||||
}
|
||||
glType(other.glType) {}
|
||||
VertexAttributeGL(VertexAttributeGL&& other)
|
||||
: VertexAttribute(std::move(other)),
|
||||
glType(other.glType) {
|
||||
}
|
||||
|
||||
glType(other.glType) {}
|
||||
|
||||
public:
|
||||
platform::GLenum getGLType() const { return glType; }
|
||||
void setGLType(platform::GLenum value);
|
||||
@@ -50,11 +47,13 @@ private:
|
||||
/// Stores a collection of vertex attributes by name
|
||||
class VertexAttributeArrayGL final : public gfx::VertexAttributeArray {
|
||||
public:
|
||||
VertexAttributeArrayGL(int initCapacity = 10) : VertexAttributeArray(initCapacity) { }
|
||||
VertexAttributeArrayGL(VertexAttributeArrayGL &&other) : VertexAttributeArray(std::move(other)) { }
|
||||
VertexAttributeArrayGL(int initCapacity = 10)
|
||||
: VertexAttributeArray(initCapacity) {}
|
||||
VertexAttributeArrayGL(VertexAttributeArrayGL&& other)
|
||||
: VertexAttributeArray(std::move(other)) {}
|
||||
VertexAttributeArrayGL(const VertexAttributeArrayGL&) = delete;
|
||||
|
||||
VertexAttributeArrayGL& operator=(VertexAttributeArrayGL &&other) {
|
||||
|
||||
VertexAttributeArrayGL& operator=(VertexAttributeArrayGL&& other) {
|
||||
VertexAttributeArray::operator=(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
@@ -62,18 +61,21 @@ public:
|
||||
VertexAttributeArray::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void applyUniforms(const gfx::ShaderProgramBase&) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<gfx::VertexAttribute> create(int index, gfx::AttributeDataType dataType,
|
||||
int size, std::size_t count) override {
|
||||
std::unique_ptr<gfx::VertexAttribute> create(int index,
|
||||
gfx::AttributeDataType dataType,
|
||||
int size,
|
||||
std::size_t count) override {
|
||||
return std::unique_ptr<gfx::VertexAttribute>(new VertexAttributeGL(index, dataType, size, count));
|
||||
}
|
||||
std::unique_ptr<gfx::VertexAttribute> copy(const gfx::VertexAttribute& attr) override {
|
||||
return std::unique_ptr<gfx::VertexAttribute>(new VertexAttributeGL(static_cast<const VertexAttributeGL&>(attr)));
|
||||
return std::unique_ptr<gfx::VertexAttribute>(
|
||||
new VertexAttributeGL(static_cast<const VertexAttributeGL&>(attr)));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace gl
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -11,10 +11,9 @@ namespace mbgl {
|
||||
class RenderOrchestrator;
|
||||
|
||||
namespace gfx {
|
||||
class Drawable;
|
||||
using DrawablePtr = std::shared_ptr<Drawable>;
|
||||
} // namespace gfx
|
||||
|
||||
class Drawable;
|
||||
using DrawablePtr = std::shared_ptr<Drawable>;
|
||||
} // namespace gfx
|
||||
|
||||
/**
|
||||
Base class for changes to be made to the scene
|
||||
@@ -40,24 +39,22 @@ using UniqueChangeRequestVec = std::vector<UniqueChangeRequest>;
|
||||
*/
|
||||
class DrawableRefChangeRequest : public ChangeRequest {
|
||||
protected:
|
||||
DrawableRefChangeRequest(util::SimpleIdentity id) : drawableID(id) { }
|
||||
DrawableRefChangeRequest(const DrawableRefChangeRequest&) = default;
|
||||
DrawableRefChangeRequest(util::SimpleIdentity id)
|
||||
: drawableID(id) {}
|
||||
DrawableRefChangeRequest(const DrawableRefChangeRequest &) = default;
|
||||
|
||||
util::SimpleIdentity drawableID;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Add a new drawable to the scene
|
||||
*/
|
||||
class AddDrawableRequest : public ChangeRequest {
|
||||
public:
|
||||
AddDrawableRequest(gfx::DrawablePtr drawable_)
|
||||
: drawable(std::move(drawable_)) {
|
||||
}
|
||||
AddDrawableRequest(AddDrawableRequest&& other)
|
||||
: drawable(std::move(other.drawable)) {
|
||||
}
|
||||
: drawable(std::move(drawable_)) {}
|
||||
AddDrawableRequest(AddDrawableRequest &&other)
|
||||
: drawable(std::move(other.drawable)) {}
|
||||
|
||||
void execute(RenderOrchestrator &) override;
|
||||
|
||||
@@ -65,29 +62,27 @@ protected:
|
||||
gfx::DrawablePtr drawable;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Remove a drawable from the scene
|
||||
*/
|
||||
class RemoveDrawableRequest : public DrawableRefChangeRequest {
|
||||
public:
|
||||
RemoveDrawableRequest(util::SimpleIdentity id) : DrawableRefChangeRequest(id) { }
|
||||
RemoveDrawableRequest(const RemoveDrawableRequest&) = default;
|
||||
RemoveDrawableRequest(util::SimpleIdentity id)
|
||||
: DrawableRefChangeRequest(id) {}
|
||||
RemoveDrawableRequest(const RemoveDrawableRequest &) = default;
|
||||
|
||||
void execute(RenderOrchestrator &) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Change the color of all vertexes
|
||||
*/
|
||||
class ResetColorRequest : public DrawableRefChangeRequest {
|
||||
public:
|
||||
ResetColorRequest(util::SimpleIdentity id, Color color) :
|
||||
DrawableRefChangeRequest(id),
|
||||
newColor(color)
|
||||
{ }
|
||||
ResetColorRequest(const ResetColorRequest& other) = default;
|
||||
ResetColorRequest(util::SimpleIdentity id, Color color)
|
||||
: DrawableRefChangeRequest(id),
|
||||
newColor(color) {}
|
||||
ResetColorRequest(const ResetColorRequest &other) = default;
|
||||
|
||||
void execute(RenderOrchestrator &) override;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
|
||||
/// Coalescing updates is up to the implementer
|
||||
virtual void update(std::shared_ptr<UpdateParameters>) = 0;
|
||||
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
|
||||
@@ -10,20 +10,17 @@ namespace gl {
|
||||
class ShaderProgramGL final : public gfx::ShaderProgramBase {
|
||||
public:
|
||||
ShaderProgramGL(UniqueProgram&& glProgram_);
|
||||
ShaderProgramGL(UniqueProgram&&,
|
||||
VertexAttributeArrayGL&& uniforms,
|
||||
VertexAttributeArrayGL&& attributes);
|
||||
ShaderProgramGL(UniqueProgram&&, VertexAttributeArrayGL&& uniforms, VertexAttributeArrayGL&& attributes);
|
||||
ShaderProgramGL(ShaderProgramGL&& other);
|
||||
~ShaderProgramGL() noexcept override = default;
|
||||
|
||||
static constexpr std::string_view Name{"GenericGLShader"};
|
||||
const std::string_view typeName() const noexcept override { return Name; }
|
||||
|
||||
static std::shared_ptr<ShaderProgramGL> create(
|
||||
Context&,
|
||||
std::string_view name,
|
||||
std::string_view vertexSource,
|
||||
std::string_view fragmentSource) noexcept(false);
|
||||
static std::shared_ptr<ShaderProgramGL> create(Context&,
|
||||
std::string_view name,
|
||||
std::string_view vertexSource,
|
||||
std::string_view fragmentSource) noexcept(false);
|
||||
|
||||
const gfx::VertexAttributeArray& getUniforms() const override { return uniforms; }
|
||||
|
||||
|
||||
@@ -7,17 +7,18 @@ namespace mtl {
|
||||
|
||||
class ShaderProgramMTL : public gfx::ShaderProgramBase {
|
||||
public:
|
||||
ShaderProgramMTL() : ShaderProgramBase() { }
|
||||
ShaderProgramMTL()
|
||||
: ShaderProgramBase() {}
|
||||
~ShaderProgramMTL() noexcept override = default;
|
||||
|
||||
static constexpr std::string_view Name{"GenericMTLShader"};
|
||||
const std::string_view typeName() const noexcept override { return Name; }
|
||||
|
||||
//bool compile(std::string_view vert, std::string_view frag);
|
||||
// Load compiled Metal functions from the default library in a bundle
|
||||
//bool load(NSBundle*, std::string_view vertFuncName, std::string_view fragFuncName);
|
||||
// Load compiled Metal functions from a specific library
|
||||
//bool load(id<MTLLibrary>, std::string_view vertFuncName, std::string_view fragFuncName);
|
||||
// bool compile(std::string_view vert, std::string_view frag);
|
||||
// Load compiled Metal functions from the default library in a bundle
|
||||
// bool load(NSBundle*, std::string_view vertFuncName, std::string_view fragFuncName);
|
||||
// Load compiled Metal functions from a specific library
|
||||
// bool load(id<MTLLibrary>, std::string_view vertFuncName, std::string_view fragFuncName);
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
@@ -11,13 +11,13 @@ namespace gfx {
|
||||
|
||||
class ShaderProgramBase : public gfx::Shader {
|
||||
protected:
|
||||
ShaderProgramBase() { }
|
||||
ShaderProgramBase(ShaderProgramBase&&) { }
|
||||
ShaderProgramBase() {}
|
||||
ShaderProgramBase(ShaderProgramBase&&) {}
|
||||
~ShaderProgramBase() noexcept override = default;
|
||||
|
||||
template <typename T>
|
||||
bool set(gfx::VertexAttributeArray& attrs, const std::string& name, std::size_t i, T value) {
|
||||
auto *item = attrs.get(name);
|
||||
auto* item = attrs.get(name);
|
||||
if (item && i < item->getCount()) {
|
||||
item->set(i, value);
|
||||
return true;
|
||||
|
||||
@@ -12,7 +12,9 @@ namespace util {
|
||||
*/
|
||||
class SimpleIdentity final {
|
||||
private:
|
||||
constexpr SimpleIdentity(std::int64_t id) : uniqueID(id) { }
|
||||
constexpr SimpleIdentity(std::int64_t id)
|
||||
: uniqueID(id) {}
|
||||
|
||||
public:
|
||||
SimpleIdentity();
|
||||
SimpleIdentity(const SimpleIdentity&) = default;
|
||||
@@ -35,7 +37,6 @@ private:
|
||||
std::int64_t uniqueID;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Base class for objects that inherit an automatically-assigned unique identity
|
||||
*/
|
||||
@@ -46,13 +47,13 @@ protected:
|
||||
virtual ~SimpleIdentifiable() = default;
|
||||
|
||||
const util::SimpleIdentity& getId() const { return uniqueID; }
|
||||
|
||||
|
||||
protected:
|
||||
util::SimpleIdentity uniqueID;
|
||||
};
|
||||
|
||||
inline std::string toString(const util::SimpleIdentity& ident) {
|
||||
return "{"+std::to_string(ident.id())+"}";
|
||||
return "{" + std::to_string(ident.id()) + "}";
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
||||
@@ -5,13 +5,19 @@ namespace util {
|
||||
|
||||
/// Wrapper that doesn't participate in copying.
|
||||
/// This allows a default-copyable object to have members that aren't copied
|
||||
template<typename T> struct SuppressCopies {
|
||||
template <typename T>
|
||||
struct SuppressCopies {
|
||||
SuppressCopies() = default;
|
||||
SuppressCopies(SuppressCopies const&) {}
|
||||
SuppressCopies(SuppressCopies&& other) : value(std::forward<T>(other.value)) {}
|
||||
SuppressCopies& operator=(SuppressCopies o) { std::swap(value, o.value); return *this; }
|
||||
SuppressCopies(SuppressCopies&& other)
|
||||
: value(std::forward<T>(other.value)) {}
|
||||
SuppressCopies& operator=(SuppressCopies o) {
|
||||
std::swap(value, o.value);
|
||||
return *this;
|
||||
}
|
||||
operator T&() { return value; }
|
||||
T& get() { return value; }
|
||||
T& get() { return value; }
|
||||
|
||||
private:
|
||||
T value;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user