Added rule of five ctors/operators

This commit is contained in:
Mafciejewicz
2021-08-30 00:37:32 +02:00
parent 8962fc147d
commit facf34ff1c
12 changed files with 385 additions and 0 deletions

View File

@@ -21,6 +21,17 @@ class AudioStream : public ::AudioStream {
set(InitAudioStream(SampleRate, SampleSize, Channels));
}
AudioStream(const AudioStream&) = delete;
AudioStream(AudioStream&& other) {
set(other);
other.buffer = nullptr;
other.sampleRate = 0;
other.sampleSize = 0;
other.channels = 0;
}
~AudioStream() {
Close();
}
@@ -35,6 +46,24 @@ class AudioStream : public ::AudioStream {
return *this;
}
AudioStream& operator=(const AudioStream&) = delete;
AudioStream& operator=(AudioStream&& other) {
if (this == &other) {
return *this;
}
Close();
set(other);
other.buffer = nullptr;
other.sampleRate = 0;
other.sampleSize = 0;
other.channels = 0;
return *this;
}
/**
* Update audio stream buffers with data
*/

View File

@@ -38,6 +38,19 @@ class Font : public ::Font {
charsCount));
}
Font(const Font&) = delete;
Font(Font&& other) {
set(other);
other.baseSize = 0;
other.charsCount = 0;
other.charsPadding = 0;
other.texture = { 0 };
other.recs = nullptr;
other.chars = nullptr;
}
~Font() {
Unload();
}
@@ -58,6 +71,26 @@ class Font : public ::Font {
return *this;
}
Font& operator=(const Font&) = delete;
Font& operator=(Font&& other) {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.baseSize = 0;
other.charsCount = 0;
other.charsPadding = 0;
other.texture = { 0 };
other.recs = nullptr;
other.chars = nullptr;
return *this;
}
/**
* Draw text using font and additional parameters.
*/

View File

@@ -47,6 +47,20 @@ class Image : public ::Image {
set(::ImageTextEx(font, text.c_str(), fontSize, spacing, tint));
}
Image(const Image& other) {
set(other.Copy());
}
Image(Image&& other) {
set(other);
other.data = nullptr;
other.width = 0;
other.height = 0;
other.mipmaps = 0;
other.format = 0;
}
static ::Image Text(const std::string& text, int fontSize,
::Color color = {255, 255, 255, 255}) {
return ::ImageText(text.c_str(), fontSize, color);
@@ -132,6 +146,32 @@ class Image : public ::Image {
return *this;
}
Image& operator=(const Image& other) {
if (this == &other) {
return *this;
}
Unload();
set(other.Copy());
}
Image& operator=(Image&& other) {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.data = nullptr;
other.width = 0;
other.height = 0;
other.mipmaps = 0;
other.format = 0;
return *this;
}
/**
* Load image from file into CPU memory (RAM)
*/

View File

@@ -24,6 +24,15 @@ class Material : public ::Material {
set(LoadMaterialDefault());
}
Material(const Material&) = delete;
Material(Material&& other) {
set(other);
other.maps = nullptr;
other.shader = { 0 };
}
~Material() {
Unload();
}
@@ -33,6 +42,7 @@ class Material : public ::Material {
*/
static std::vector<Material> Load(const std::string& fileName) {
int count = 0;
// this function possibly leaks the materials array
::Material* materials = ::LoadMaterials(fileName.c_str(), &count);
return std::vector<Material>(materials, materials + count);
}
@@ -47,6 +57,22 @@ class Material : public ::Material {
return *this;
}
Material& operator=(const Material&) = delete;
Material& operator=(Material&& other) {
if (this != &other) {
return *this;
}
Unload();
set(other);
other.maps = nullptr;
other.shader = { 0 };
return *this;
}
/**
* Unload material from memory
*/

View File

@@ -30,6 +30,28 @@ class Mesh : public ::Mesh {
// return std::vector<Mesh>(meshes, meshes + count);
// }
Mesh(const Mesh&) = delete;
Mesh(Mesh&& other) {
set(other);
other.vertexCount = 0;
other.triangleCount = 0;
other.vertices = nullptr;
other.texcoords = nullptr;
other.texcoords2 = nullptr;
other.normals = nullptr;
other.tangents = nullptr;
other.colors = nullptr;
other.indices = nullptr;
other.animVertices = nullptr;
other.animNormals = nullptr;
other.boneIds = nullptr;
other.boneWeights = nullptr;
other.vaoId = 0;
other.vboId = nullptr;
}
/**
* Generate polygonal mesh
*/
@@ -121,6 +143,35 @@ class Mesh : public ::Mesh {
return *this;
}
Mesh& operator=(const Mesh&) = delete;
Mesh& operator=(Mesh&& other) {
if (this != &other) {
return *this;
}
Unload();
set(other);
other.vertexCount = 0;
other.triangleCount = 0;
other.vertices = nullptr;
other.texcoords = nullptr;
other.texcoords2 = nullptr;
other.normals = nullptr;
other.tangents = nullptr;
other.colors = nullptr;
other.indices = nullptr;
other.animVertices = nullptr;
other.animNormals = nullptr;
other.boneIds = nullptr;
other.boneWeights = nullptr;
other.vaoId = 0;
other.vboId = nullptr;
return *this;
}
~Mesh() {
Unload();
}

View File

@@ -29,6 +29,20 @@ class Model : public ::Model {
Unload();
}
Model(const Model&) = delete;
Model(Model&& other) {
set(other);
other.bones = nullptr;
other.boneCount = 0;
other.materials = nullptr;
other.materialCount = 0;
other.meshes = nullptr;
other.meshCount = 0;
other.bindPose = nullptr;
}
GETTERSETTER(::Matrix, Transform, transform)
GETTERSETTER(int, MeshCount, meshCount)
GETTERSETTER(int, MaterialCount, materialCount)
@@ -44,6 +58,27 @@ class Model : public ::Model {
return *this;
}
Model& operator=(const Model&) = delete;
Model& operator=(Model&& other) {
if (this != &other) {
return *this;
}
Unload();
set(other);
other.bones = nullptr;
other.boneCount = 0;
other.materials = nullptr;
other.materialCount = 0;
other.meshes = nullptr;
other.meshCount = 0;
other.bindPose = nullptr;
return *this;
}
/**
* Unload model (including meshes) from memory (RAM and/or VRAM)
*/

View File

@@ -18,6 +18,17 @@ class ModelAnimation : public ::ModelAnimation {
set(model);
}
ModelAnimation(const ModelAnimation&) = delete;
ModelAnimation(ModelAnimation&& other) {
set(other);
other.boneCount = 0;
other.bones = nullptr;
other.frameCount = 0;
other.framePoses = nullptr;
}
~ModelAnimation() {
Unload();
}
@@ -41,6 +52,23 @@ class ModelAnimation : public ::ModelAnimation {
return *this;
}
ModelAnimation& operator=(const ModelAnimation&) = delete;
ModelAnimation& operator=(ModelAnimation&& other) {
if (this != &other) {
return *this;
}
Unload();
set(other);
other.boneCount = 0;
other.bones = nullptr;
other.frameCount = 0;
other.framePoses = nullptr;
}
/**
* Unload animation data
*/

View File

@@ -30,6 +30,18 @@ class Music : public ::Music {
set(::LoadMusicStreamFromMemory(fileType.c_str(), data, dataSize));
}
Music(const Music&) = delete;
Music(Music&& other) {
set(other);
other.ctxType = 0;
other.ctxData = nullptr;
other.looping = false;
other.sampleCount = 0;
other.stream = { 0 };
}
/**
* Unload music stream
*/
@@ -48,6 +60,25 @@ class Music : public ::Music {
return *this;
}
Music& operator=(const Music&) = delete;
Music& operator=(Music&& other) {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.ctxType = 0;
other.ctxData = nullptr;
other.looping = false;
other.sampleCount = 0;
other.stream = { 0 };
return *this;
}
/**
* Unload music stream
*/

View File

@@ -20,6 +20,16 @@ class RenderTexture : public ::RenderTexture {
set(LoadRenderTexture(width, height));
}
RenderTexture(const RenderTexture&) = delete;
RenderTexture(RenderTexture&& other) {
set(other);
other.id = 0;
other.texture = { 0 };
other.depth = { 0 };
}
GETTERSETTER(unsigned int, Id, id)
GETTERSETTER(::Texture2D, Texture, texture)
GETTERSETTER(::Texture2D, Depth, depth)
@@ -29,6 +39,23 @@ class RenderTexture : public ::RenderTexture {
return *this;
}
RenderTexture& operator=(const RenderTexture&) = delete;
RenderTexture& operator=(RenderTexture&& other) {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.id = 0;
other.texture = { 0 };
other.depth = { 0 };
return *this;
}
~RenderTexture() {
Unload();
}

View File

@@ -23,6 +23,15 @@ class Shader : public ::Shader {
set(::LoadShader(vsFileName.c_str(), fsFileName.c_str()));
}
Shader(const Shader&) = delete;
Shader(Shader&& other) {
set(other);
other.id = 0;
other.locs = nullptr;
}
/**
* Load shader from files and bind default locations.
*/
@@ -42,6 +51,20 @@ class Shader : public ::Shader {
return *this;
}
Shader& operator=(const Shader&) = delete;
Shader& operator=(Shader&& other) {
if (this != &other) {
return *this;
}
Unload();
set(other);
other.id = 0;
other.locs = nullptr;
}
~Shader() {
Unload();
}

View File

@@ -38,6 +38,18 @@ class Texture : public ::Texture {
Load(fileName);
}
Texture(const Texture&) = delete;
Texture(Texture&& other) {
set(other);
other.id = 0;
other.width = 0;
other.height = 0;
other.mipmaps = 0;
other.format = 0;
}
~Texture() {
Unload();
}
@@ -53,6 +65,25 @@ class Texture : public ::Texture {
return *this;
}
Texture& operator=(const Texture&) = delete;
Texture& operator=(Texture&& other) {
if (this == &other) {
return *this;
}
Unload();
set(other);
other.id = 0;
other.width = 0;
other.height = 0;
other.mipmaps = 0;
other.format = 0;
return *this;
}
/**
* Retrieve the width and height of the texture.
*/

View File

@@ -38,6 +38,18 @@ class Wave : public ::Wave {
set(::LoadWaveFromMemory(fileType.c_str(), fileData, dataSize));
}
Wave(const Wave&) = delete;
Wave(Wave&& other) {
set(other);
other.sampleCount = 0;
other.sampleRate = 0;
other.sampleSize = 0;
other.channels = 0;
other.data = nullptr;
}
/**
* Unload wave data
*/
@@ -56,6 +68,25 @@ class Wave : public ::Wave {
return *this;
}
Wave& operator=(const Wave&) = delete;
Wave& operator=(Wave&& other) {
if (this != &other) {
return *this;
}
Unload();
set(other);
other.sampleCount = 0;
other.sampleRate = 0;
other.sampleSize = 0;
other.channels = 0;
other.data = nullptr;
return *this;
}
/**
* Convert wave data to desired format
*/