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

ustl::cmemlink Class Reference
[Memory Management]

A read-only pointer to a sized block of memory. More...

#include <ustl.h>

Inheritance diagram for ustl::cmemlink:

ustl::istream ustl::memlink ustl::istringstream ustl::memblock ustl::ostream ustl::fdistringstream 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 char value_type
typedef const value_type * pointer
typedef const value_type * const_pointer
typedef value_type reference
typedef value_type const_reference
typedef size_t size_type
typedef ptrdiff_t difference_type
typedef const_pointer const_iterator
typedef const_iterator iterator

Public Member Functions

 cmemlink (void)
 Default constructor initializes to point to NULL,0.
 cmemlink (const void *p, size_type n)
 Attaches the object to pointer p of size n.
 cmemlink (const cmemlink &l)
 Copies values from l.
void link (const void *p, size_type n)
 Attaches the object to pointer p of size n.
void link (const void *first, const void *last)
 Links to iterator range first - last.
void link (const cmemlink &l)
 Links to l.
virtual void unlink (void)
 Resets all to 0.
const cmemlinkoperator= (const cmemlink &l)
 Copies values from l.
bool operator== (const cmemlink &l) const
 Compares to memory block pointed by l. Size is compared first.
void swap (cmemlink &l)
 swaps the contents with l
const_pointer cdata (void) const
 Returns the pointer to the internal data.
iterator begin (void) const
 Returns the pointer to the internal data.
iterator end (void) const
 Returns the pointer to the end of the internal data.
size_type size (void) const
 Returns the size of the block.
size_type max_size (void) const
 Returns the maximum size of the block (non-resizable, so always == size()).
size_type readable_size (void) const
 Returns the readable size of the block.
bool empty (void) const
 true if size() == 0
void resize (size_type n)
 Resizes the block as seen by users of the class (no memory allocation).
void read (istream &)
 Reads the object from stream os.
void write (ostream &os) const
 Writes the object to stream os.
size_type stream_size (void) const
 Returns the number of bytes required to write this object to a stream.
void write_file (const char *filename, int mode=0644) const
 Writes the data to file "filename".
virtual size_type elementSize (void) const
 Returns the size of the atomic element in the block, if any.
size_type elementBytes (size_type n) const

Detailed Description

A read-only pointer to a sized block of memory.

Use this class the way you would a const pointer to an allocated unstructured block. The pointer and block size are available through member functions and cast operator.

Example usage:

        void* p = malloc (46721);
        cmemlink a, b;
        a.link (p, 46721);
        assert (a.size() == 46721));
        b = a;
        assert (b.size() == 46721));
        assert (b.DataAt(34) == a.DataAt(34));
        assert (0 == memcmp (a, b, 12));


Member Function Documentation

void ustl::cmemlink::link const void *  p,
size_type  n
 

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 in ustl::memlink, ustl::istream, ustl::vector< T >, and ustl::vector< pair< K, V > >.

void ustl::cmemlink::unlink void   )  [virtual]
 

Resets all to 0.

Warning:
Do NOT override this function. It is virtual only for memlink, memblock, and the streams; there is no way to "unvirtualize" a function, hence the documentation.

Reimplemented in ustl::memblock, ustl::memlink, ustl::istream, ustl::ostream, and ustl::ostringstream.


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