UCommon
memory.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 Cherokees of Idaho.
3 //
4 // This file is part of GNU uCommon C++.
5 //
6 // GNU uCommon C++ is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published
8 // by the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // GNU uCommon C++ is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
18 
31 #ifndef _UCOMMON_MEMORY_H_
32 #define _UCOMMON_MEMORY_H_
33 
34 #ifndef _UCOMMON_CONFIG_H_
35 #include <ucommon/platform.h>
36 #endif
37 
38 #ifndef _UCOMMON_PROTOCOLS_H_
39 #include <ucommon/protocols.h>
40 #endif
41 
42 #ifndef _UCOMMON_LINKED_H_
43 #include <ucommon/linked.h>
44 #endif
45 
46 #ifndef _UCOMMON_STRING_H_
47 #include <ucommon/string.h>
48 #endif
49 
50 namespace ucommon {
51 
52 class PagerPool;
53 
61 class __EXPORT memalloc : public MemoryProtocol
62 {
63 private:
64  friend class bufpager;
65 
66  // disabled...
67  inline memalloc(const memalloc& copy) {};
68 
69  size_t pagesize, align;
70  unsigned count;
71 
72  typedef struct mempage {
73  struct mempage *next;
74  union {
75  void *memalign;
76  unsigned used;
77  };
78  } page_t;
79 
80  page_t *page;
81 
82 protected:
83  unsigned limit;
84 
89  page_t *pager(void);
90 
94  virtual void fault(void) const;
95 
96 public:
101  memalloc(size_t page = 0);
102 
106  virtual ~memalloc();
107 
112  inline unsigned pages(void) const
113  {return count;}
114 
122  inline unsigned max(void) const
123  {return limit;}
124 
129  inline unsigned size(void) const
130  {return (unsigned)pagesize;}
131 
142  unsigned utilization(void) const;
143 
147  void purge(void);
148 
149 protected:
157  virtual void *_alloc(size_t size);
158 
159 public:
164  void assign(memalloc& source);
165 
166  inline memalloc& operator=(memalloc& source) {
167  assign(source);
168  return *this;
169  }
170 };
171 
192 class __EXPORT mempager : public memalloc, public LockingProtocol
193 {
194 private:
195  mutable pthread_mutex_t mutex;
196 
197  inline mempager(const mempager& copy) {};
198 
199 protected:
206  virtual void _lock(void);
207 
211  virtual void _unlock(void);
212 
213 public:
218  mempager(size_t page = 0);
219 
223  virtual ~mempager();
224 
235  unsigned utilization(void);
236 
240  void purge(void);
241 
249  virtual void dealloc(void *memory);
250 
251 protected:
260  virtual void *_alloc(size_t size);
261 
262 public:
267  void assign(mempager& source);
268 
269  inline mempager& operator=(mempager& source) {
270  assign(source);
271  return *this;
272  }
273 };
274 
275 class __EXPORT ObjectPager : protected memalloc
276 {
277 public:
278  class __EXPORT member : public LinkedObject
279  {
280  private:
281  void *mem;
282 
283  protected:
284  friend class ObjectPager;
285 
286  inline void set(member *node)
287  {Next = node;}
288 
289  inline void *get(void) const
290  {return mem;}
291 
292  member(LinkedObject **root);
293  member();
294 
295  public:
296  inline void *operator*() const
297  {return mem;}
298  };
299 
300 private:
301  unsigned members;
302  LinkedObject *root;
303  size_t typesize;
304  member *last;
305  void **index;
306 
307  inline ObjectPager(const ObjectPager& ref) {};
308 
309 protected:
310  ObjectPager(size_t objsize, size_t pagesize = 256);
311 
318  void *get(unsigned item) const;
319 
324  void *add(void);
325 
326  void *push(void);
327 
332  void *pull(void);
333 
338  void *pop(void);
339 
344  void *invalid(void) const;
345 
346 public:
351  void clear(void);
352 
358  inline ObjectPager::member *begin(void)
359  {return static_cast<ObjectPager::member *>(root);}
360 
361  inline operator bool() const
362  {return members > 0;}
363 
364  inline bool operator!() const
365  {return !members;}
366 
371  inline unsigned count(void) const
372  {return members;}
373 
377  typedef linked_pointer<ObjectPager::member> iterator;
378 
379  inline size_t size(void)
380  {return memalloc::size();}
381 
382  inline unsigned pages(void)
383  {return memalloc::pages();}
384 
385 protected:
390  void **list(void);
391 
392 public:
397  void assign(ObjectPager& source);
398 
399  inline ObjectPager& operator=(ObjectPager& source) {
400  assign(source);
401  return *this;
402  }
403 };
404 
410 class __EXPORT StringPager : protected memalloc
411 {
412 private:
413  unsigned members;
414  LinkedObject *root;
415 
416  inline StringPager(const StringPager& copy) {};
417 
418 protected:
419  virtual const char *invalid(void) const;
420 
421 public:
429  virtual bool filter(char *text, size_t size);
430 
437  class __EXPORT member : public LinkedObject
438  {
439  private:
440  const char *text;
441 
442  protected:
443  friend class StringPager;
444 
445  inline void set(member *node)
446  {Next = node;}
447 
448  member(LinkedObject **root, const char *data);
449  member(const char *data);
450 
451  public:
452  inline const char *operator*() const
453  {return text;}
454 
455  inline const char *get(void) const
456  {return text;}
457  };
458 
463  StringPager(size_t pagesize = 256);
464 
465  StringPager(char **list, size_t pagesize = 256);
466 
471  inline unsigned count(void) const
472  {return members;}
473 
480  const char *get(unsigned item) const;
481 
487  void set(unsigned item, const char *string);
488 
493  void add(const char *text);
494 
499  void push(const char *text);
500 
505  void push(char **text);
506 
511  const char *pull(void);
512 
517  const char *pop(void);
518 
524  void add(char **list);
525 
531  void set(char **list);
532 
537  void clear(void);
538 
545  inline const char *operator[](unsigned item) const
546  {return get(item);}
547 
548  inline const char *at(unsigned item) const
549  {return get(item);}
550 
556  inline StringPager::member *begin(void) const
557  {return static_cast<StringPager::member *>(root);}
558 
563  inline void operator+=(const char *text)
564  {add(text);}
565 
570  inline StringPager& operator<<(const char *text)
571  {add(text); return *this;}
572 
573  inline StringPager& operator>>(const char *text)
574  {push(text); return *this;}
575 
579  void sort(void);
580 
585  char **list(void);
586 
595  unsigned token(const char *text, const char *list, const char *quote = NULL, const char *end = NULL);
596 
597  unsigned split(const char *text, const char *string, unsigned flags = 0);
598 
599  unsigned split(stringex_t& expr, const char *string, unsigned flags = 0);
600 
601  String join(const char *prefix = NULL, const char *middle = NULL, const char *suffix = NULL);
602 
603  inline operator bool()
604  {return members > 0;}
605 
606  inline bool operator!()
607  {return !members;}
608 
609  inline StringPager& operator=(char **list)
610  {set(list); return *this;}
611 
612  inline const char *operator*()
613  {return pull();}
614 
615  inline operator char **()
616  {return list();}
617 
622 
623  inline size_t size(void) const
624  {return memalloc::size();}
625 
626  inline unsigned pages(void) const
627  {return memalloc::pages();}
628 
629 private:
630  member *last;
631  char **index;
632 
633 public:
638  void assign(StringPager& source);
639 
640  inline StringPager& operator=(StringPager& source) {
641  assign(source);
642  return *this;
643  }
644 };
645 
653 class __EXPORT DirPager : protected StringPager
654 {
655 private:
656  DirPager(const DirPager& copy) {};
657 
658 protected:
659  const char *dir;
660 
668  virtual bool filter(char *filename, size_t size);
669 
675  bool load(const char *path);
676 
677 public:
678  DirPager();
679 
680  DirPager(const char *path);
681 
682  void operator=(const char *path);
683 
684  inline const char *operator*() const
685  {return dir;}
686 
687  inline operator bool() const
688  {return dir != NULL;}
689 
690  inline bool operator!() const
691  {return dir == NULL;}
692 
693  inline unsigned count(void) const
694  {return StringPager::count();}
695 
702  inline const char *operator[](unsigned item) const
703  {return StringPager::get(item);}
704 
705  inline const char *get(unsigned item) const
706  {return StringPager::get(item);}
707 
708  inline const char *at(unsigned item) const
709  {return StringPager::get(item);}
710 
711  inline size_t size(void) const
712  {return memalloc::size();}
713 
714  inline unsigned pages(void) const
715  {return memalloc::pages();}
716 
717 public:
722  void assign(DirPager& source);
723 
724  inline DirPager& operator=(DirPager& source) {
725  assign(source);
726  return *this;
727  }
728 };
729 
734 class __EXPORT bufpager : public memalloc, public CharacterProtocol
735 {
736 private:
737  typedef struct cpage {
738  struct cpage *next;
739  char *text;
740  unsigned size, used;
741  } cpage_t;
742 
743  cpage_t *first, *last, *current, *freelist;
744  unsigned cpos;
745  unsigned long ccount;
746  bool eom; /* null written or out of memory */
747 
748  virtual int _getch(void);
749  virtual int _putch(int code);
750 
751 protected:
752  virtual void *_alloc(size_t size);
753 
754 public:
758  void reset(void);
759 
763  void rewind(void);
764 
769  char *dup(void);
770 
775  void set(const char *text);
776 
781  void add(const char *text);
782 
789  size_t get(char *text, size_t size);
790 
796  void put(const char *text, size_t size);
797 
802  inline unsigned long used(void) const
803  {return ccount;}
804 
809  inline char *operator *()
810  {return dup();}
811 
816  inline bufpager& operator<<(const char *text)
817  {add(text); return *this;}
818 
819  bufpager(size_t page = 0);
820 
826  char *request(size_t *iosize);
827 
834  char *copy(size_t *iosize);
835 
840  void update(size_t size);
841 
846  inline bool operator!() const
847  {return eom;}
848 
853  inline operator bool() const
854  {return !eom;}
855 
860  void assign(bufpager& source);
861 
862  inline bufpager& operator=(bufpager& source) {
863  assign(source);
864  return *this;
865  }
866 };
867 
875 class __EXPORT autorelease
876 {
877 private:
878  LinkedObject *pool;
879 
880 public:
884  autorelease();
885 
889  ~autorelease();
890 
896  void release(void);
897 
902  void operator+=(LinkedObject *object);
903 };
904 
915 class __EXPORT PagerObject : public LinkedObject, public CountedObject
916 {
917 protected:
918  friend class PagerPool;
919 
920  PagerPool *pager;
921 
925  PagerObject();
926 
930  void reset(void);
931 
935  void release(void);
936 
940  void dealloc(void);
941 };
942 
951 class __EXPORT PagerPool : public MemoryProtocol
952 {
953 private:
954  LinkedObject *freelist;
955  mutable pthread_mutex_t mutex;
956 
957 protected:
958  PagerPool();
959  virtual ~PagerPool();
960 
961  PagerObject *get(size_t size);
962 
963 public:
968  void put(PagerObject *object);
969 };
970 
971 class __EXPORT charmem : public CharacterProtocol
972 {
973 protected:
974  char *buffer;
975  size_t inp, out, size;
976  bool dynamic;
977 
978  int _getch(void);
979  int _putch(int code);
980 
981 public:
982  charmem(char *mem, size_t size);
983  charmem(size_t size);
984  charmem();
985  virtual ~charmem();
986 
987  void release(void);
988 
989  void set(char *mem, size_t size);
990 
991  void set(size_t size);
992 
993  inline void reset(void)
994  {inp = out = 0;}
995 
996  inline void rewind(void)
997  {inp = 0;}
998 };
999 
1000 class __EXPORT chartext : public CharacterProtocol
1001 {
1002 private:
1003  char *pos;
1004  size_t max;
1005 
1006  int _putch(int code);
1007  int _getch(void);
1008 
1009 public:
1010  chartext();
1011  chartext(char *buf);
1012  chartext(char *buf, size_t size);
1013  virtual ~chartext();
1014 };
1015 
1027 class __EXPORT keyassoc : protected mempager
1028 {
1029 private:
1033  class __LOCAL keydata : public NamedObject
1034  {
1035  public:
1036  void *data;
1037  char text[8];
1038 
1039  keydata(keyassoc *assoc, const char *id, unsigned max, unsigned bufsize);
1040  };
1041 
1042  friend class keydata;
1043 
1044  unsigned keycount;
1045  unsigned paths;
1046  size_t keysize;
1047  NamedObject **root;
1048  LinkedObject **list;
1049 
1050 protected:
1057  void *allocate(const char *name, size_t size);
1058 
1059 public:
1066  keyassoc(unsigned indexing = 177, size_t max = 0, size_t page = 0);
1067 
1071  ~keyassoc();
1072 
1077  inline unsigned count(void) const
1078  {return keycount;}
1079 
1085  inline void *operator()(const char *name)
1086  {return locate(name);}
1087 
1091  void purge(void);
1092 
1098  void *locate(const char *name);
1099 
1107  bool assign(const char *name, void *pointer);
1108 
1115  bool create(const char *name, void *pointer);
1116 
1123  void *remove(const char *name);
1124 };
1125 
1126 template <class T, size_t P = 0>
1127 class listof : private ObjectPager
1128 {
1129 public:
1130  inline listof() : ObjectPager(sizeof(T), P) {}
1131 
1132  inline T& operator[](unsigned item) const
1133  {return (T&)ObjectPager::get(item);}
1134 
1135  inline T* operator()(unsigned item) const
1136  {return (T*)ObjectPager::get(item);}
1137 
1138  inline const T& at(unsigned item) const
1139  {return (const T&)ObjectPager::get(item);}
1140 
1141  inline T* pull(void)
1142  {return (T*)ObjectPager::pull();}
1143 
1144  inline T* pop(void)
1145  {return (T*)ObjectPager::pop();}
1146 
1147  inline operator T**()
1148  {return (T**)ObjectPager::list();}
1149 
1150  inline T** list(void)
1151  {return (T**)ObjectPager::list();}
1152 
1153  inline T* operator++(void)
1154  {T* tmp = ObjectPager::add(); if(tmp) new((caddr_t)tmp) T; return tmp;}
1155 
1156  inline T* add(const T& object)
1157  {T* tmp = ObjectPager::add(); if(tmp) new((caddr_t)tmp) T(object); return tmp;}
1158 
1159  inline T* push(const T& object)
1160  {T* tmp = ObjectPager::push(); if(tmp) new((caddr_t)tmp) T(object); return tmp;}
1161 
1162  inline listof& operator<<(const T& object)
1163  {T* tmp = ObjectPager::add(); if(tmp) new((caddr_t)tmp) T(object); return *this;}
1164 
1165  inline listof& operator>>(const T& object)
1166  {T* tmp = ObjectPager::push(); if(tmp) new((caddr_t)tmp) T(object); return *this;}
1167 
1168 };
1169 
1170 template <class T, unsigned I = 177, size_t M = 0, size_t P = 0>
1171 class mapof : private keyassoc
1172 {
1173 public:
1177  inline mapof() : keyassoc(I, M, P) {}
1178 
1183  inline unsigned count(void) const
1184  {return keyassoc::count();}
1185 
1189  inline void purge(void)
1190  {keyassoc::purge();}
1191 
1197  inline T *locate(const char *name)
1198  {return static_cast<T*>(keyassoc::locate(name));}
1199 
1200  inline T *operator[](const char *name)
1201  {return static_cast<T*>(keyassoc::locate(name));}
1202 
1208  inline T *operator()(const char *name)
1209  {return locate(name);}
1210 
1215  inline T *map(const char *name)
1216  {T *tmp = keyassoc::allocate(name, sizeof(T)); if(tmp) new((caddr_t)tmp) T;}
1217 
1223  inline void unmap(const char *name)
1224  {keyassoc::remove(name);}
1225 
1231  inline unsigned utilization(void) const
1232  {return mempager::utilization();}
1233 
1240  inline unsigned pages(void) const
1241  {return mempager::pages();}
1242 };
1243 
1251 template <class T, unsigned I = 177, size_t M = 0, size_t P = 0>
1252 class assoc_pointer : private keyassoc
1253 {
1254 public:
1258  inline assoc_pointer() : keyassoc(I, M, P) {}
1259 
1264  inline unsigned count(void) const
1265  {return keyassoc::count();}
1266 
1270  inline void purge(void)
1271  {keyassoc::purge();}
1272 
1278  inline T *locate(const char *name)
1279  {return static_cast<T*>(keyassoc::locate(name));}
1280 
1281  inline T *operator[](const char *name)
1282  {return static_cast<T*>(keyassoc::locate(name));}
1283 
1284 
1290  inline T *operator()(const char *name)
1291  {return locate(name);}
1292 
1300  inline bool assign(char *name, T *pointer)
1301  {return keyassoc::assign(name, pointer);}
1302 
1309  inline bool create(char *name, T *pointer)
1310  {return keyassoc::create(name, pointer);}
1311 
1317  inline void remove(char *name)
1318  {keyassoc::remove(name);}
1319 
1325  inline unsigned utilization(void) const
1326  {return mempager::utilization();}
1327 
1334  inline unsigned pages(void) const
1335  {return mempager::pages();}
1336 };
1337 
1344 template <typename T>
1345 class pager : private MemoryRedirect, private PagerPool
1346 {
1347 public:
1352  inline pager(mempager *heap = NULL) : MemoryRedirect(heap), PagerPool() {}
1353 
1358  inline T *operator()(void)
1359  {return new(get(sizeof(T))) T;}
1360 
1365  inline T *operator*()
1366  {return new(get(sizeof(T))) T;}
1367 };
1368 
1374 template <class T, unsigned M = 177>
1375 class keypager : public mempager
1376 {
1377 private:
1378  NamedObject *idx[M];
1379 
1380 public:
1385  inline keypager(size_t size) : mempager(size) {}
1386 
1390  inline ~keypager()
1391  {NamedObject::purge(idx, M); mempager::purge();}
1392 
1399  inline T *get(const char *name) const {
1400  T *node = (static_cast<T*>(NamedObject::map(idx, name, M)));
1401  if(!node) {
1402  node = init<T>(static_cast<T*>(mempager::_alloc(sizeof(T))));
1403  node->NamedObject::add(idx, name, M);
1404  }
1405  return node;
1406  }
1407 
1413  bool test(const char *name) const
1414  {return NamedObject::map(idx, name, M) != NULL;}
1415 
1422  inline T *operator[](const char *name) const
1423  {return get(name);}
1424 
1429  inline T *begin(void) const
1430  {return static_cast<T*>(NamedObject::skip(idx, NULL, M));}
1431 
1437  inline T *next(T *current) const
1438  {return static_cast<T*>(NamedObject::skip(idx, current, M));}
1439 
1444  inline unsigned count(void) const
1445  {return NamedObject::count(idx, M);}
1446 
1453  inline T **index(void) const
1454  {return NamedObject::index(idx, M);}
1455 
1462  inline T **sort(void) const
1463  {return NamedObject::sort(NamedObject::index(idx, M));}
1464 
1469 };
1470 
1475 
1480 
1485 
1486 inline const char *shift(stringlist_t& list)
1487  {return list.pull();}
1488 
1489 inline void unshift(stringlist_t& list, const char *text)
1490  {list.push(text);}
1491 
1492 
1493 inline String str(StringPager& list, const char *prefix = NULL, const char *middle = NULL, const char *suffix = NULL)
1494  {return list.join(prefix, middle, suffix);}
1495 
1496 } // namespace ucommon
1497 
1498 #endif
unsigned utilization(void) const
Access to pager utilization stats.
Definition: memory.h:1325
A common string class and character string support functions.
T * next(T *current) const
Find next typed object in hash map for iteration.
Definition: memory.h:1437
void release(SharedAccess &object)
Convenience function to unlock shared object through it's protocol.
Definition: access.h:280
static void purge(NamedObject **hash, unsigned size)
Purge a hash indexed table of named objects.
const char * operator[](unsigned item) const
Return specified member from pager list.
Definition: memory.h:545
Common locking protocol.
Definition: protocols.h:122
const char * operator[](unsigned item) const
Return specified filename from directory list.
Definition: memory.h:702
void * remove(const char *name)
Remove a name and pointer association.
StringPager stringlist_t
A convenience type for paged string lists.
Definition: memory.h:1474
A base class for reference counted objects.
Definition: object.h:56
assoc_pointer()
Construct an associated pointer hash map based on the class template.
Definition: memory.h:1258
unsigned long used(void) const
Get total size.
Definition: memory.h:802
Various miscellaneous platform specific headers and defines.
bool assign(char *name, T *pointer)
Assign a name for a pointer to a typed object.
Definition: memory.h:1300
bool create(const char *name, void *pointer)
Create a new name in the association table and assign it's value.
StringPager::member stringlistitem_t
A convenience type for paged string list items.
Definition: memory.h:1479
bufpager & operator<<(const char *text)
Convenience operator to add to pager.
Definition: memory.h:816
unsigned pages(void) const
Get the number of pages that have been allocated from the real heap.
Definition: memory.h:112
bool create(char *name, T *pointer)
Create a new name in the association table and assign typed object.
Definition: memory.h:1309
T * locate(const char *name)
Lookup a typed object by name.
Definition: memory.h:1278
A managed private heap for small allocations.
Definition: memory.h:192
A class to hold memory pointers referenced by string names.
Definition: memory.h:1027
Convenience class for directories.
Definition: fsys.h:748
unsigned count(void) const
Count the number of typed objects in our hash map.
Definition: memory.h:1444
Common base class for all objects that can be formed into a linked list.
Definition: linked.h:59
void purge(void)
Purge all associations and return allocated pages to heap.
const char * pull(void)
Remove element from front of list.
ObjectProtocol * copy(ObjectProtocol *object)
Convenience function to access object copy.
Definition: object.h:510
unsigned pages(void) const
Access to number of pages allocated from heap for our associated index pointer.
Definition: memory.h:1334
T * begin(void) const
Find first typed object in hash map to iterate.
Definition: memory.h:1429
Buffered pager for storing paged strings for character protocol.
Definition: memory.h:734
Linked objects, lists, templates, and containers.
A typed template for using a key association with typed objects.
Definition: memory.h:1252
This is a base class for objects that may be created in pager pools.
Definition: memory.h:915
static NamedObject * map(NamedObject **hash, const char *name, unsigned size)
Find a named object through a hash map table.
T * dup(const T &object)
Convenience function to duplicate object pointer to heap.
Definition: generics.h:324
A redirection base class for the memory protocol.
Definition: protocols.h:104
unsigned size(void) const
Get the size of a memory page.
Definition: memory.h:129
void * locate(const char *name)
Lookup the data pointer by the string name given.
unsigned utilization(void)
Determine fragmentation level of acquired heap pages.
virtual void * _alloc(size_t size)
Allocate memory from the pager heap.
T ** sort(void) const
Convert our hash map into an alphabetically sorted linear object pointer array.
Definition: memory.h:1462
Create a linked list of auto-releasable objects.
Definition: memory.h:875
unsigned count(void) const
Get the number of items in the pager string list.
Definition: memory.h:471
Pager pool base class for managed memory pools.
Definition: memory.h:951
bool operator!() const
Check if can still save into buffer.
Definition: memory.h:846
bool assign(const char *name, void *pointer)
Assign a name to a data pointer.
unsigned max(void) const
Get the maximum number of pages that are permitted.
Definition: memory.h:122
Member of string list.
Definition: memory.h:437
Generic smart pointer class.
Definition: generics.h:54
~keypager()
Destroy the hash pager by purging the index chains and memory pools.
Definition: memory.h:1390
bool test(const char *name) const
Test if a name exists in the pool.
Definition: memory.h:1413
void purge(void)
Purge all allocated memory and heap pages immediately.
pager(mempager *heap=((void *) 0))
Construct a pager and optionally assign a private pager heap.
Definition: memory.h:1352
T &() limit(T &value, T &low, T &high)
Convenience macro to range restrict values.
Definition: generics.h:437
T * operator()(const char *name)
Reference a typed object directly by name.
Definition: memory.h:1290
Common namespace for all ucommon objects.
Definition: access.h:47
keypager(size_t size)
Create the object cache.
Definition: memory.h:1385
static unsigned count(NamedObject **hash, unsigned size)
Count the total named objects in a hash table.
Mempager managed type factory for pager pool objects.
Definition: memory.h:1345
static NamedObject ** index(NamedObject **hash, unsigned size)
Convert a hash index into a linear object pointer array.
T ** index(void) const
Convert our hash map into a linear object pointer array.
Definition: memory.h:1453
unsigned count(void) const
Get the count of typed objects stored in our hash map.
Definition: memory.h:1264
A smart pointer template for iterating linked lists.
Definition: linked.h:1348
static NamedObject ** sort(NamedObject **list, size_t count=0)
Sort an array of named objects in alphabetical order.
T * operator()(void)
Create a managed object by casting reference.
Definition: memory.h:1358
A memory protocol pager for private heap manager.
Definition: memory.h:61
String pager for storing lists of NULL terminated strings.
Definition: memory.h:410
static NamedObject * skip(NamedObject **hash, NamedObject *current, unsigned size)
Iterate through a hash map table.
void * operator()(const char *name)
Lookup the data pointer of a string by direct operation.
Definition: memory.h:1085
void * allocate(const char *name, size_t size)
Allocate object stored in pager also.
StringPager::member * begin(void) const
Get root of pager list.
Definition: memory.h:556
const char * get(unsigned item) const
Get string item from list.
linked_pointer< T > iterator
Convenience typedef for iterative pointer.
Definition: memory.h:1468
T &() max(T &o1, T &o2)
Convenience function to return max of two objects.
Definition: generics.h:414
A template class for a hash pager.
Definition: memory.h:1375
keyassoc(unsigned indexing=177, size_t max=0, size_t page=0)
Create a key associated memory pointer table.
Abstract interfaces and support.
T * operator[](const char *name) const
Find a typed object derived from NamedObject in the hash map by name.
Definition: memory.h:1422
unsigned count(void) const
Get the number of associations we have in our object.
Definition: memory.h:1077
void purge(void)
Purge the hash map of typed objects.
Definition: memory.h:1270
A linked object base class with members found by name.
Definition: linked.h:411
DirPager dirlist_t
A convenience type for using DirPager directly.
Definition: memory.h:1484
linked_pointer< StringPager::member > iterator
Convenience typedef for iterative pointer.
Definition: memory.h:621
void operator+=(const char *text)
Convenience operator to add to pager and auto-sort.
Definition: memory.h:563
StringPager & operator<<(const char *text)
Convenience operator to add to pager.
Definition: memory.h:570
Common character processing protocol.
Definition: protocols.h:175
T * operator*()
Create a managed object by pointer reference.
Definition: memory.h:1365
Directory pager is a paged string list for directory file names.
Definition: memory.h:653