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 {
548 return static_cast<StringPager::member *>(root);
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);
Linked objects, lists, templates, and containers.
const char * operator[](unsigned item) const
Return specified member from pager list.
Mempager managed type factory for pager pool objects.
pager(mempager *heap=NULL)
Construct a pager and optionally assign a private pager heap.
Create a linked list of auto-releasable objects.
String pager for storing lists of NULL terminated strings.
linked_pointer< StringPager::member > iterator
Convenience typedef for iterative pointer.
Pager pool base class for managed memory pools.
A copy-on-write string class that operates by reference count.
DirPager dirlist_t
A convenience type for using DirPager directly.
unsigned count(void) const
Get the number of items in the pager string list.
StringPager & operator<<(const char *text)
Convenience operator to add to pager.
A common string class and character string support functions.
unsigned pages(void) const
Get the number of pages that have been allocated from the real heap.
T &() limit(T &value, T &low, T &high)
Convenience macro to range restrict values.
StringPager::member * begin(void) const
Get root of pager list.
Convenience class for directories.
size_t size(void) const
Get the size of a memory page.
T * operator *()
Create a managed object by pointer reference.
A managed private heap for small allocations.
A memory protocol pager for private heap manager.
Various miscellaneous platform specific headers and defines.
Common namespace for all ucommon objects.
Directory pager is a paged string list for directory file names.
unsigned max(void) const
Get the maximum number of pages that are permitted.
T copy(const T &src)
Convenience function to copy objects.
Abstract interfaces and support.
StringPager stringlist_t
A convenience type for paged string lists.
T * operator()(void)
Create a managed object by casting reference.
const char * get(unsigned item) const
Get string item from list.
A redirection base class for the memory protocol.
This is a base class for objects that may be created in pager pools.
A smart pointer template for iterating linked lists.
void operator+=(const char *text)
Convenience operator to add to pager and auto-sort.
StringPager::member stringlistitem_t
A convenience type for paged string list items.
Common base class for all objects that can be formed into a linked list.
A base class for reference counted objects.
const char * operator[](unsigned item) const
Return specified filename from directory list.