31 #ifndef _UCOMMON_MEMORY_H_ 32 #define _UCOMMON_MEMORY_H_ 34 #ifndef _UCOMMON_CONFIG_H_ 38 #ifndef _UCOMMON_PROTOCOLS_H_ 42 #ifndef _UCOMMON_LINKED_H_ 46 #ifndef _UCOMMON_STRING_H_ 61 class __EXPORT
memalloc :
public __PROTOCOL MemoryProtocol
64 friend class bufpager;
66 size_t pagesize, align;
69 typedef struct mempage {
117 inline unsigned max(
void)
const {
125 inline size_t size(
void)
const {
139 unsigned utilization(
void)
const;
154 virtual void *_alloc(
size_t size) __OVERRIDE;
187 mutable pthread_mutex_t mutex;
196 virtual void _lock(
void) __OVERRIDE;
201 virtual void _unlock(
void) __OVERRIDE;
227 unsigned utilization(
void);
241 virtual void dealloc(
void *memory);
252 virtual void *_alloc(
size_t size) __OVERRIDE;
262 class __EXPORT ObjectPager :
protected memalloc 271 friend class ObjectPager;
273 inline void set(member *node) {
277 inline void *
get(void)
const {
281 member(LinkedObject **root);
285 inline void *operator*()
const {
297 __DELETE_COPY(ObjectPager);
300 ObjectPager(
size_t objsize,
size_t pagesize = 256);
308 void *
get(
unsigned item)
const;
334 void *invalid(
void)
const;
348 inline ObjectPager::member *begin(
void) {
349 return static_cast<ObjectPager::member *
>(root);
352 inline operator bool()
const {
356 inline bool operator!()
const {
364 inline unsigned count(
void)
const {
371 typedef linked_pointer<ObjectPager::member> iterator;
373 inline size_t size(
void) {
377 inline unsigned pages(
void) {
393 void assign(ObjectPager& source);
415 virtual bool filter(
char *text,
size_t size);
431 inline void set(
member *node)
438 inline const char *operator*()
const {
442 inline const char *
get(void)
const {
469 const char *
get(
unsigned item)
const;
476 void set(
unsigned item,
const char *string);
482 void add(
const char *text);
488 void push(
const char *text);
494 void push(
char **text);
500 const char *pull(
void);
506 const char *pop(
void);
513 void add(
char **list);
520 void set(
char **list);
538 inline const char *at(
unsigned item)
const {
592 unsigned token(
const char *text,
const char *list,
const char *quote = NULL,
const char *end = NULL);
594 unsigned split(
const char *text,
const char *
string,
unsigned flags = 0);
596 unsigned split(stringex_t& expr,
const char *
string,
unsigned flags = 0);
598 String join(
const char *prefix = NULL,
const char *middle = NULL,
const char *suffix = NULL);
600 inline operator bool()
const {
604 inline bool operator!()
const {
608 inline StringPager& operator=(
char **list) {
613 inline const char *operator*() {
617 inline operator char **() {
626 inline size_t size(
void)
const {
630 inline unsigned pages(
void)
const {
643 void assign(StringPager& source);
668 virtual bool filter(
char *filename,
size_t size) __OVERRIDE;
675 bool load(
const char *path);
682 void operator=(
const char *path);
684 inline const char *operator*()
const {
688 inline operator bool()
const {
692 inline bool operator!()
const {
696 inline unsigned count(
void)
const {
710 inline const char *
get(
unsigned item)
const {
714 inline const char *at(
unsigned item)
const {
718 inline size_t size(
void)
const {
722 inline unsigned pages(
void)
const {
731 void assign(DirPager& source);
803 void retain(
void) __OVERRIDE;
808 void release(
void) __OVERRIDE;
813 void dealloc(
void) __OVERRIDE;
824 class __EXPORT
PagerPool :
public __PROTOCOL MemoryProtocol
828 mutable pthread_mutex_t mutex;
852 template <
typename T>
856 __DELETE_COPY(
pager);
870 return new(
get(
sizeof(T))) T;
878 return new(
get(
sizeof(T))) T;
897 inline String str(
StringPager& list,
const char *prefix = NULL,
const char *middle = NULL,
const char *suffix = NULL) {
898 return list.join(prefix, middle, suffix);
T &() limit(T &value, T &low, T &high)
Convenience macro to range restrict values.
Common base class for all objects that can be formed into a linked list.
unsigned pages(void) const
Get the number of pages that have been allocated from the real heap.
unsigned max(void) const
Get the maximum number of pages that are permitted.
StringPager & operator<<(const char *text)
Convenience operator to add to pager.
T copy(const T &src)
Convenience function to copy objects.
const char * operator[](unsigned item) const
Return specified member from pager list.
Mempager managed type factory for pager pool objects.
Create a linked list of auto-releasable objects.
const char * get(unsigned item) const
Get string item from list.
pager(mempager *heap=NULL)
Construct a pager and optionally assign a private pager heap.
A copy-on-write string class that operates by reference count.
String pager for storing lists of NULL terminated strings.
unsigned count(void) const
Get the number of items in the pager string list.
A managed private heap for small allocations.
linked_pointer< StringPager::member > iterator
Convenience typedef for iterative pointer.
A memory protocol pager for private heap manager.
T * operator()(void)
Create a managed object by casting reference.
Pager pool base class for managed memory pools.
Directory pager is a paged string list for directory file names.
Abstract interfaces and support.
void operator+=(const char *text)
Convenience operator to add to pager and auto-sort.
This is a base class for objects that may be created in pager pools.
A smart pointer template for iterating linked lists.
A common string class and character string support functions.
StringPager::member stringlistitem_t
A convenience type for paged string list items.
A base class for reference counted objects.
Various miscellaneous platform specific headers and defines.
DirPager dirlist_t
A convenience type for using DirPager directly.
Common namespace for all ucommon objects.
const char * operator[](unsigned item) const
Return specified filename from directory list.
Convenience class for directories.
StringPager stringlist_t
A convenience type for paged string lists.
Linked objects, lists, templates, and containers.
size_t size(void) const
Get the size of a memory page.
A redirection base class for the memory protocol.
StringPager::member * begin(void) const
Get root of pager list.
T * operator*()
Create a managed object by pointer reference.