Public Types | Public Member Functions | List of all members
ustl::cmemlink Class Reference

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::ifstream ustl::string ustl::ostringstream ustl::ofstream

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 uint32_t written_size_type
 
typedef ptrdiff_t difference_type
 
typedef const_pointer const_iterator
 
typedef const_iterator iterator
 
typedef const cmemlinkrcself_t
 

Public Member Functions

 cmemlink (const void *p, size_type n)
 
 cmemlink (const cmemlink &l)
 
void link (const void *p, size_type n)
 Attaches the object to pointer p of size n. More...
 
void link (const cmemlink &l)
 
void link (const void *first, const void *last)
 
void relink (const void *p, size_type n)
 A fast alternative to link which can be used when relinking to the same block (i.e. when it is resized)
 
virtual void unlink (void) noexcept
 
rcself_t operator= (const cmemlink &l)
 
bool operator== (const cmemlink &l) const noexcept
 Compares to memory block pointed by l. Size is compared first.
 
void swap (cmemlink &l)
 
size_type size (void) const
 
size_type max_size (void) const
 
size_type readable_size (void) const
 
bool empty (void) const
 
const_pointer data (void) const
 
const_pointer cdata (void) const
 
iterator begin (void) const
 
iterator iat (size_type i) const
 
iterator end (void) const
 
void resize (size_type n)
 
void read (istream &)
 
void write (ostream &os) const
 Writes the object to stream os.
 
size_type stream_size (void) const noexcept
 Returns the number of bytes required to write this object to a stream.
 
void text_write (ostringstream &os) const
 Writes the object to stream os.
 
void write_file (const char *filename, int mode=0644) const
 Writes the data to file "filename".
 

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 nullptr and n is non-zero, bad_alloc is thrown and current state remains unchanged.

References relink().


The documentation for this class was generated from the following files:

Generated on Mon Sep 28 2015 17:58:50 for uSTL by Doxygen 1.8.10