Skip to content

Commit facf34f

Browse files
committed
Added rule of five ctors/operators
1 parent 8962fc1 commit facf34f

File tree

12 files changed

+385
-0
lines changed

12 files changed

+385
-0
lines changed

include/AudioStream.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ class AudioStream : public ::AudioStream {
2121
set(InitAudioStream(SampleRate, SampleSize, Channels));
2222
}
2323

24+
AudioStream(const AudioStream&) = delete;
25+
26+
AudioStream(AudioStream&& other) {
27+
set(other);
28+
29+
other.buffer = nullptr;
30+
other.sampleRate = 0;
31+
other.sampleSize = 0;
32+
other.channels = 0;
33+
}
34+
2435
~AudioStream() {
2536
Close();
2637
}
@@ -35,6 +46,24 @@ class AudioStream : public ::AudioStream {
3546
return *this;
3647
}
3748

49+
AudioStream& operator=(const AudioStream&) = delete;
50+
51+
AudioStream& operator=(AudioStream&& other) {
52+
if (this == &other) {
53+
return *this;
54+
}
55+
56+
Close();
57+
set(other);
58+
59+
other.buffer = nullptr;
60+
other.sampleRate = 0;
61+
other.sampleSize = 0;
62+
other.channels = 0;
63+
64+
return *this;
65+
}
66+
3867
/**
3968
* Update audio stream buffers with data
4069
*/

include/Font.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ class Font : public ::Font {
3838
charsCount));
3939
}
4040

41+
Font(const Font&) = delete;
42+
43+
Font(Font&& other) {
44+
set(other);
45+
46+
other.baseSize = 0;
47+
other.charsCount = 0;
48+
other.charsPadding = 0;
49+
other.texture = { 0 };
50+
other.recs = nullptr;
51+
other.chars = nullptr;
52+
}
53+
4154
~Font() {
4255
Unload();
4356
}
@@ -58,6 +71,26 @@ class Font : public ::Font {
5871
return *this;
5972
}
6073

74+
Font& operator=(const Font&) = delete;
75+
76+
Font& operator=(Font&& other) {
77+
if (this == &other) {
78+
return *this;
79+
}
80+
81+
Unload();
82+
set(other);
83+
84+
other.baseSize = 0;
85+
other.charsCount = 0;
86+
other.charsPadding = 0;
87+
other.texture = { 0 };
88+
other.recs = nullptr;
89+
other.chars = nullptr;
90+
91+
return *this;
92+
}
93+
6194
/**
6295
* Draw text using font and additional parameters.
6396
*/

include/Image.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ class Image : public ::Image {
4747
set(::ImageTextEx(font, text.c_str(), fontSize, spacing, tint));
4848
}
4949

50+
Image(const Image& other) {
51+
set(other.Copy());
52+
}
53+
54+
Image(Image&& other) {
55+
set(other);
56+
57+
other.data = nullptr;
58+
other.width = 0;
59+
other.height = 0;
60+
other.mipmaps = 0;
61+
other.format = 0;
62+
}
63+
5064
static ::Image Text(const std::string& text, int fontSize,
5165
::Color color = {255, 255, 255, 255}) {
5266
return ::ImageText(text.c_str(), fontSize, color);
@@ -132,6 +146,32 @@ class Image : public ::Image {
132146
return *this;
133147
}
134148

149+
Image& operator=(const Image& other) {
150+
if (this == &other) {
151+
return *this;
152+
}
153+
154+
Unload();
155+
set(other.Copy());
156+
}
157+
158+
Image& operator=(Image&& other) {
159+
if (this == &other) {
160+
return *this;
161+
}
162+
163+
Unload();
164+
set(other);
165+
166+
other.data = nullptr;
167+
other.width = 0;
168+
other.height = 0;
169+
other.mipmaps = 0;
170+
other.format = 0;
171+
172+
return *this;
173+
}
174+
135175
/**
136176
* Load image from file into CPU memory (RAM)
137177
*/

include/Material.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ class Material : public ::Material {
2424
set(LoadMaterialDefault());
2525
}
2626

27+
Material(const Material&) = delete;
28+
29+
Material(Material&& other) {
30+
set(other);
31+
32+
other.maps = nullptr;
33+
other.shader = { 0 };
34+
}
35+
2736
~Material() {
2837
Unload();
2938
}
@@ -33,6 +42,7 @@ class Material : public ::Material {
3342
*/
3443
static std::vector<Material> Load(const std::string& fileName) {
3544
int count = 0;
45+
// this function possibly leaks the materials array
3646
::Material* materials = ::LoadMaterials(fileName.c_str(), &count);
3747
return std::vector<Material>(materials, materials + count);
3848
}
@@ -47,6 +57,22 @@ class Material : public ::Material {
4757
return *this;
4858
}
4959

60+
Material& operator=(const Material&) = delete;
61+
62+
Material& operator=(Material&& other) {
63+
if (this != &other) {
64+
return *this;
65+
}
66+
67+
Unload();
68+
set(other);
69+
70+
other.maps = nullptr;
71+
other.shader = { 0 };
72+
73+
return *this;
74+
}
75+
5076
/**
5177
* Unload material from memory
5278
*/

include/Mesh.hpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ class Mesh : public ::Mesh {
3030
// return std::vector<Mesh>(meshes, meshes + count);
3131
// }
3232

33+
Mesh(const Mesh&) = delete;
34+
35+
Mesh(Mesh&& other) {
36+
set(other);
37+
38+
other.vertexCount = 0;
39+
other.triangleCount = 0;
40+
other.vertices = nullptr;
41+
other.texcoords = nullptr;
42+
other.texcoords2 = nullptr;
43+
other.normals = nullptr;
44+
other.tangents = nullptr;
45+
other.colors = nullptr;
46+
other.indices = nullptr;
47+
other.animVertices = nullptr;
48+
other.animNormals = nullptr;
49+
other.boneIds = nullptr;
50+
other.boneWeights = nullptr;
51+
other.vaoId = 0;
52+
other.vboId = nullptr;
53+
}
54+
3355
/**
3456
* Generate polygonal mesh
3557
*/
@@ -121,6 +143,35 @@ class Mesh : public ::Mesh {
121143
return *this;
122144
}
123145

146+
Mesh& operator=(const Mesh&) = delete;
147+
148+
Mesh& operator=(Mesh&& other) {
149+
if (this != &other) {
150+
return *this;
151+
}
152+
153+
Unload();
154+
set(other);
155+
156+
other.vertexCount = 0;
157+
other.triangleCount = 0;
158+
other.vertices = nullptr;
159+
other.texcoords = nullptr;
160+
other.texcoords2 = nullptr;
161+
other.normals = nullptr;
162+
other.tangents = nullptr;
163+
other.colors = nullptr;
164+
other.indices = nullptr;
165+
other.animVertices = nullptr;
166+
other.animNormals = nullptr;
167+
other.boneIds = nullptr;
168+
other.boneWeights = nullptr;
169+
other.vaoId = 0;
170+
other.vboId = nullptr;
171+
172+
return *this;
173+
}
174+
124175
~Mesh() {
125176
Unload();
126177
}

include/Model.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ class Model : public ::Model {
2929
Unload();
3030
}
3131

32+
Model(const Model&) = delete;
33+
34+
Model(Model&& other) {
35+
set(other);
36+
37+
other.bones = nullptr;
38+
other.boneCount = 0;
39+
other.materials = nullptr;
40+
other.materialCount = 0;
41+
other.meshes = nullptr;
42+
other.meshCount = 0;
43+
other.bindPose = nullptr;
44+
}
45+
3246
GETTERSETTER(::Matrix, Transform, transform)
3347
GETTERSETTER(int, MeshCount, meshCount)
3448
GETTERSETTER(int, MaterialCount, materialCount)
@@ -44,6 +58,27 @@ class Model : public ::Model {
4458
return *this;
4559
}
4660

61+
Model& operator=(const Model&) = delete;
62+
63+
Model& operator=(Model&& other) {
64+
if (this != &other) {
65+
return *this;
66+
}
67+
68+
Unload();
69+
set(other);
70+
71+
other.bones = nullptr;
72+
other.boneCount = 0;
73+
other.materials = nullptr;
74+
other.materialCount = 0;
75+
other.meshes = nullptr;
76+
other.meshCount = 0;
77+
other.bindPose = nullptr;
78+
79+
return *this;
80+
}
81+
4782
/**
4883
* Unload model (including meshes) from memory (RAM and/or VRAM)
4984
*/

include/ModelAnimation.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ class ModelAnimation : public ::ModelAnimation {
1818
set(model);
1919
}
2020

21+
ModelAnimation(const ModelAnimation&) = delete;
22+
23+
ModelAnimation(ModelAnimation&& other) {
24+
set(other);
25+
26+
other.boneCount = 0;
27+
other.bones = nullptr;
28+
other.frameCount = 0;
29+
other.framePoses = nullptr;
30+
}
31+
2132
~ModelAnimation() {
2233
Unload();
2334
}
@@ -41,6 +52,23 @@ class ModelAnimation : public ::ModelAnimation {
4152
return *this;
4253
}
4354

55+
56+
ModelAnimation& operator=(const ModelAnimation&) = delete;
57+
58+
ModelAnimation& operator=(ModelAnimation&& other) {
59+
if (this != &other) {
60+
return *this;
61+
}
62+
63+
Unload();
64+
set(other);
65+
66+
other.boneCount = 0;
67+
other.bones = nullptr;
68+
other.frameCount = 0;
69+
other.framePoses = nullptr;
70+
}
71+
4472
/**
4573
* Unload animation data
4674
*/

include/Music.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ class Music : public ::Music {
3030
set(::LoadMusicStreamFromMemory(fileType.c_str(), data, dataSize));
3131
}
3232

33+
Music(const Music&) = delete;
34+
35+
Music(Music&& other) {
36+
set(other);
37+
38+
other.ctxType = 0;
39+
other.ctxData = nullptr;
40+
other.looping = false;
41+
other.sampleCount = 0;
42+
other.stream = { 0 };
43+
}
44+
3345
/**
3446
* Unload music stream
3547
*/
@@ -48,6 +60,25 @@ class Music : public ::Music {
4860
return *this;
4961
}
5062

63+
Music& operator=(const Music&) = delete;
64+
65+
Music& operator=(Music&& other) {
66+
if (this == &other) {
67+
return *this;
68+
}
69+
70+
Unload();
71+
set(other);
72+
73+
other.ctxType = 0;
74+
other.ctxData = nullptr;
75+
other.looping = false;
76+
other.sampleCount = 0;
77+
other.stream = { 0 };
78+
79+
return *this;
80+
}
81+
5182
/**
5283
* Unload music stream
5384
*/

0 commit comments

Comments
 (0)