ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
misc.h
Go to the documentation of this file.
1// Copyright (C) 2001-2005 Open Source Telecom Corporation.
2// Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
3// Copyright (C) 2015 Cherokees of Idaho.
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
17//
18// As a special exception, you may use this file as part of a free software
19// library without restriction. Specifically, if other files instantiate
20// templates or use macros or inline functions from this file, or you compile
21// this file and link it with other files to produce an executable, this
22// file does not by itself cause the resulting executable to be covered by
23// the GNU General Public License. This exception does not however
24// invalidate any other reasons why the executable file might be covered by
25// the GNU General Public License.
26//
27// This exception applies only to the code released under the name GNU
28// Common C++. If you copy code from other releases into a copy of GNU
29// Common C++, as the General Public License permits, the exception does
30// not apply to the code that you add in this way. To avoid misleading
31// anyone as to the status of such modified files, you must delete
32// this exception notice from them.
33//
34// If you write modifications of your own for GNU Common C++, it is your choice
35// whether to permit this exception to apply to your modifications.
36// If you do not wish that, delete this exception notice.
37//
38
39/**
40 * @file misc.h
41 * @short various miscellaneous classes historically used.
42 **/
43
44#ifndef COMMONCPP_MISC_H_
45#define COMMONCPP_MISC_H_
46
47#ifndef COMMONCPP_CONFIG_H_
48#include <commoncpp/config.h>
49#endif
50
51#define KEYDATA_INDEX_SIZE 97
52#define KEYDATA_PAGER_SIZE 512
53#if defined(PATH_MAX)
54#if PATH_MAX > 512
55#define KEYDATA_PATH_SIZE 512
56#else
57#define KEYDATA_PATH_SIZE PATH_MAX
58#endif
59#else
60#define KEYDATA_PATH_SIZE 256
61#endif
62
63namespace ost {
64
66{
67private:
69
70public:
71 inline MemPager(size_t pagesize = 4096) : ucommon::memalloc(pagesize) {}
72
73 inline void *alloc(size_t size) {
74 return _alloc(size);
75 }
76
77 char *alloc(const char *str);
78
79 inline char *first(const char *str) {
80 return alloc(str);
81 }
82
83 inline void *first(size_t size) {
84 return _alloc(size);
85 }
86
87 inline int getPages(void) const {
88 return pages();
89 }
90
91 inline void purge(void) {
92 memalloc::purge();
93 }
94};
95
96/**
97 * The shared mempager uses a mutex to protect key access methods.
98 * This class is used when a mempager will be shared by multiple
99 * threads.
100 *
101 * @author David Sugar <dyfet@gnutelephony.org>
102 * @short mutex protected memory pager.
103 */
104class __EXPORT SharedMemPager : public MemPager, public Mutex
105{
106private:
108
109protected:
110 /**
111 * Create a mempager mutex pool.
112 *
113 * @param pagesize page size for allocation.
114 * @param name a name for the pool.
115 */
116 SharedMemPager(size_t pagesize = 4096);
117 /**
118 * Purge the memory pool while locked.
119 */
120 void purge(void);
121
122 /**
123 * Get the last memory page after locking.
124 *
125 * @return allocated memory space.
126 * @param size of request.
127 */
128 void* alloc(size_t size);
129
130 inline void *first(size_t size) {
131 return alloc(size);
132 }
133};
134
135/**
136 * This class is used to associate (object) pointers with named strings.
137 * A virtual is used to allocate memory which can be overriden in the
138 * derived class.
139 *
140 * @author David Sugar <dyfet@ostel.com>
141 * @short associate names with pointers.
142 */
144{
145private:
146 struct entry {
147 const char *id;
149 void *data;
150 };
151
153
155
156protected:
157 Assoc();
158 virtual ~Assoc();
159
160 void clear(void);
161
162 virtual void *getMemory(size_t size) = 0;
163
164public:
165 void *getPointer(const char *id) const;
166 void setPointer(const char *id, void *data);
167};
168
169} // namespace ost
170#endif
This class is used to associate (object) pointers with named strings.
Definition: misc.h:144
virtual void * getMemory(size_t size)=0
__DELETE_COPY(Assoc)
void * alloc(size_t size)
Definition: misc.h:73
void purge(void)
Definition: misc.h:91
MemPager(size_t pagesize=4096)
Definition: misc.h:71
int getPages(void) const
Definition: misc.h:87
void * first(size_t size)
Definition: misc.h:83
__DELETE_COPY(MemPager)
char * first(const char *str)
Definition: misc.h:79
The shared mempager uses a mutex to protect key access methods.
Definition: misc.h:105
void * first(size_t size)
Definition: misc.h:130
__DELETE_COPY(SharedMemPager)
A memory protocol pager for private heap manager.
Definition: memory.h:62
#define __EXPORT
Definition: config.h:49
#define KEYDATA_INDEX_SIZE
Definition: misc.h:51
Definition: address.cpp:63
Common namespace for all ucommon objects.
Definition: access.cpp:23
T & clear(T &o)
Definition: generics.h:416
String str(Socket &so, size_t size)
Definition: socket.cpp:3507
const char * id
Definition: misc.h:147
void * data
Definition: misc.h:149
entry * next
Definition: misc.h:148