30 #ifndef _UCOMMON_MEMORY_H_
31 #define _UCOMMON_MEMORY_H_
33 #ifndef _UCOMMON_CONFIG_H_
37 #ifndef _UCOMMON_PROTOCOLS_H_
41 #ifndef _UCOMMON_LINKED_H_
61 size_t pagesize, align;
64 typedef struct mempage {
99 inline unsigned getPages(
void)
109 inline unsigned getLimit(
void)
116 inline unsigned getAlloc(
void)
129 unsigned utilization(
void);
143 virtual void *_alloc(
size_t size);
169 pthread_mutex_t mutex;
178 virtual void _lock(
void);
183 virtual void _unlock(
void);
221 virtual void dealloc(
void *memory);
231 virtual void *
_alloc(
size_t size);
260 inline void set(
member *node)
267 inline const char *operator*()
const
270 inline const char *
get(void)
const
293 const char *
get(
unsigned item);
299 void add(
const char *text);
306 void add(
char **list);
320 inline const char *operator[](
unsigned item)
335 inline void operator+=(
const char *text)
343 {
add(text);
return *
this;};
371 virtual bool filter(
const char *filename);
378 bool load(
const char *path);
385 void operator=(
const char *path);
387 inline const char *operator*()
390 inline operator bool()
391 {
return dir != NULL;};
393 inline bool operator!()
394 {
return dir == NULL;};
403 {
return stringpager::get(item);};
405 inline const char *
get(
unsigned item)
406 {
return stringpager::get(item);};
416 typedef struct cpage {
422 cpage_t *first, *last, *current, *freelist;
424 unsigned long ccount;
427 virtual int _putch(
int code);
430 virtual void *
_alloc(
size_t size);
447 inline unsigned long getUsed(
void)
535 pthread_mutex_t mutex;
555 size_t inp, out, size;
562 charmem(
char *mem,
size_t size);
563 charmem(
size_t size);
569 void set(
char *mem,
size_t size);
571 void set(
size_t size);
573 inline void reset(
void)
576 inline void rewind(
void)
580 class __EXPORT chartext :
public CharacterProtocol
586 int _putch(
int code);
592 chartext(
char *buf,
size_t size);
619 keydata(
keyassoc *assoc,
char *
id,
unsigned max,
unsigned bufsize);
622 friend class keydata;
637 keyassoc(
unsigned indexing = 177,
size_t max = 0,
size_t page = 0);
648 inline unsigned getCount(
void)
656 inline void *operator()(
const char *name)
657 {
return locate(name);};
669 void *locate(
const char *name);
678 bool assign(
char *name,
void *
pointer);
686 bool create(
char *name,
void *
pointer);
694 void *
remove(
const char *name);
704 template <
class T,
unsigned I = 177,
size_t M = 0,
size_t P = 0>
717 inline unsigned getCount(
void)
718 {
return keyassoc::getCount();};
723 inline void purge(
void)
724 {keyassoc::purge();};
731 inline T *locate(
const char *name)
732 {
return static_cast<T*
>(keyassoc::locate(name));};
739 inline T *operator()(
const char *name)
740 {
return locate(name);};
750 {
return keyassoc::assign(name, pointer);};
759 {
return keyassoc::create(name, pointer);};
766 inline void remove(
char *name)
774 inline unsigned utilization(
void)
775 {
return mempager::utilization();};
783 inline unsigned getPages(
void)
784 {
return mempager::getPages();};
793 template <
typename T>
807 {mempager::purge();};
813 inline T *operator()(
void)
814 {
return new(
get(
sizeof(T))) T;};
820 inline T *operator*()
821 {
return new(
get(
sizeof(T))) T;};
829 template <
class T,
unsigned M = 177>
846 {NamedObject::purge(idx, M); mempager::purge();};
854 inline T *
get(
const char *name)
const {
855 T *node = (
static_cast<T*
>(NamedObject::map(idx, name, M)));
857 node = init<T>(
static_cast<T*
>(mempager::_alloc(
sizeof(T))));
858 node->NamedObject::add(idx, name, M);
868 bool test(
const char *name)
const
869 {
return NamedObject::map(idx, name, M) != NULL;};
877 inline T *operator[](
const char *name)
const
884 inline T *begin(
void)
const
885 {
return static_cast<T*
>(NamedObject::skip(idx, NULL, M));};
892 inline T *next(T *current)
const
893 {
return static_cast<T*
>(NamedObject::skip(idx, current, M));};
899 inline unsigned count(
void)
const
900 {
return NamedObject::count(idx, M);};
908 inline T **index(
void)
const
909 {
return NamedObject::index(idx, M);};
917 inline T **sort(
void)
const
918 {
return NamedObject::sort(NamedObject::index(idx, M));};