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<class T> using shptr = std::shared_ptr<T>;
template<class T> using uqptr = std::unique_ptr<T>;
template<class T> using wkptr = std::weak_ptr<T>;
This commit is contained in:
Vojtech Bubnik 2021-10-04 16:56:26 +02:00
parent b028e169c8
commit e185bf58b7
8 changed files with 38 additions and 47 deletions

View File

@ -65,7 +65,7 @@ void CSGDisplay::render_scene()
glFlush();
}
void Scene::set_print(uqptr<SLAPrint> &&print)
void Scene::set_print(std::unique_ptr<SLAPrint> &&print)
{
m_print = std::move(print);
@ -85,7 +85,7 @@ void CSGDisplay::SceneCache::clear()
primitives.clear();
}
shptr<Primitive> CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh)
std::shared_ptr<Primitive> CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh)
{
auto p = std::make_shared<Primitive>();
p->load_mesh(mesh);
@ -94,7 +94,7 @@ shptr<Primitive> CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh)
return p;
}
shptr<Primitive> CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh,
std::shared_ptr<Primitive> CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh,
OpenCSG::Operation o,
unsigned c)
{

View File

@ -17,11 +17,6 @@ class SLAPrint;
namespace GL {
// Simple shorthands for smart pointers
template<class T> using shptr = std::shared_ptr<T>;
template<class T> using uqptr = std::unique_ptr<T>;
template<class T> using wkptr = std::weak_ptr<T>;
template<class T, class A = std::allocator<T>> using vector = std::vector<T, A>;
// remove empty weak pointers from a vector
@ -61,7 +56,7 @@ public:
};
private:
vector<wkptr<Listener>> m_listeners;
vector<std::weak_ptr<Listener>> 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> listener)
void add_listener(std::shared_ptr<Listener> 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<SLAPrint> m_print;
std::unique_ptr<SLAPrint> 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<SLAPrint> &&print);
void set_print(std::unique_ptr<SLAPrint> &&print);
const SLAPrint * get_print() const { return m_print.get(); }
BoundingBoxf3 get_bounding_box() const;
void add_listener(shptr<Listener> listener)
void add_listener(std::shared_ptr<Listener> listener)
{
m_listeners.emplace_back(listener);
cleanup(m_listeners);
}
private:
vector<wkptr<Listener>> m_listeners;
vector<std::weak_ptr<Listener>> 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<Camera> m_camera;
std::shared_ptr<Camera> m_camera;
FpsCounter m_fps_counter;
public:
explicit Display(shptr<Camera> camera = nullptr)
explicit Display(std::shared_ptr<Camera> camera = nullptr)
: m_camera(camera ? camera : std::make_shared<PerspectiveCamera>())
{}
~Display() override;
shptr<const Camera> get_camera() const { return m_camera; }
shptr<Camera> get_camera() { return m_camera; }
void set_camera(shptr<Camera> cam) { m_camera = cam; }
std::shared_ptr<const Camera> get_camera() const { return m_camera; }
std::shared_ptr<Camera> get_camera() { return m_camera; }
void set_camera(std::shared_ptr<Camera> 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<shptr<Primitive>> primitives;
vector<std::shared_ptr<Primitive>> primitives;
vector<Primitive *> primitives_free;
vector<OpenCSG::Primitive *> primitives_csg;
void clear();
shptr<Primitive> add_mesh(const TriangleMesh &mesh);
shptr<Primitive> add_mesh(const TriangleMesh &mesh,
std::shared_ptr<Primitive> add_mesh(const TriangleMesh &mesh);
std::shared_ptr<Primitive> 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<Controller>,
Vec2i m_mouse_pos, m_mouse_pos_rprev, m_mouse_pos_lprev;
bool m_left_btn = false, m_right_btn = false;
shptr<Scene> m_scene;
vector<wkptr<Display>> m_displays;
std::shared_ptr<Scene> m_scene;
vector<std::weak_ptr<Display>> m_displays;
// Call a method of Camera on all the cameras of the attached displays
template<class F, class...Args>
void call_cameras(F &&f, Args&&... args) {
for (wkptr<Display> &l : m_displays)
for (std::weak_ptr<Display> &l : m_displays)
if (auto disp = l.lock()) if (auto cam = disp->get_camera())
(cam.get()->*f)(std::forward<Args>(args)...);
}
@ -460,7 +455,7 @@ class Controller : public std::enable_shared_from_this<Controller>,
public:
// Set the scene that will be controlled.
void set_scene(shptr<Scene> scene)
void set_scene(std::shared_ptr<Scene> 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<Display> disp)
void add_display(std::shared_ptr<Display> disp)
{
m_displays.emplace_back(disp);
cleanup(m_displays);

View File

@ -12,7 +12,7 @@ class CSGVolume: public Volume
class ShaderCSGDisplay: public Display {
protected:
vector<shptr<CSGVolume>> m_volumes;
vector<std::shared_ptr<CSGVolume>> m_volumes;
void add_mesh(const TriangleMesh &mesh);
public:

View File

@ -34,7 +34,7 @@ using namespace Slic3r::GL;
class Renderer {
protected:
wxGLCanvas *m_canvas;
shptr<wxGLContext> m_context;
std::shared_ptr<wxGLContext> 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<Slic3r::GL::Display> m_display;
std::shared_ptr<Slic3r::GL::Display> m_display;
public:
template<class...Args>
Canvas(Args &&...args): wxGLCanvas(std::forward<Args>(args)...) {}
shptr<Slic3r::GL::Display> get_display() const { return m_display; }
std::shared_ptr<Slic3r::GL::Display> get_display() const { return m_display; }
void set_display(shptr<Slic3r::GL::Display> d) { m_display = d; }
void set_display(std::shared_ptr<Slic3r::GL::Display> 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<Scene> m_scene; // Model
shptr<Canvas> m_canvas; // Views store
shptr<OCSGRenderer> m_ocsgdisplay; // View
shptr<ShaderCSGRenderer> m_shadercsg_display; // Another view
shptr<Controller> m_ctl; // Controller
std::shared_ptr<Scene> m_scene; // Model
std::shared_ptr<Canvas> m_canvas; // Views store
std::shared_ptr<OCSGRenderer> m_ocsgdisplay; // View
std::shared_ptr<ShaderCSGRenderer> m_shadercsg_display; // Another view
std::shared_ptr<Controller> m_ctl; // Controller
// Add a status bar with progress indication.
shptr<Slic3r::GUI::ProgressStatusBar> m_stbar;
std::shared_ptr<Slic3r::GUI::ProgressStatusBar> m_stbar;
RecorderMouseInput m_mouse;
@ -237,7 +237,7 @@ class MyFrame: public wxFrame
}
};
uqptr<SLAJob> m_ui_job;
std::unique_ptr<SLAJob> m_ui_job;
// To keep track of the running average of measured fps values.
double m_fps_avg = 0.;

View File

@ -423,7 +423,7 @@ void fill_slicerconf(ConfMap &m, const SLAPrint &print)
} // namespace
uqptr<sla::RasterBase> SL1Archive::create_raster() const
std::unique_ptr<sla::RasterBase> SL1Archive::create_raster() const
{
sla::RasterBase::Resolution res;
sla::RasterBase::PixelDim pxdim;

View File

@ -12,7 +12,7 @@ class SL1Archive: public SLAArchive {
SLAPrinterConfig m_cfg;
protected:
uqptr<sla::RasterBase> create_raster() const override;
std::unique_ptr<sla::RasterBase> create_raster() const override;
sla::RasterEncoder get_encoder() const override;
public:

View File

@ -13,10 +13,6 @@
namespace Slic3r {
template<class T> using uqptr = std::unique_ptr<T>;
template<class T> using shptr = std::shared_ptr<T>;
template<class T> using wkptr = std::weak_ptr<T>;
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<RasterBase> create_raster_grayscale_aa(
std::unique_ptr<RasterBase> create_raster_grayscale_aa(
const RasterBase::Resolution &res,
const RasterBase::PixelDim & pxdim,
double gamma = 1.0,

View File

@ -391,7 +391,7 @@ class SLAArchive {
protected:
std::vector<sla::EncodedRaster> m_layers;
virtual uqptr<sla::RasterBase> create_raster() const = 0;
virtual std::unique_ptr<sla::RasterBase> create_raster() const = 0;
virtual sla::RasterEncoder get_encoder() const = 0;
public: