Clean up placefile shared pointer usage with const references

This commit is contained in:
Dan Paulat 2023-08-22 21:52:11 -05:00
parent 232fafc9fa
commit 9955c4ccbe
12 changed files with 33 additions and 31 deletions

View file

@ -54,7 +54,7 @@ struct PlacefileIconInfo
class PlacefileIcons::Impl class PlacefileIcons::Impl
{ {
public: public:
explicit Impl(std::shared_ptr<GlContext> context) : explicit Impl(const std::shared_ptr<GlContext>& context) :
context_ {context}, context_ {context},
shaderProgram_ {nullptr}, shaderProgram_ {nullptr},
uMVPMatrixLocation_(GL_INVALID_INDEX), uMVPMatrixLocation_(GL_INVALID_INDEX),
@ -69,6 +69,9 @@ public:
~Impl() {} ~Impl() {}
void UpdateBuffers();
void Update(bool textureAtlasChanged);
std::shared_ptr<GlContext> context_; std::shared_ptr<GlContext> context_;
bool dirty_ {false}; bool dirty_ {false};
@ -98,12 +101,9 @@ public:
std::array<GLuint, 2> vbo_; std::array<GLuint, 2> vbo_;
GLsizei numVertices_; GLsizei numVertices_;
void UpdateBuffers();
void Update(bool textureAtlasChanged);
}; };
PlacefileIcons::PlacefileIcons(std::shared_ptr<GlContext> context) : PlacefileIcons::PlacefileIcons(const std::shared_ptr<GlContext>& context) :
DrawItem(context->gl()), p(std::make_unique<Impl>(context)) DrawItem(context->gl()), p(std::make_unique<Impl>(context))
{ {
} }

View file

@ -18,7 +18,7 @@ namespace draw
class PlacefileIcons : public DrawItem class PlacefileIcons : public DrawItem
{ {
public: public:
explicit PlacefileIcons(std::shared_ptr<GlContext> context); explicit PlacefileIcons(const std::shared_ptr<GlContext>& context);
~PlacefileIcons(); ~PlacefileIcons();
PlacefileIcons(const PlacefileIcons&) = delete; PlacefileIcons(const PlacefileIcons&) = delete;

View file

@ -28,7 +28,7 @@ static const boost::gil::rgba8_pixel_t kBlack_ {0, 0, 0, 255};
class PlacefileLines::Impl class PlacefileLines::Impl
{ {
public: public:
explicit Impl(std::shared_ptr<GlContext> context) : explicit Impl(const std::shared_ptr<GlContext>& context) :
context_ {context}, context_ {context},
shaderProgram_ {nullptr}, shaderProgram_ {nullptr},
uMVPMatrixLocation_(GL_INVALID_INDEX), uMVPMatrixLocation_(GL_INVALID_INDEX),
@ -49,7 +49,8 @@ public:
const float angle, const float angle,
const boost::gil::rgba8_pixel_t color, const boost::gil::rgba8_pixel_t color,
const GLint threshold); const GLint threshold);
void UpdateBuffers(std::shared_ptr<const gr::Placefile::LineDrawItem>); void
UpdateBuffers(const std::shared_ptr<const gr::Placefile::LineDrawItem>& di);
void Update(); void Update();
std::shared_ptr<GlContext> context_; std::shared_ptr<GlContext> context_;
@ -79,7 +80,7 @@ public:
GLsizei numVertices_; GLsizei numVertices_;
}; };
PlacefileLines::PlacefileLines(std::shared_ptr<GlContext> context) : PlacefileLines::PlacefileLines(const std::shared_ptr<GlContext>& context) :
DrawItem(context->gl()), p(std::make_unique<Impl>(context)) DrawItem(context->gl()), p(std::make_unique<Impl>(context))
{ {
} }
@ -255,7 +256,7 @@ void PlacefileLines::FinishLines()
} }
void PlacefileLines::Impl::UpdateBuffers( void PlacefileLines::Impl::UpdateBuffers(
std::shared_ptr<const gr::Placefile::LineDrawItem> di) const std::shared_ptr<const gr::Placefile::LineDrawItem>& di)
{ {
// Threshold value // Threshold value
units::length::nautical_miles<double> threshold = di->threshold_; units::length::nautical_miles<double> threshold = di->threshold_;

View file

@ -16,7 +16,7 @@ namespace draw
class PlacefileLines : public DrawItem class PlacefileLines : public DrawItem
{ {
public: public:
explicit PlacefileLines(std::shared_ptr<GlContext> context); explicit PlacefileLines(const std::shared_ptr<GlContext>& context);
~PlacefileLines(); ~PlacefileLines();
PlacefileLines(const PlacefileLines&) = delete; PlacefileLines(const PlacefileLines&) = delete;

View file

@ -42,7 +42,7 @@ typedef std::array<GLdouble, kTessVertexSize_> TessVertexArray;
class PlacefilePolygons::Impl class PlacefilePolygons::Impl
{ {
public: public:
explicit Impl(std::shared_ptr<GlContext> context) : explicit Impl(const std::shared_ptr<GlContext>& context) :
context_ {context}, context_ {context},
shaderProgram_ {nullptr}, shaderProgram_ {nullptr},
uMVPMatrixLocation_(GL_INVALID_INDEX), uMVPMatrixLocation_(GL_INVALID_INDEX),
@ -115,7 +115,8 @@ public:
GLint currentThreshold_; GLint currentThreshold_;
}; };
PlacefilePolygons::PlacefilePolygons(std::shared_ptr<GlContext> context) : PlacefilePolygons::PlacefilePolygons(
const std::shared_ptr<GlContext>& context) :
DrawItem(context->gl()), p(std::make_unique<Impl>(context)) DrawItem(context->gl()), p(std::make_unique<Impl>(context))
{ {
} }

View file

@ -18,7 +18,7 @@ namespace draw
class PlacefilePolygons : public DrawItem class PlacefilePolygons : public DrawItem
{ {
public: public:
explicit PlacefilePolygons(std::shared_ptr<GlContext> context); explicit PlacefilePolygons(const std::shared_ptr<GlContext>& context);
~PlacefilePolygons(); ~PlacefilePolygons();
PlacefilePolygons(const PlacefilePolygons&) = delete; PlacefilePolygons(const PlacefilePolygons&) = delete;

View file

@ -23,8 +23,8 @@ static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
class PlacefileText::Impl class PlacefileText::Impl
{ {
public: public:
explicit Impl(std::shared_ptr<GlContext> context, explicit Impl(const std::shared_ptr<GlContext>& context,
const std::string& placefileName) : const std::string& placefileName) :
context_ {context}, placefileName_ {placefileName} context_ {context}, placefileName_ {placefileName}
{ {
} }
@ -63,8 +63,8 @@ public:
std::vector<std::shared_ptr<const gr::Placefile::TextDrawItem>> newList_ {}; std::vector<std::shared_ptr<const gr::Placefile::TextDrawItem>> newList_ {};
}; };
PlacefileText::PlacefileText(std::shared_ptr<GlContext> context, PlacefileText::PlacefileText(const std::shared_ptr<GlContext>& context,
const std::string& placefileName) : const std::string& placefileName) :
DrawItem(context->gl()), p(std::make_unique<Impl>(context, placefileName)) DrawItem(context->gl()), p(std::make_unique<Impl>(context, placefileName))
{ {
} }

View file

@ -16,8 +16,8 @@ namespace draw
class PlacefileText : public DrawItem class PlacefileText : public DrawItem
{ {
public: public:
explicit PlacefileText(std::shared_ptr<GlContext> context, explicit PlacefileText(const std::shared_ptr<GlContext>& context,
const std::string& placefileName); const std::string& placefileName);
~PlacefileText(); ~PlacefileText();
PlacefileText(const PlacefileText&) = delete; PlacefileText(const PlacefileText&) = delete;

View file

@ -28,7 +28,7 @@ public:
std::uint64_t textureAtlasBuildCount_ {}; std::uint64_t textureAtlasBuildCount_ {};
}; };
DrawLayer::DrawLayer(std::shared_ptr<MapContext> context) : DrawLayer::DrawLayer(const std::shared_ptr<MapContext>& context) :
GenericLayer(context), p(std::make_unique<DrawLayerImpl>(context)) GenericLayer(context), p(std::make_unique<DrawLayerImpl>(context))
{ {
} }
@ -76,7 +76,7 @@ void DrawLayer::Deinitialize()
} }
} }
void DrawLayer::AddDrawItem(std::shared_ptr<gl::draw::DrawItem> drawItem) void DrawLayer::AddDrawItem(const std::shared_ptr<gl::draw::DrawItem>& drawItem)
{ {
p->drawList_.push_back(drawItem); p->drawList_.push_back(drawItem);
} }

View file

@ -15,7 +15,7 @@ class DrawLayerImpl;
class DrawLayer : public GenericLayer class DrawLayer : public GenericLayer
{ {
public: public:
explicit DrawLayer(std::shared_ptr<MapContext> context); explicit DrawLayer(const std::shared_ptr<MapContext>& context);
virtual ~DrawLayer(); virtual ~DrawLayer();
virtual void Initialize(); virtual void Initialize();
@ -23,7 +23,7 @@ public:
virtual void Deinitialize(); virtual void Deinitialize();
protected: protected:
void AddDrawItem(std::shared_ptr<gl::draw::DrawItem> drawItem); void AddDrawItem(const std::shared_ptr<gl::draw::DrawItem>& drawItem);
private: private:
std::unique_ptr<DrawLayerImpl> p; std::unique_ptr<DrawLayerImpl> p;

View file

@ -22,9 +22,9 @@ static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
class PlacefileLayer::Impl class PlacefileLayer::Impl
{ {
public: public:
explicit Impl(PlacefileLayer* self, explicit Impl(PlacefileLayer* self,
std::shared_ptr<MapContext> context, const std::shared_ptr<MapContext>& context,
const std::string& placefileName) : const std::string& placefileName) :
self_ {self}, self_ {self},
placefileName_ {placefileName}, placefileName_ {placefileName},
placefileIcons_ {std::make_shared<gl::draw::PlacefileIcons>(context)}, placefileIcons_ {std::make_shared<gl::draw::PlacefileIcons>(context)},
@ -53,8 +53,8 @@ public:
std::shared_ptr<gl::draw::PlacefileText> placefileText_; std::shared_ptr<gl::draw::PlacefileText> placefileText_;
}; };
PlacefileLayer::PlacefileLayer(std::shared_ptr<MapContext> context, PlacefileLayer::PlacefileLayer(const std::shared_ptr<MapContext>& context,
const std::string& placefileName) : const std::string& placefileName) :
DrawLayer(context), DrawLayer(context),
p(std::make_unique<PlacefileLayer::Impl>(this, context, placefileName)) p(std::make_unique<PlacefileLayer::Impl>(this, context, placefileName))
{ {

View file

@ -16,8 +16,8 @@ class PlacefileLayer : public DrawLayer
Q_OBJECT Q_OBJECT
public: public:
explicit PlacefileLayer(std::shared_ptr<MapContext> context, explicit PlacefileLayer(const std::shared_ptr<MapContext>& context,
const std::string& placefileName); const std::string& placefileName);
~PlacefileLayer(); ~PlacefileLayer();
std::string placefile_name() const; std::string placefile_name() const;