ToMemBase

Files CCore/inc/ToMemBase.h CCore/src/ToMemBase.cpp

ToMemBase is a Partial class, designed to be a base class for "... to memory" classes.


class ToMemBase : NoCopy
 {
   uint8 *ptr;
   ulen len;
   
  protected: 
  
   uint8 * alloc(ulen len); // one-time call
   
  public:
  
   ToMemBase();
   
   ~ToMemBase();
   
   const uint8 * getPtr() const { return ptr; }
 
   ulen getLen() const { return len; }
   
   // std move

   ToMemBase(ToMemBase &&obj) noexcept;

   ToMemBase & operator = (ToMemBase &&obj) noexcept;

   // swap/move objects

   void objSwap(ToMemBase &obj);
   
   explicit ToMemBase(ToMoveCtor<ToMemBase> obj);
 };

It has the protected method alloc(), it must be called no more than once in a derived class.

Default constructor initialize the class in the null state. Destructor releases the allocated memory.

ToMemBase is std movable. The original object is nullified during the move.

The class is swappable and movable.