1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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
45 #ifndef CCXX_MISC_H_
46 #define CCXX_MISC_H_
47
48 #ifndef CCXX_MISSING_H_
50 #endif
51
52 #ifndef CCXX_THREAD_H_
54 #endif
55
56 #define KEYDATA_INDEX_SIZE 97
57 #define KEYDATA_PAGER_SIZE 512
58
59 #if defined(PATH_MAX)
60 #if PATH_MAX > 512
61 #define KEYDATA_PATH_SIZE 512
62 #else
63 #define KEYDATA_PATH_SIZE PATH_MAX
64 #endif
65 #else
66 #define KEYDATA_PATH_SIZE 256
67 #endif
68
69 #ifdef CCXX_NAMESPACES
70 namespace ost {
71 #endif
72
75
92 {
93 private:
96
99
103 } *page;
104
105 protected:
115 virtual void* first(size_t size);
116
124 virtual void* alloc(size_t size);
125
135 char* first(char *str);
136
146 char* alloc(const char *str);
147
158
162 void purge(void);
163
167 void clean(void);
168
173
174 public:
182 {return pages;};
183 };
184
195 {
196 private:
201
203
204 public:
211
219 void *push(const void *object, size_t size);
220
227 void *push(const char *string);
228
234 void *pull(void);
235
239 void purge(void);
240 };
241
251 {
252 protected:
260
264 void purge(void);
265
272 void* first(size_t size);
273
280 void* alloc(size_t size);
281 };
282
284
353 {
354 public:
355 #ifdef CCXX_PACKED
356 #pragma pack(1)
357 #endif
358
362 };
363
370 };
371
375 };
376
377 #ifdef CCXX_PACKED
378 #pragma pack()
379 #endif
380
381 private:
386
388
390
397 unsigned getIndex(const char *sym);
398
399 protected:
400 Keysym* getSymbol(
const char *sym,
bool create);
401
402 public:
414 void load(const char *keypath);
415
429 void loadPrefix(const char *prefix, const char *keypath);
430
440 void loadFile(const char *filepath, const char *keys = NULL, const char *pre = NULL);
441
451
456
465
474
481
489 void unlink(void);
490
499 int getCount(const char *sym);
500
508 const char* getFirst(const char *sym);
509
517 const char* getLast(const char *sym);
518
525 bool isKey(const char *sym);
526
534 const char *getString(const char *sym, const char *def = NULL);
535
543 long getLong(const char *sym, long def = 0);
544
551 bool getBool(const char *key);
552
560 double getDouble(const char *key, double def = 0.);
561
570 unsigned getIndex(char **data, unsigned max);
571
578 unsigned getCount(void);
579
588 void setValue(const char *sym, const char *data);
589
597 const char * const* getList(const char *sym);
598
605 void clrValue(const char *sym);
606
612 {return getLast(keyword);};
613
617 static void end(void);
618
625 };
626
635 {
636 public:
643 inline void *
operator new(
size_t size,
MemPager &pager)
644 {return pager.alloc(size);};
645
652 inline void *
operator new[](
size_t size,
MemPager &pager)
653 {return pager.alloc(size);};
654
658 inline void operator delete(
void *) {};
659
663 inline void operator delete[](
void *) {};
664 };
665
675 {
676 private:
681 };
682
684
685 protected:
688
689 void clear(void);
690
691 virtual void *getMemory(size_t size) = 0;
692
693 public:
694 void *getPointer(const char *id) const;
695 void setPointer(const char *id, void *data);
696 };
697
709 {
710 private:
712
713 protected:
715 void check(void);
716
717 public:
724
734
742
748 void set(unsigned limit);
749 };
750
758 {
759 private:
763
764 protected:
767
772 virtual void ready(void) = 0;
773
774 public:
782
788 void stoping(void);
789 };
790
791 #ifdef CCXX_NAMESPACES
792 }
793 #endif
794
795 #endif
796
#define KEYDATA_INDEX_SIZE
substitute functions which may be missing in target platform libc.
static void end(void)
static member to end keydata i/o allocations.
The Mutex class is used to protect a section of code so that at any given time only a single thread c...
This class is used to associate (object) pointers with named strings.
#define KEYDATA_PATH_SIZE
This is a generic and portable string class.
__EXPORT void endKeydata(void)
static std::ifstream * cfgFile
Keydata objects are used to load and hold "configuration" data for a given application.
Synchronization and threading services.
const char * operator[](const char *keyword)
A convient notation for accessing the keydata as an associative array of keyword/value pairs through ...
A runlist is used to restrict concurrent exection to a limited set of concurrent sessions, much like a semaphore.
A container for objects that can be queued against a runlist.