OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::UndoRedo::MutableObjectHistory< T > Class Template Reference
Inheritance diagram for Slic3r::UndoRedo::MutableObjectHistory< T >:
Collaboration diagram for Slic3r::UndoRedo::MutableObjectHistory< T >:

Public Member Functions

 ~MutableObjectHistory () override
bool is_mutable () const override
bool is_immutable () const override
size_t memsize () const override
bool try_save_timestamp (size_t active_snapshot_time, size_t current_time, uint64_t timestamp)
void save (size_t active_snapshot_time, size_t current_time, const std::string &data)
std::string load (size_t timestamp) const
size_t release_optional () override
void restore_optional () override
bool valid () override
bool empty () override
size_t release_before_timestamp (size_t timestamp) override
size_t release_after_timestamp (size_t timestamp) override
size_t release_between_timestamps (size_t timestamp_start, size_t timestamp_end) override
virtual bool is_optional () const
virtual const void * immutable_object_ptr () const

Protected Attributes

std::vector< MutableHistoryInterval > m_history

Detailed Description

template<typename T>
class Slic3r::UndoRedo::MutableObjectHistory< T >

Constructor & Destructor Documentation

◆ ~MutableObjectHistory()

template<typename T>
Slic3r::UndoRedo::MutableObjectHistory< T >::~MutableObjectHistory ( )
inlineoverride
433{}

Member Function Documentation

◆ empty()

bool Slic3r::UndoRedo::ObjectHistory< MutableHistoryInterval >::empty ( )
inlineoverridevirtualinherited

Implements Slic3r::UndoRedo::ObjectHistoryBase.

147{ return m_history.empty(); }
Definition UndoRedo.cpp:142
bool empty() override
Definition UndoRedo.cpp:147

◆ immutable_object_ptr()

virtual const void * Slic3r::UndoRedo::ObjectHistoryBase::immutable_object_ptr ( ) const
inlinevirtualinherited

Reimplemented in Slic3r::UndoRedo::ImmutableObjectHistory< T >.

108{ return nullptr; }

◆ is_immutable()

template<typename T>
bool Slic3r::UndoRedo::MutableObjectHistory< T >::is_immutable ( ) const
inlineoverridevirtual

Implements Slic3r::UndoRedo::ObjectHistoryBase.

436{ return false; }

◆ is_mutable()

template<typename T>
bool Slic3r::UndoRedo::MutableObjectHistory< T >::is_mutable ( ) const
inlineoverridevirtual

Implements Slic3r::UndoRedo::ObjectHistoryBase.

435{ return true; }

◆ is_optional()

virtual bool Slic3r::UndoRedo::ObjectHistoryBase::is_optional ( ) const
inlinevirtualinherited

Reimplemented in Slic3r::UndoRedo::ImmutableObjectHistory< T >.

106{ return false; }

◆ load()

template<typename T>
std::string Slic3r::UndoRedo::MutableObjectHistory< T >::load ( size_t timestamp) const
inline
489 {
490 assert(! m_history.empty());
492 if (it == m_history.end() || it->begin() > timestamp) {
493 //assert(it != m_history.begin());
494 if (it != m_history.begin())
495 --it;
496 }
497 //assert(timestamp >= it->begin() && timestamp < it->end());
498 return std::string(it->data(), it->data() + it->size());
499 }
Definition UndoRedo.cpp:431
std::vector< MutableHistoryInterval > m_history
Definition UndoRedo.cpp:228

References Slic3r::UndoRedo::ObjectHistory< MutableHistoryInterval >::m_history.

◆ memsize()

template<typename T>
size_t Slic3r::UndoRedo::MutableObjectHistory< T >::memsize ( ) const
inlineoverridevirtual

Implements Slic3r::UndoRedo::ObjectHistoryBase.

439 {
440 size_t memsize = sizeof(*this);
441 memsize += m_history.size() * sizeof(MutableHistoryInterval);
444 return memsize;
445 }
size_t memsize() const override
Definition UndoRedo.cpp:439

References Slic3r::UndoRedo::ObjectHistory< MutableHistoryInterval >::m_history, and memsize().

Referenced by memsize().

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

◆ release_after_timestamp()

size_t Slic3r::UndoRedo::ObjectHistory< MutableHistoryInterval >::release_after_timestamp ( size_t timestamp)
inlineoverridevirtualinherited

Implements Slic3r::UndoRedo::ObjectHistoryBase.

178 {
179 size_t mem_released = 0;
180 if (! m_history.empty()) {
181 assert(this->valid());
182 // it points to an interval which either starts with timestamp, or follows the timestamp.
183 auto it = std::lower_bound(m_history.begin(), m_history.end(), T(timestamp, timestamp));
184 if (it != m_history.begin()) {
185 auto it_prev = it;
186 -- it_prev;
187 assert(it_prev->begin() < timestamp);
188 // Trim the last interval with timestamp.
189 it_prev->trim_end(timestamp);
190 }
191 for (auto it2 = it; it2 != m_history.end(); ++ it2)
193 m_history.erase(it, m_history.end());
194 assert(this->valid());
195 }
196 return mem_released;
197 }
virtual size_t memsize() const =0

◆ release_before_timestamp()

size_t Slic3r::UndoRedo::ObjectHistory< MutableHistoryInterval >::release_before_timestamp ( size_t timestamp)
inlineoverridevirtualinherited

Implements Slic3r::UndoRedo::ObjectHistoryBase.

150 {
151 size_t mem_released = 0;
152 if (! m_history.empty()) {
153 assert(this->valid());
154 // it points to an interval which either starts with timestamp, or follows the timestamp.
155 auto it = std::lower_bound(m_history.begin(), m_history.end(), T(timestamp, timestamp));
156 // Find the first iterator with begin() < timestamp.
157 if (it == m_history.end())
158 -- it;
159 while (it != m_history.begin() && it->begin() >= timestamp)
160 -- it;
161 if (it->begin() < timestamp && it->end() > timestamp) {
162 it->trim_begin(timestamp);
163 if (it != m_history.begin())
164 -- it;
165 }
166 if (it->end() <= timestamp) {
167 auto it_end = ++ it;
168 for (it = m_history.begin(); it != it_end; ++ it)
169 mem_released += it->memsize();
170 m_history.erase(m_history.begin(), it_end);
171 }
172 assert(this->valid());
173 }
174 return mem_released;
175 }

◆ release_between_timestamps()

size_t Slic3r::UndoRedo::ObjectHistory< MutableHistoryInterval >::release_between_timestamps ( size_t timestamp_start,
size_t timestamp_end )
inlineoverridevirtualinherited

Implements Slic3r::UndoRedo::ObjectHistoryBase.

202 {
203 size_t mem_released = 0;
204 if (! m_history.empty()) {
205 assert(this->valid());
206 // Find the span of m_history intervals that are fully in (timestamp_start, timestamp_end>, thus they will be never
207 // deserialized for any snapshot in <timestamp_start, timestamp_end).
208 auto it_lo = std::upper_bound(m_history.begin(), m_history.end(), timestamp_start, [](size_t l, const auto &r) { return l < r.begin(); });
209 auto it_hi = std::upper_bound(it_lo, m_history.end(), timestamp_end, [](size_t l, const auto &r) { return l < r.end(); });
210 if (it_lo != it_hi) {
211 // There are some intervals that start inside (timestamp_start, timestamp_end), that could be released.
212 assert(it_lo->begin() > timestamp_start && it_lo->end() <= timestamp_end);
213 assert(it_hi == m_history.end() || (it_hi->begin() > it_lo->begin() && it_hi->end() > timestamp_end));
214 if (it_lo != m_history.begin() && it_hi != m_history.end()) {
215 // One may consider merging the two intervals.
216 //FIXME merge them.
217 }
218 for (auto it = it_lo; it != it_hi; ++ it)
219 mem_released += it->memsize();
220 m_history.erase(it_lo, it_hi);
221 }
222 assert(this->valid());
223 }
224 return mem_released;
225 }

◆ release_optional()

template<typename T>
size_t Slic3r::UndoRedo::MutableObjectHistory< T >::release_optional ( )
inlineoverridevirtual

Implements Slic3r::UndoRedo::ObjectHistoryBase.

502{ return 0; }

◆ restore_optional()

template<typename T>
void Slic3r::UndoRedo::MutableObjectHistory< T >::restore_optional ( )
inlineoverridevirtual

◆ save()

template<typename T>
void Slic3r::UndoRedo::MutableObjectHistory< T >::save ( size_t active_snapshot_time,
size_t current_time,
const std::string & data )
inline
468 {
469 assert(m_history.empty() || m_history.back().end() <= active_snapshot_time);
470 if (m_history.empty() || m_history.back().end() < active_snapshot_time) {
471 if (! m_history.empty() && m_history.back().matches(data))
472 // Share the previous data by reference counting.
473 m_history.emplace_back(Interval(current_time, current_time + 1), m_history.back());
474 else
475 // Allocate new data.
476 m_history.emplace_back(Interval(current_time, current_time + 1), data);
477 } else {
478 assert(! m_history.empty());
479 assert(m_history.back().end() == active_snapshot_time);
480 if (m_history.back().matches(data))
481 // Just extend the last interval using the old data.
482 m_history.back().extend_end(current_time + 1);
483 else
484 // Allocate new data time continuous with the previous data.
486 }
487 }

References Slic3r::UndoRedo::ObjectHistory< MutableHistoryInterval >::m_history.

◆ try_save_timestamp()

template<typename T>
bool Slic3r::UndoRedo::MutableObjectHistory< T >::try_save_timestamp ( size_t active_snapshot_time,
size_t current_time,
uint64_t timestamp )
inline
451 {
452 assert(m_history.empty() || m_history.back().end() <= active_snapshot_time);
453 if (! m_history.empty() && m_history.back().matches_timestamp(timestamp)) {
454 if (m_history.back().end() < active_snapshot_time)
455 // Share the previous data by reference counting.
456 m_history.emplace_back(Interval(current_time, current_time + 1), m_history.back());
457 else {
458 assert(m_history.back().end() == active_snapshot_time);
459 // Just extend the last interval using the old data.
460 m_history.back().extend_end(current_time + 1);
461 }
462 return true;
463 }
464 // The timestamp is not valid, the caller has to call this->save() with the serialized data.
465 return false;
466 }

References Slic3r::UndoRedo::ObjectHistory< MutableHistoryInterval >::m_history.

◆ valid()

template<typename T>
bool Slic3r::UndoRedo::MutableObjectHistory< T >::valid ( )
overridevirtual

Implements Slic3r::UndoRedo::ObjectHistoryBase.

537{
538 // Verify that the history intervals are sorted and do not overlap, and that the data reference counters are correct.
539 if (! m_history.empty()) {
541 assert(m_history.front().data() != nullptr);
542 ++ refcntrs[m_history.front().data()];
543 for (size_t i = 1; i < m_history.size(); ++ i) {
545 ++ refcntrs[m_history[i].data()];
546 }
547 for (const auto &hi : m_history) {
548 assert(hi.data() != nullptr);
549 assert(refcntrs[hi.data()] == hi.refcnt());
550 }
551 }
552 return true;
553}

References Slic3r::UndoRedo::ObjectHistory< MutableHistoryInterval >::m_history.

Member Data Documentation

◆ m_history


The documentation for this class was generated from the following file:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/UndoRedo.cpp