From e185bf58b731ca5eb66c98b6865760236883cc7c Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Mon, 4 Oct 2021 16:56:26 +0200 Subject: [PATCH] Replaced "Simple shorthands for smart pointers" shptr, uqptr, wkptr with their original names. Using weird shorthands makes the code unreadable for anyone but the original author. template using shptr = std::shared_ptr; template using uqptr = std::unique_ptr; template using wkptr = std::weak_ptr; --- sandboxes/opencsg/Engine.cpp | 6 ++-- sandboxes/opencsg/Engine.hpp | 43 ++++++++++++-------------- sandboxes/opencsg/ShaderCSGDisplay.hpp | 2 +- sandboxes/opencsg/main.cpp | 22 ++++++------- src/libslic3r/Format/SL1.cpp | 2 +- src/libslic3r/Format/SL1.hpp | 2 +- src/libslic3r/SLA/RasterBase.hpp | 6 +--- src/libslic3r/SLAPrint.hpp | 2 +- 8 files changed, 38 insertions(+), 47 deletions(-) diff --git a/sandboxes/opencsg/Engine.cpp b/sandboxes/opencsg/Engine.cpp index d8f1d3464..e64a47132 100644 --- a/sandboxes/opencsg/Engine.cpp +++ b/sandboxes/opencsg/Engine.cpp @@ -65,7 +65,7 @@ void CSGDisplay::render_scene() glFlush(); } -void Scene::set_print(uqptr &&print) +void Scene::set_print(std::unique_ptr &&print) { m_print = std::move(print); @@ -85,7 +85,7 @@ void CSGDisplay::SceneCache::clear() primitives.clear(); } -shptr CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh) +std::shared_ptr CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh) { auto p = std::make_shared(); p->load_mesh(mesh); @@ -94,7 +94,7 @@ shptr CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh) return p; } -shptr CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh, +std::shared_ptr CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh, OpenCSG::Operation o, unsigned c) { diff --git a/sandboxes/opencsg/Engine.hpp b/sandboxes/opencsg/Engine.hpp index fc76c1b31..114268ddc 100644 --- a/sandboxes/opencsg/Engine.hpp +++ b/sandboxes/opencsg/Engine.hpp @@ -17,11 +17,6 @@ class SLAPrint; namespace GL { -// Simple shorthands for smart pointers -template using shptr = std::shared_ptr; -template using uqptr = std::unique_ptr; -template using wkptr = std::weak_ptr; - template> using vector = std::vector; // remove empty weak pointers from a vector @@ -61,7 +56,7 @@ public: }; private: - vector> m_listeners; + vector> m_listeners; public: virtual ~MouseInput() = default; @@ -95,7 +90,7 @@ public: call(&Listener::on_moved_to, m_listeners, x, y); } - void add_listener(shptr listener) + void add_listener(std::shared_ptr listener) { m_listeners.emplace_back(listener); cleanup(m_listeners); @@ -322,7 +317,7 @@ public: // The scene is a wrapper around SLAPrint which holds the data to be visualized. class Scene { - uqptr m_print; + std::unique_ptr m_print; public: // Subscribers will be notified if the model is changed. This might be a @@ -340,19 +335,19 @@ public: Scene(); ~Scene(); - void set_print(uqptr &&print); + void set_print(std::unique_ptr &&print); const SLAPrint * get_print() const { return m_print.get(); } BoundingBoxf3 get_bounding_box() const; - void add_listener(shptr listener) + void add_listener(std::shared_ptr listener) { m_listeners.emplace_back(listener); cleanup(m_listeners); } private: - vector> m_listeners; + vector> m_listeners; }; // The basic Display. This is almost just an interface but will do all the @@ -366,20 +361,20 @@ protected: Vec2i m_size; bool m_initialized = false; - shptr m_camera; + std::shared_ptr m_camera; FpsCounter m_fps_counter; public: - explicit Display(shptr camera = nullptr) + explicit Display(std::shared_ptr camera = nullptr) : m_camera(camera ? camera : std::make_shared()) {} ~Display() override; - shptr get_camera() const { return m_camera; } - shptr get_camera() { return m_camera; } - void set_camera(shptr cam) { m_camera = cam; } + std::shared_ptr get_camera() const { return m_camera; } + std::shared_ptr get_camera() { return m_camera; } + void set_camera(std::shared_ptr cam) { m_camera = cam; } virtual void swap_buffers() = 0; virtual void set_active(long width, long height); @@ -410,14 +405,14 @@ protected: // Cache the renderable primitives. These will be fetched when the scene // is modified. struct SceneCache { - vector> primitives; + vector> primitives; vector primitives_free; vector primitives_csg; void clear(); - shptr add_mesh(const TriangleMesh &mesh); - shptr add_mesh(const TriangleMesh &mesh, + std::shared_ptr add_mesh(const TriangleMesh &mesh); + std::shared_ptr add_mesh(const TriangleMesh &mesh, OpenCSG::Operation op, unsigned covexity); } m_scene_cache; @@ -446,13 +441,13 @@ class Controller : public std::enable_shared_from_this, Vec2i m_mouse_pos, m_mouse_pos_rprev, m_mouse_pos_lprev; bool m_left_btn = false, m_right_btn = false; - shptr m_scene; - vector> m_displays; + std::shared_ptr m_scene; + vector> m_displays; // Call a method of Camera on all the cameras of the attached displays template void call_cameras(F &&f, Args&&... args) { - for (wkptr &l : m_displays) + for (std::weak_ptr &l : m_displays) if (auto disp = l.lock()) if (auto cam = disp->get_camera()) (cam.get()->*f)(std::forward(args)...); } @@ -460,7 +455,7 @@ class Controller : public std::enable_shared_from_this, public: // Set the scene that will be controlled. - void set_scene(shptr scene) + void set_scene(std::shared_ptr scene) { m_scene = scene; m_scene->add_listener(shared_from_this()); @@ -468,7 +463,7 @@ public: const Scene * get_scene() const { return m_scene.get(); } - void add_display(shptr disp) + void add_display(std::shared_ptr disp) { m_displays.emplace_back(disp); cleanup(m_displays); diff --git a/sandboxes/opencsg/ShaderCSGDisplay.hpp b/sandboxes/opencsg/ShaderCSGDisplay.hpp index bf0c3a424..0e2c763df 100644 --- a/sandboxes/opencsg/ShaderCSGDisplay.hpp +++ b/sandboxes/opencsg/ShaderCSGDisplay.hpp @@ -12,7 +12,7 @@ class CSGVolume: public Volume class ShaderCSGDisplay: public Display { protected: - vector> m_volumes; + vector> m_volumes; void add_mesh(const TriangleMesh &mesh); public: diff --git a/sandboxes/opencsg/main.cpp b/sandboxes/opencsg/main.cpp index f5fb12493..f0627b974 100644 --- a/sandboxes/opencsg/main.cpp +++ b/sandboxes/opencsg/main.cpp @@ -34,7 +34,7 @@ using namespace Slic3r::GL; class Renderer { protected: wxGLCanvas *m_canvas; - shptr m_context; + std::shared_ptr m_context; public: Renderer(wxGLCanvas *c): m_canvas{c} { @@ -86,16 +86,16 @@ public: class Canvas: public wxGLCanvas { // One display is active at a time, the OCSGRenderer by default. - shptr m_display; + std::shared_ptr m_display; public: template Canvas(Args &&...args): wxGLCanvas(std::forward(args)...) {} - shptr get_display() const { return m_display; } + std::shared_ptr get_display() const { return m_display; } - void set_display(shptr d) { m_display = d; } + void set_display(std::shared_ptr d) { m_display = d; } }; // Enumerate possible mouse events, we will record them. @@ -197,14 +197,14 @@ public: class MyFrame: public wxFrame { // Instantiate the 3D engine. - shptr m_scene; // Model - shptr m_canvas; // Views store - shptr m_ocsgdisplay; // View - shptr m_shadercsg_display; // Another view - shptr m_ctl; // Controller + std::shared_ptr m_scene; // Model + std::shared_ptr m_canvas; // Views store + std::shared_ptr m_ocsgdisplay; // View + std::shared_ptr m_shadercsg_display; // Another view + std::shared_ptr m_ctl; // Controller // Add a status bar with progress indication. - shptr m_stbar; + std::shared_ptr m_stbar; RecorderMouseInput m_mouse; @@ -237,7 +237,7 @@ class MyFrame: public wxFrame } }; - uqptr m_ui_job; + std::unique_ptr m_ui_job; // To keep track of the running average of measured fps values. double m_fps_avg = 0.; diff --git a/src/libslic3r/Format/SL1.cpp b/src/libslic3r/Format/SL1.cpp index 4ddc584ba..c4b8f030f 100644 --- a/src/libslic3r/Format/SL1.cpp +++ b/src/libslic3r/Format/SL1.cpp @@ -423,7 +423,7 @@ void fill_slicerconf(ConfMap &m, const SLAPrint &print) } // namespace -uqptr SL1Archive::create_raster() const +std::unique_ptr SL1Archive::create_raster() const { sla::RasterBase::Resolution res; sla::RasterBase::PixelDim pxdim; diff --git a/src/libslic3r/Format/SL1.hpp b/src/libslic3r/Format/SL1.hpp index 7f4356b12..46a82e1b8 100644 --- a/src/libslic3r/Format/SL1.hpp +++ b/src/libslic3r/Format/SL1.hpp @@ -12,7 +12,7 @@ class SL1Archive: public SLAArchive { SLAPrinterConfig m_cfg; protected: - uqptr create_raster() const override; + std::unique_ptr create_raster() const override; sla::RasterEncoder get_encoder() const override; public: diff --git a/src/libslic3r/SLA/RasterBase.hpp b/src/libslic3r/SLA/RasterBase.hpp index 1cd688ccb..1eba360e3 100644 --- a/src/libslic3r/SLA/RasterBase.hpp +++ b/src/libslic3r/SLA/RasterBase.hpp @@ -13,10 +13,6 @@ namespace Slic3r { -template using uqptr = std::unique_ptr; -template using shptr = std::shared_ptr; -template using wkptr = std::weak_ptr; - namespace sla { // Raw byte buffer paired with its size. Suitable for compressed image data. @@ -112,7 +108,7 @@ struct PPMRasterEncoder { std::ostream& operator<<(std::ostream &stream, const EncodedRaster &bytes); // If gamma is zero, thresholding will be performed which disables AA. -uqptr create_raster_grayscale_aa( +std::unique_ptr create_raster_grayscale_aa( const RasterBase::Resolution &res, const RasterBase::PixelDim & pxdim, double gamma = 1.0, diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index deaabbe19..833146985 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -391,7 +391,7 @@ class SLAArchive { protected: std::vector m_layers; - virtual uqptr create_raster() const = 0; + virtual std::unique_ptr create_raster() const = 0; virtual sla::RasterEncoder get_encoder() const = 0; public: