Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

ustl::memlink Class Reference
[Memory Management]

Wrapper for pointer to block with size. More...

#include <ustl.h>

Inheritance diagram for ustl::memlink:

ustl::cmemlink ustl::memblock ustl::ostream ustl::string ustl::vector< T > ustl::vector< pair< K, V > > ustl::ostringstream ustl::list< T > ustl::multiset< T > ustl::set< T > ustl::map< K, V > ustl::multimap< K, V > ustl::fdostringstream List of all members.

Public Types

typedef value_type * pointer
typedef cmemlink::pointer const_pointer
typedef cmemlink::const_iterator const_iterator
typedef pointer iterator

Public Member Functions

 memlink (void)
 Initializes both links to point to NULL,0.
 memlink (void *p, size_type n)
 Initializes both links to point to p, n.
 memlink (const void *p, size_type n)
 Initializes the const link to point to p, n. Non-const link is NULL.
 memlink (const memlink &l)
 Copies information from l.
 memlink (const cmemlink &l)
 Copies information from l.
void link (const void *p, size_type n)
 Attaches the object to pointer p of size n.
void link (void *p, size_type n)
 Initializes both links to point to p, n.
void link (const cmemlink &l)
 Links to l.
void link (memlink &l)
 Links to l.
void link (const void *first, const void *last)
 Links to iterator range first - last.
void link (void *first, void *last)
 Links to iterator range first - last.
virtual void unlink (void)
 Resets all members to 0.
void copy (const cmemlink &l)
 Copies from l.
void copy (const void *p, size_type n)
 Copies begin from p, n to the linked block.
void copy (iterator offset, const void *p, size_type n)
 Copies data from p, n to the linked block starting at start.
pointer data (void)
 Returns a modifiable pointer to the block.
size_type writable_size (void) const
 Returns the size of the writable area.
const memlinkoperator= (const cmemlink &l)
 Copies information from l.
const memlinkoperator= (const memlink &l)
 Copies information from l.
void swap (memlink &l)
 Exchanges the contents with l.
iterator begin (void)
 Returns a modifiable pointer to the block.
iterator end (void)
 Returns a modifiable pointer to the end of the block.
const_iterator begin (void) const
 Returns a const pointer to the block.
const_iterator end (void) const
 Returns a const pointer to the end of the block.
void fill (iterator start, const void *p, size_type elsize, size_type elCount=1)
void insert (iterator start, size_type size)
void erase (iterator start, size_type size)
void read (istream &is)
 Reads the object from stream s.

Protected Member Functions

virtual void constructBlock (void *, size_type) const
 Override to initialize malloc'ed space, like calling constructors, for example.
virtual void destructBlock (void *, size_type) const
 Override to deinitialize malloc'ed space, like calling destructors, for example.

Detailed Description

Wrapper for pointer to block with size.

Use this class the way you would a pointer to an allocated unstructured block. The pointer and block size are available through member functions and cast operator. The begin in the block may be modified, but the block is static in size.

Warning:
This class actually contains two pointers: a const pointer and a non-const pointer. Both are the same when you have linked the object to a modifiable block. But if you have for some reason linked the object to a const block, the non-const pointer will be NULL. With proper usage, there should be no problem with this; just be aware that such a thing may happen.
Example usage:
        void* p = malloc (46721);
        memlink a, b;
        a.link (p, 46721);
        assert (a.size() == 46721));
        b = a;
        assert (b.size() == 46721));
        assert (b.begin() + 34 == a.begin + 34);
        assert (0 == memcmp (a, b, 12));
        a.fill (673, b, 42, 67);
        b.erase (87, 12);


Member Function Documentation

void ustl::memlink::erase iterator  start,
size_type  n
 

Shifts the data in the linked block from start + n to start. The contents of the uncovered bytes is undefined.

Reimplemented in ustl::memblock, ustl::ostream, ustl::string, ustl::vector< T >, and ustl::vector< pair< K, V > >.

void ustl::memlink::fill iterator  start,
const void *  p,
size_type  elSize,
size_type  elCount = 1
 

Fills the linked block with the given pattern.

  • start Offset at which to start filling the linked block
  • p Pointer to the pattern.
  • elSize Size of the pattern.
  • elCount Number of times to write the pattern. Total number of bytes written is elSize * elCount.

void ustl::memlink::insert iterator  start,
size_type  n
 

Shifts the data in the linked block from start to start + n. The contents of the uncovered bytes is undefined.

Reimplemented in ustl::memblock, and ustl::ostream.

void ustl::memlink::link const void *  p,
size_type  n
[inline]
 

Attaches the object to pointer p of size n.

If p is NULL and n is non-zero, bad_alloc is thrown and current state remains unchanged.

Reimplemented from ustl::cmemlink.

Reimplemented in ustl::vector< T >, and ustl::vector< pair< K, V > >.


The documentation for this class was generated from the following files:
Generated on Mon Jan 17 14:35:02 2005 for uSTL by 1.3.9 Doxygen Hosted on SourceForge.net