OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::Lazy< T > Class Template Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Lazy.hpp>

Inheritance diagram for Slic3r::GUI::Lazy< T >:
Collaboration diagram for Slic3r::GUI::Lazy< T >:

Public Types

using Factory = std::function<T*()>

Public Member Functions

 Lazy (std::string name, int order, Factory make)
 ~Lazy () override
 Lazy (const Lazy &)=delete
Lazy & operator= (const Lazy &)=delete
T * get () const
T * ensure ()
void when_built (std::function< void(T &)> fn)
const std::string & name () const override
bool built () const override
bool pending () const override
int prebuild_order () const override
bool build_step () override

Static Protected Member Functions

static void log_null_factory (const std::string &name)

Private Member Functions

bool steps_remain () const
void step ()

Static Private Member Functions

static constexpr bool registered ()
static constexpr bool staged ()

Private Attributes

std::string m_name
int m_order
Factory m_make
T * m_object { nullptr }
std::atomic< bool > m_complete { false }
bool m_building { false }
bool m_failed { false }
std::vector< std::function< void(T &)> > m_deferred

Detailed Description

template<class T>
class Slic3r::GUI::Lazy< T >

Member Typedef Documentation

◆ Factory

template<class T>
using Slic3r::GUI::Lazy< T >::Factory = std::function<T*()>

Constructor & Destructor Documentation

◆ Lazy() [1/2]

template<class T>
Slic3r::GUI::Lazy< T >::Lazy ( std::string name,
int order,
Factory make )
inline
73 {
74 if constexpr (registered())
76 }
Definition Lazy.hpp:68
Factory m_make
Definition Lazy.hpp:167
static constexpr bool registered()
Definition Lazy.hpp:149
int m_order
Definition Lazy.hpp:166
std::string m_name
Definition Lazy.hpp:165
const std::string & name() const override
Definition Lazy.hpp:111

References m_make, m_name, m_order, name(), registered(), and Slic3r::GUI::LazyInstance< Self >::s_lazy.

Referenced by Lazy(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~Lazy()

template<class T>
Slic3r::GUI::Lazy< T >::~Lazy ( )
inlineoverride
78 {
79 if constexpr (registered())
80 if (LazyInstance<T>::s_lazy == this)
82 }

References registered(), and Slic3r::GUI::LazyInstance< Self >::s_lazy.

Here is the call graph for this function:

◆ Lazy() [2/2]

template<class T>
Slic3r::GUI::Lazy< T >::Lazy ( const Lazy< T > & )
delete

References Lazy().

Here is the call graph for this function:

Member Function Documentation

◆ build_step()

template<class T>
bool Slic3r::GUI::Lazy< T >::build_step ( )
inlineoverridevirtual

Implements Slic3r::GUI::LazyBase.

120 {
121 if (built() || m_building || m_failed)
122 return false;
123 m_building = true;
124 try {
125 if (m_object == nullptr)
126 m_object = m_make();
127 else
128 step();
129 } catch (...) {
130 m_building = false;
131 throw;
132 }
133 m_building = false;
134 if (m_object == nullptr) {
135 m_failed = true;
137 return false;
138 }
139 if (steps_remain())
140 return true;
142 for (auto& fn : m_deferred)
143 fn(*m_object);
144 m_deferred.clear();
145 return false;
146 }
static void log_null_factory(const std::string &name)
Definition Lazy.cpp:25
std::atomic< bool > m_complete
Definition Lazy.hpp:169
bool m_building
Definition Lazy.hpp:170
T * m_object
Definition Lazy.hpp:168
void step()
Definition Lazy.hpp:159
bool m_failed
Definition Lazy.hpp:171
bool steps_remain() const
Definition Lazy.hpp:152
std::vector< std::function< void(T &)> > m_deferred
Definition Lazy.hpp:172
bool built() const override
Definition Lazy.hpp:113

References built(), Slic3r::GUI::LazyBase::log_null_factory(), m_building, m_complete, m_deferred, m_failed, m_make, m_name, m_object, step(), and steps_remain().

Referenced by ensure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ built()

template<class T>
bool Slic3r::GUI::Lazy< T >::built ( ) const
inlineoverridevirtual

Implements Slic3r::GUI::LazyBase.

References m_complete.

Referenced by build_step(), ensure(), get(), pending(), and when_built().

Here is the caller graph for this function:

◆ ensure()

template<class T>
T * Slic3r::GUI::Lazy< T >::ensure ( )
inline
92 {
93 if (!built() && !m_building) {
94 OnDemandBuild build(*this);
95 do
96 build.unit();
97 while (build_step());
98 }
99 return get();
100 }
T * get() const
Definition Lazy.hpp:87
bool build_step() override
Definition Lazy.hpp:119

References build_step(), built(), get(), m_building, and Slic3r::GUI::LazyBase::OnDemandBuild::unit().

Here is the call graph for this function:

◆ get()

template<class T>
T * Slic3r::GUI::Lazy< T >::get ( ) const
inline
87{ return built() ? m_object : nullptr; }

References built(), and m_object.

Referenced by ensure(), and Slic3r::PluginPages::remove_page().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_null_factory()

void Slic3r::GUI::LazyBase::log_null_factory ( const std::string & name)
staticprotectedinherited
26{
27 BOOST_LOG_TRIVIAL(error) << "Lazy::build_step: the factory for " << name << " returned null";
28}
virtual const std::string & name() const =0

References name().

Referenced by Slic3r::GUI::Lazy< T >::build_step().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ name()

template<class T>
const std::string & Slic3r::GUI::Lazy< T >::name ( ) const
inlineoverridevirtual

Implements Slic3r::GUI::LazyBase.

111{ return m_name; }

References m_name.

Referenced by Lazy().

Here is the caller graph for this function:

◆ operator=()

template<class T>
Lazy & Slic3r::GUI::Lazy< T >::operator= ( const Lazy< T > & )
delete

References Lazy().

Here is the call graph for this function:

◆ pending()

template<class T>
bool Slic3r::GUI::Lazy< T >::pending ( ) const
inlineoverridevirtual

Reimplemented from Slic3r::GUI::LazyBase.

Reimplemented in Slic3r::GUI::LazyPage< Panel >, Slic3r::GUI::LazyPage< Slic3r::GUI::CalibrationPanel >, Slic3r::GUI::LazyPage< Slic3r::GUI::MonitorPanel >, Slic3r::GUI::LazyPage< Slic3r::GUI::MultiMachinePage >, Slic3r::GUI::LazyPage< Slic3r::GUI::PrinterWebView >, Slic3r::GUI::LazyPage< Slic3r::GUI::ProjectPanel >, Slic3r::GUI::LazyPage< Slic3r::GUI::WebViewPanel >, and Slic3r::GUI::LazyPage< Slic3r::PluginPage >.

114{ return !built() && !m_failed; }

References built(), and m_failed.

Referenced by Slic3r::GUI::LazyPage< Panel >::pending().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prebuild_order()

template<class T>
int Slic3r::GUI::Lazy< T >::prebuild_order ( ) const
inlineoverridevirtual

Implements Slic3r::GUI::LazyBase.

115{ return m_order; }

References m_order.

◆ registered()

template<class T>
constexpr bool Slic3r::GUI::Lazy< T >::registered ( )
inlinestaticconstexprprivate

Referenced by Lazy(), and ~Lazy().

Here is the caller graph for this function:

◆ staged()

template<class T>
constexpr bool Slic3r::GUI::Lazy< T >::staged ( )
inlinestaticconstexprprivate

Referenced by step(), and steps_remain().

Here is the caller graph for this function:

◆ step()

template<class T>
void Slic3r::GUI::Lazy< T >::step ( )
inlineprivate
160 {
161 if constexpr (staged())
162 m_object->build_step();
163 }
static constexpr bool staged()
Definition Lazy.hpp:150

References m_object, and staged().

Referenced by build_step().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ steps_remain()

template<class T>
bool Slic3r::GUI::Lazy< T >::steps_remain ( ) const
inlineprivate
153 {
154 if constexpr (staged())
155 return !m_object->built();
156 else
157 return false;
158 }

References m_object, and staged().

Referenced by build_step().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ when_built()

template<class T>
void Slic3r::GUI::Lazy< T >::when_built ( std::function< void(T &)> fn)
inline
104 {
105 if (built())
106 fn(*m_object);
107 else
108 m_deferred.push_back(std::move(fn));
109 }

References built(), m_deferred, and m_object.

Here is the call graph for this function:

Member Data Documentation

◆ m_building

template<class T>
bool Slic3r::GUI::Lazy< T >::m_building { false }
private
170{ false };

Referenced by build_step(), and ensure().

◆ m_complete

template<class T>
std::atomic<bool> Slic3r::GUI::Lazy< T >::m_complete { false }
private
169{ false };

Referenced by build_step(), and built().

◆ m_deferred

template<class T>
std::vector<std::function<void(T&)> > Slic3r::GUI::Lazy< T >::m_deferred
private

Referenced by build_step(), and when_built().

◆ m_failed

template<class T>
bool Slic3r::GUI::Lazy< T >::m_failed { false }
private
171{ false };

Referenced by build_step(), and pending().

◆ m_make

template<class T>
Factory Slic3r::GUI::Lazy< T >::m_make
private

Referenced by Lazy(), and build_step().

◆ m_name

template<class T>
std::string Slic3r::GUI::Lazy< T >::m_name
private

Referenced by Lazy(), build_step(), and name().

◆ m_object

template<class T>
T* Slic3r::GUI::Lazy< T >::m_object { nullptr }
private
168{ nullptr };

Referenced by build_step(), get(), step(), steps_remain(), and when_built().

◆ m_order

template<class T>
int Slic3r::GUI::Lazy< T >::m_order
private

Referenced by Lazy(), and prebuild_order().


The documentation for this class was generated from the following file:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Lazy.hpp