UCommon
Data Structures | Public Types | Public Member Functions
ucommon::StringPager Class Reference

String pager for storing lists of NULL terminated strings. More...

#include <memory.h>

Inheritance diagram for ucommon::StringPager:
Inheritance graph
[legend]
Collaboration diagram for ucommon::StringPager:
Collaboration graph
[legend]

Data Structures

class  member
 Member of string list. More...
 

Public Types

typedef linked_pointer< StringPager::memberiterator
 Convenience typedef for iterative pointer.
 

Public Member Functions

void add (const char *text)
 Add text to list. More...
 
void add (char **list)
 Add list to list. More...
 
void assign (StringPager &source)
 Assign foreign pager to us. More...
 
const char * at (unsigned item) const
 
StringPager::memberbegin (void) const
 Get root of pager list. More...
 
void clear (void)
 Purge all members and release pager member. More...
 
unsigned count (void) const
 Get the number of items in the pager string list. More...
 
virtual bool filter (char *text, size_t size)
 Filter text in a derived class. More...
 
const char * get (unsigned item) const
 Get string item from list. More...
 
String join (const char *prefix=NULL, const char *middle=NULL, const char *suffix=NULL)
 
char ** list (void)
 Gather index list. More...
 
const char * operator * ()
 
 operator bool () const
 
 operator char ** ()
 
bool operator! () const
 
void operator+= (const char *text)
 Convenience operator to add to pager and auto-sort. More...
 
StringPageroperator<< (const char *text)
 Convenience operator to add to pager. More...
 
StringPageroperator= (char **list)
 
StringPageroperator>> (const char *text)
 
const char * operator[] (unsigned item) const
 Return specified member from pager list. More...
 
unsigned pages (void) const
 
const char * pop (void)
 Remove element from back of list. More...
 
const char * pull (void)
 Remove element from front of list. More...
 
void push (const char *text)
 Add text to front of list. More...
 
void push (char **text)
 Add text list to front of list. More...
 
void set (unsigned item, const char *string)
 Replace string item in list. More...
 
void set (char **list)
 Set list to list. More...
 
size_t size (void) const
 
void sort (void)
 Sort members.
 
unsigned split (const char *text, const char *string, unsigned flags=0)
 
unsigned split (stringex_t &expr, const char *string, unsigned flags=0)
 
 StringPager (size_t pagesize=256)
 Create a pager with a maximum page size. More...
 
 StringPager (char **list, size_t pagesize=256)
 
unsigned token (const char *text, const char *list, const char *quote=NULL, const char *end=NULL)
 Tokenize a string and add each token to the StringPager. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ucommon::memalloc
virtual void * _alloc (size_t size)
 Allocate memory from the pager heap. More...
 
page_t * pager (void)
 Acquire a new page from the heap. More...
 
void assign (memalloc &source)
 Assign foreign pager to us. More...
 
unsigned max (void) const
 Get the maximum number of pages that are permitted. More...
 
 memalloc (size_t page=0)
 Construct a memory pager. More...
 
 memalloc (const memalloc &copy)
 
unsigned pages (void) const
 Get the number of pages that have been allocated from the real heap. More...
 
void purge (void)
 Purge all allocated memory and heap pages immediately.
 
size_t size (void) const
 Get the size of a memory page. More...
 
unsigned utilization (void) const
 Determine fragmentation level of acquired heap pages. More...
 
virtual ~memalloc ()
 Destroy a memory pager. More...
 
- Protected Attributes inherited from ucommon::memalloc
unsigned limit
 

Detailed Description

String pager for storing lists of NULL terminated strings.

This is used for accumulating lists which can be destroyed all at once.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 401 of file memory.h.

Constructor & Destructor Documentation

◆ StringPager()

ucommon::StringPager::StringPager ( size_t  pagesize = 256)

Create a pager with a maximum page size.

Parameters
sizeof pager allocation pages.

Member Function Documentation

◆ add() [1/2]

void ucommon::StringPager::add ( const char *  text)

Add text to list.

Parameters
textto add.

◆ add() [2/2]

void ucommon::StringPager::add ( char **  list)

Add list to list.

This is a list of string pointers terminated with NULL.

Parameters
listof text to add.

◆ assign()

void ucommon::StringPager::assign ( StringPager source)

Assign foreign pager to us.

This relocates the heap references to our object, clears the other object.

◆ begin()

StringPager::member* ucommon::StringPager::begin ( void  ) const
inline

Get root of pager list.

This is useful for externally enumerating the list of strings.

Returns
first member of list or NULL if empty.

Definition at line 547 of file memory.h.

◆ clear()

void ucommon::StringPager::clear ( void  )

Purge all members and release pager member.

The list can then be added to again.

◆ count()

unsigned ucommon::StringPager::count ( void  ) const
inline

Get the number of items in the pager string list.

Returns
number of items stored.

Definition at line 459 of file memory.h.

◆ filter()

virtual bool ucommon::StringPager::filter ( char *  text,
size_t  size 
)
virtual

Filter text in a derived class.

The base class filter removes newlines at end of text and filters out empty strings.

Parameters
textto filter.
sizeof text buffer for transforms.
Returns
false if end of data.

Reimplemented in ucommon::DirPager.

◆ get()

const char* ucommon::StringPager::get ( unsigned  item) const

Get string item from list.

This is useful when StringPager is passed as a pointer and hence inconvenient for the [] operator.

Parameters
itemto access.
Returns
pointer to text for item, or NULL if out of range.

◆ list()

char** ucommon::StringPager::list ( void  )

Gather index list.

Returns
index.

◆ operator+=()

void ucommon::StringPager::operator+= ( const char *  text)
inline

Convenience operator to add to pager and auto-sort.

Parameters
textto add to list.

Definition at line 555 of file memory.h.

◆ operator<<()

StringPager& ucommon::StringPager::operator<< ( const char *  text)
inline

Convenience operator to add to pager.

Parameters
textto add to list.

Definition at line 563 of file memory.h.

◆ operator[]()

const char* ucommon::StringPager::operator[] ( unsigned  item) const
inline

Return specified member from pager list.

This is a convenience operator.

Parameters
itemto access.
Returns
text of item or NULL if invalid.

Definition at line 534 of file memory.h.

◆ pop()

const char* ucommon::StringPager::pop ( void  )

Remove element from back of list.

Does not release memory.

Returns
text removed.

◆ pull()

const char* ucommon::StringPager::pull ( void  )

Remove element from front of list.

Does not release memory.

Returns
text removed.

◆ push() [1/2]

void ucommon::StringPager::push ( const char *  text)

Add text to front of list.

Parameters
textto add.

◆ push() [2/2]

void ucommon::StringPager::push ( char **  text)

Add text list to front of list.

Parameters
textto add.

◆ set() [1/2]

void ucommon::StringPager::set ( unsigned  item,
const char *  string 
)

Replace string item in list.

Parameters
itemto replace.
stringto replace with.

◆ set() [2/2]

void ucommon::StringPager::set ( char **  list)

Set list to list.

This is a list of string pointers terminated with NULL.

Parameters
listof text to set.

◆ token()

unsigned ucommon::StringPager::token ( const char *  text,
const char *  list,
const char *  quote = NULL,
const char *  end = NULL 
)

Tokenize a string and add each token to the StringPager.

Parameters
textto tokenize.
listof characters to use as token separators.
quotepairs of characters for quoted text or NULL if not used.
endof line marker characters or NULL if not used.
Returns
number of tokens parsed.

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