The Vish Visualization Shell 0.3
Vish
Classes | Public Member Functions | Protected Member Functions | List of all members
MemCore::Chunk< T > Class Template Reference

A class which handles a chunk of memory. More...

#include <elementary/memcore/Chunk.hpp>

Inheritance diagram for MemCore::Chunk< T >:
MemCore::TypedChunk< T > MemCore::ResizableChunk< T >

Classes

struct  Filler
 

Public Member Functions

const base_vector_type & base_vector () const override
 Implement virtual base class function to yield constant vector of base elements. Internally uses ugly reinterpret_cast<> of STL vectors.
 
base_vector_type & base_vector () override
 Implement virtual base class function to yield vector of base elements. Internally uses ugly reinterpret_cast<> of STL vectors.
 
 Chunk (const Filler &, const T &FillValue, size_t N=1)
 Constructor allocates a chunk of data.
 
 Chunk (const std::string &buffer)
 Construct a chunk of data from a character set.
 
 Chunk (const std::vector< T > &SourceValues)
 Copy values.
 
 Chunk (size_t N, bool ReserveOnly=false)
 Constructor allocates a chunk of data.
 
T * operator() ()
 Use function call operator to get the actual data pointer Note that this function returns 0 if the data type is not addressible via a pointer, for instance a boolean.
 
- Public Member Functions inherited from MemCore::TypedChunk< T >
std::vector< T > & get_vector ()
 Get a STL vector of element types, it can be modified.
 
const std::vector< T > & get_vector () const
 Get a const STL vector of element types, only for read access.
 

Protected Member Functions

 ~Chunk ()
 Destructor deletes the data pointer.
 

Detailed Description

template<class T>
class MemCore::Chunk< T >

A class which handles a chunk of memory.

It keeps initially allocated memory alive as long as the Chunk object lives, employing the STL vector<> class.

Basically, the Chunk class is a MemCore API to std::vector's with reference pointers, and an induced hierarchy. Induced hierarchy means that if an class B is derived from class A, then also a TypedChunk< B > will be derived from TypedChunk< A >. A TypedChunk<> is the base class of Chunk<> and provides all operator access to the data, which is actually stored in a Chunk<>.

For the hierarchy induction to work, a type trait BaseClass<> must exist for the given type. This is as simple as in this following code segment:

struct A
{
int i;
};
struct B : A
{
};
template <>
struct BaseClass<B>
{
typedef A result;
};
Definition RefPtrPerformance.cpp:24

In this case, the class hierarchy will be:

Base class for chunks of managed memory (any type possible).
Definition elementary/memcore/Chunk.hpp:31
A class which handles a chunk of memory.
Definition elementary/memcore/Chunk.hpp:319
The abstract base class for chunks that have a certain type.
Definition elementary/memcore/Chunk.hpp:98
Class of chunks of a specific type, recursively derived from chunks on base classes of the given type...
Definition elementary/memcore/Chunk.hpp:209

A any element of this hierarchy can be converted into each other via assignment to a RefPtr<> of another element. For each typed chunk, a std::vector<> can be retrieved. Here, the Chunk can be accessed as an std::vector<B> as well as an std::vector<A> .


Class Documentation

◆ MemCore::Chunk::Filler

struct MemCore::Chunk::Filler
template<class T>
struct MemCore::Chunk< T >::Filler

Constructor & Destructor Documentation

◆ Chunk() [1/2]

template<class T >
MemCore::Chunk< T >::Chunk ( size_t  N,
bool  ReserveOnly = false 
)
inline

Constructor allocates a chunk of data.

Parameters
NAllocate that many objects.
ReserveOnlyReserve that many objects to be appended later.

◆ Chunk() [2/2]

template<class T >
MemCore::Chunk< T >::Chunk ( const Filler ,
const T &  FillValue,
size_t  N = 1 
)
inline

Constructor allocates a chunk of data.

Parameters
NAllocate that many objects.
FillValueThe default value of each element.