Template Class ScopedBitonalBitmapLocker#

Inheritance Relationships#

Base Type#

Class Documentation#

template<typename TBitonalBitmap>
class ScopedBitonalBitmapLocker : public libCZI::BitonalBitmapLockInfo#

A helper class used to scope the lock state of a bitonal bitmap.

It is intended to be used like this:

libCZI::IBitonalBitmapData* bm = ... // assume that we have a pointer to a bitonal bitmap

// access the bitonal bitmap's pixels directly within this scope
libCZI::ScopedBitonalBitmapLocker<libCZI::IBitonalBitmapData*> lckBm{ bm };   // <- will call bm->Lock here
for (std::uint32_t y  = 0; y < bm->GetHeight(); ++y)
{
    const std::uint8_t* ptrLine = ((const std::uint8_t*)lckBm.ptrData) + y * lckBm.stride;
    // do something with the pixel data...
}
    
// when lckBm goes out of scope, bm->Unlock will be called

For convenience two typedef are provided: ScopedBitonalBitmapLockerP and ScopedBitonalBitmapLockerSP for use with the types IBitonalBitmapData* and std::shared_ptr<IBitonalBitmapData>.

typedef ScopedBitonalBitmapLocker<IBitonalBitmapData*> ScopedBitonalBitmapLockerP;
typedef ScopedBitonalBitmapLocker<std::shared_ptr<IBitonalBitmapData>> ScopedBitonalBitmapLockerSP;

So in above sample we could have used

libCZI::ScopedBitonalBitmapLockerP lckBm{ bm };

This utility is intended to help adhering to the RAII-pattern, since it makes writing exception-safe code easier - in case of an exception (within the scope of the ScopedBitonalBitmapLocker object) the bitmap’s Unlock method will be called (which is cumbersome to achieve otherwise).

Public Functions

ScopedBitonalBitmapLocker() = delete#
inline explicit ScopedBitonalBitmapLocker(const TBitonalBitmap &bitonal_bitmap_data)#

Constructor taking the object for which we provide the scope-guard.

Parameters:

bitonal_bitmap_data – The object for which we are to provide the scope-guard.

inline ScopedBitonalBitmapLocker(const ScopedBitonalBitmapLocker<TBitonalBitmap> &other)#

Copy-Constructor.

Parameters:

other – The other object.

inline ScopedBitonalBitmapLocker(ScopedBitonalBitmapLocker<TBitonalBitmap> &&other) noexcept#

Move constructor.

inline ScopedBitonalBitmapLocker<TBitonalBitmap> &operator=(ScopedBitonalBitmapLocker<TBitonalBitmap> &&other) noexcept#

Move assignment operator.

inline ScopedBitonalBitmapLocker<TBitonalBitmap> &operator=(const ScopedBitonalBitmapLocker<TBitonalBitmap> &other)#

Copy assignment operator.

Parameters:

other – The other object.

inline ~ScopedBitonalBitmapLocker()#