Making classes non-assignable

Following CppCheck recomendation, all classes that should not be manipulated by value are made non-assignable to ensure no mistake is made.
This commit is contained in:
Bruno
2021-04-18 13:04:16 +02:00
parent c6d01c1420
commit 2392d844d9
17 changed files with 83 additions and 23 deletions

View File

@@ -289,7 +289,7 @@ set(VMIX_SRCS
Selection.cpp Selection.cpp
SessionSource.cpp SessionSource.cpp
SessionVisitor.cpp SessionVisitor.cpp
GarbageVisitor.cpp Interpolator.cpp
SessionCreator.cpp SessionCreator.cpp
Mixer.cpp Mixer.cpp
FrameGrabber.cpp FrameGrabber.cpp

View File

@@ -24,6 +24,9 @@ public:
FrameBufferImage(int w, int h); FrameBufferImage(int w, int h);
FrameBufferImage(jpegBuffer jpgimg); FrameBufferImage(jpegBuffer jpgimg);
// non assignable class
FrameBufferImage(FrameBufferImage const&) = delete;
FrameBufferImage& operator=(FrameBufferImage const&) = delete;
~FrameBufferImage(); ~FrameBufferImage();
}; };
@@ -45,6 +48,7 @@ public:
FrameBuffer(glm::vec3 resolution, bool useAlpha = false, bool multiSampling = false); FrameBuffer(glm::vec3 resolution, bool useAlpha = false, bool multiSampling = false);
FrameBuffer(uint width, uint height, bool useAlpha = false, bool multiSampling = false); FrameBuffer(uint width, uint height, bool useAlpha = false, bool multiSampling = false);
FrameBuffer(FrameBuffer const&) = delete;
~FrameBuffer(); ~FrameBuffer();
// Bind & push attribs to prepare draw // Bind & push attribs to prepare draw

View File

@@ -7,6 +7,9 @@ class GeometryView : public View
{ {
public: public:
GeometryView(); GeometryView();
// non assignable class
GeometryView(GeometryView const&) = delete;
GeometryView& operator=(GeometryView const&) = delete;
void draw () override; void draw () override;
void update (float dt) override; void update (float dt) override;

View File

@@ -1194,7 +1194,7 @@ struct InputTextCallback_UserData
static int InputTextCallback(ImGuiInputTextCallbackData* data) static int InputTextCallback(ImGuiInputTextCallbackData* data)
{ {
InputTextCallback_UserData* user_data = (InputTextCallback_UserData*)data->UserData; InputTextCallback_UserData* user_data = static_cast<InputTextCallback_UserData*>(data->UserData);
if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) if (data->EventFlag == ImGuiInputTextFlags_CallbackResize)
{ {
// if (user_data->WordWrap > 1) // if (user_data->WordWrap > 1)

View File

@@ -1,9 +1,27 @@
#include <glm/gtc/matrix_access.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include "defines.h"
#include "Log.h"
#include "ImageProcessingShader.h"
#include "Interpolator.h" #include "Interpolator.h"
Interpolator::Interpolator(Source *subject, const SourceCore &target) : Interpolator::Interpolator(Source *subject, const SourceCore &target) :
subject_(subject), cursor_(0.f) subject_(subject), from_(static_cast<SourceCore> (*subject)), to_(target), cursor_(0.f)
{ {
from_ = static_cast<SourceCore> (*subject);
to_ = target;
}
void Interpolator::apply(float percent)
{
cursor_ = CLAMP( percent, 0.f, 1.f);
} }

View File

@@ -16,6 +16,7 @@ public:
float cursor_; float cursor_;
void apply(float percent);
}; };

View File

@@ -7,6 +7,9 @@ class LayerView : public View
{ {
public: public:
LayerView(); LayerView();
// non assignable class
LayerView(LayerView const&) = delete;
LayerView& operator=(LayerView const&) = delete;
void draw () override; void draw () override;
void update (float dt) override; void update (float dt) override;

View File

@@ -14,6 +14,9 @@ class MixingGroup
public: public:
MixingGroup (SourceList sources); MixingGroup (SourceList sources);
// non assignable class
MixingGroup(MixingGroup const&) = delete;
MixingGroup& operator=(MixingGroup const&) = delete;
~MixingGroup (); ~MixingGroup ();
// Get unique id // Get unique id

View File

@@ -9,6 +9,9 @@ class MixingView : public View
{ {
public: public:
MixingView(); MixingView();
// non assignable class
MixingView(MixingView const&) = delete;
MixingView& operator=(MixingView const&) = delete;
void draw () override; void draw () override;
void update (float dt) override; void update (float dt) override;

View File

@@ -20,6 +20,7 @@ protected:
const IpEndpointName& remoteEndpoint ); const IpEndpointName& remoteEndpoint );
public: public:
inline void setParent(NetworkStream *s) { parent_ = s; } inline void setParent(NetworkStream *s) { parent_ = s; }
StreamerResponseListener() : parent_(nullptr) {}
}; };

View File

@@ -239,6 +239,9 @@ class Scene {
public: public:
Scene(); Scene();
// non assignable class
Scene(Scene const&) = delete;
Scene& operator=(Scene const&) = delete;
~Scene(); ~Scene();
void accept (Visitor& v); void accept (Visitor& v);

View File

@@ -80,8 +80,8 @@ bool SessionVisitor::saveSession(const std::string& filename, Session *session)
// for( ; N ; N=N->NextSiblingElement()) // for( ; N ; N=N->NextSiblingElement())
// snapshots->InsertEndChild( N->DeepClone( &xmlDoc )); // snapshots->InsertEndChild( N->DeepClone( &xmlDoc ));
XMLText *text = xmlDoc.NewText( Action::manager().snapshotsDescription() ); XMLText *desc = xmlDoc.NewText( Action::manager().snapshotsDescription() );
snapshots->InsertEndChild( text ); snapshots->InsertEndChild( desc );
xmlDoc.InsertEndChild(snapshots); xmlDoc.InsertEndChild(snapshots);
// 4. optional notes // 4. optional notes

View File

@@ -17,7 +17,7 @@
#include "Source.h" #include "Source.h"
SourceCore::SourceCore() : processingshader_(nullptr) SourceCore::SourceCore()
{ {
// default nodes // default nodes
groups_[View::RENDERING] = new Group; groups_[View::RENDERING] = new Group;
@@ -40,6 +40,11 @@ SourceCore::SourceCore() : processingshader_(nullptr)
renderingshader_ = static_cast<Shader *>(new ImageShader); renderingshader_ = static_cast<Shader *>(new ImageShader);
} }
SourceCore::SourceCore(SourceCore const& other) : SourceCore()
{
copy(other);
}
SourceCore::~SourceCore() SourceCore::~SourceCore()
{ {
// all groups and their children are deleted in the scene // all groups and their children are deleted in the scene
@@ -61,6 +66,22 @@ SourceCore::~SourceCore()
groups_.clear(); groups_.clear();
} }
void SourceCore::copy(SourceCore const& other)
{
// copy groups properties
groups_[View::RENDERING]->copyTransform( other.group(View::RENDERING) );
groups_[View::MIXING]->copyTransform( other.group(View::MIXING) );
groups_[View::GEOMETRY]->copyTransform( other.group(View::GEOMETRY) );
groups_[View::LAYER]->copyTransform( other.group(View::LAYER) );
groups_[View::TEXTURE]->copyTransform( other.group(View::TEXTURE) );
groups_[View::TRANSITION]->copyTransform( other.group(View::TRANSITION) );
stored_status_->copyTransform( other.stored_status_ );
// copy shader properties
processingshader_->copy(*other.processingshader_);
renderingshader_->copy(*other.renderingshader_);
}
void SourceCore::store (View::Mode m) void SourceCore::store (View::Mode m)
{ {
stored_status_->copyTransform(groups_[m]); stored_status_->copyTransform(groups_[m]);
@@ -69,18 +90,7 @@ void SourceCore::store (View::Mode m)
SourceCore& SourceCore::operator= (SourceCore const& other) SourceCore& SourceCore::operator= (SourceCore const& other)
{ {
if (this != &other) { // no self assignment if (this != &other) { // no self assignment
// copy groups properties copy(other);
groups_[View::RENDERING]->copyTransform( other.group(View::RENDERING) );
groups_[View::MIXING]->copyTransform( other.group(View::MIXING) );
groups_[View::GEOMETRY]->copyTransform( other.group(View::GEOMETRY) );
groups_[View::LAYER]->copyTransform( other.group(View::LAYER) );
groups_[View::TEXTURE]->copyTransform( other.group(View::TEXTURE) );
groups_[View::TRANSITION]->copyTransform( other.group(View::TRANSITION) );
stored_status_->copyTransform( other.stored_status_ );
// copy shader properties
processingshader_->copy(*other.processingshader_);
renderingshader_->copy(*other.renderingshader_);
} }
return *this; return *this;
} }

View File

@@ -27,6 +27,8 @@ class SourceCore
{ {
public: public:
SourceCore(); SourceCore();
SourceCore(SourceCore const&);
SourceCore& operator= (SourceCore const& other);
virtual ~SourceCore(); virtual ~SourceCore();
// get handle on the nodes used to manipulate the source in a view // get handle on the nodes used to manipulate the source in a view
@@ -39,8 +41,6 @@ public:
// a Source always has an image processing shader // a Source always has an image processing shader
inline ImageProcessingShader *processingShader () const { return processingshader_; } inline ImageProcessingShader *processingShader () const { return processingshader_; }
SourceCore& operator= (SourceCore const& other);
protected: protected:
// nodes // nodes
std::map<View::Mode, Group*> groups_; std::map<View::Mode, Group*> groups_;
@@ -51,6 +51,8 @@ protected:
// pointer to the currently attached shader // pointer to the currently attached shader
// (will be processingshader_ if image processing is enabled) // (will be processingshader_ if image processing is enabled)
Shader *renderingshader_; Shader *renderingshader_;
void copy(SourceCore const& other);
}; };
class Source : public SourceCore class Source : public SourceCore
@@ -69,6 +71,9 @@ public:
// create a source and add it to the list // create a source and add it to the list
// only subclasses of sources can actually be instanciated // only subclasses of sources can actually be instanciated
Source (uint64_t id = 0); Source (uint64_t id = 0);
// non assignable class
Source(Source const&) = delete;
Source& operator=(Source const&) = delete;
virtual ~Source (); virtual ~Source ();
// Get unique id // Get unique id

View File

@@ -8,6 +8,9 @@ class TextureView : public View
{ {
public: public:
TextureView(); TextureView();
// non assignable class
TextureView(TextureView const&) = delete;
TextureView& operator=(TextureView const&) = delete;
void draw () override; void draw () override;
void update (float dt) override; void update (float dt) override;

View File

@@ -7,6 +7,9 @@ class TransitionView : public View
{ {
public: public:
TransitionView(); TransitionView();
// non assignable class
TransitionView(TransitionView const&) = delete;
TransitionView& operator=(TransitionView const&) = delete;
void draw () override; void draw () override;
void update (float dt) override; void update (float dt) override;

View File

@@ -100,7 +100,7 @@ UserInterface::UserInterface()
show_opengl_about = false; show_opengl_about = false;
show_view_navigator = 0; show_view_navigator = 0;
target_view_navigator = 1; target_view_navigator = 1;
currentTextEdit = ""; currentTextEdit.clear();
screenshot_step = 0; screenshot_step = 0;
// keep hold on frame grabbers // keep hold on frame grabbers