Chameleon

Chameleon Commit Details

Date:2010-12-13 09:04:08 (8 years 6 months ago)
Author:Evan Lojewski
Commit:660
Parents: 659
Message:Added includes dir for modules (c++ includes only at the moment, may ad klibc includes later on). Includes path is now included for modules
Changes:
D/branches/meklort/i386/modules/uClibc++/include
A/branches/meklort/i386/modules/include/list
A/branches/meklort/i386/modules/include/support
A/branches/meklort/i386/modules/include/iterator_base
A/branches/meklort/i386/modules/include/algorithm
A/branches/meklort/i386/modules/include/cctype
A/branches/meklort/i386/modules/include/cstdarg
A/branches/meklort/i386/modules/include/bitset
A/branches/meklort/i386/modules/include/map.old
A/branches/meklort/i386/modules/include/iosfwd
A/branches/meklort/i386/modules/include/iomanip
A/branches/meklort/i386/modules/include/exception
A/branches/meklort/i386/modules/include/system_configuration.h
A/branches/meklort/i386/modules/include/limits
A/branches/meklort/i386/modules/include/functional
A/branches/meklort/i386/modules/include/numeric
A/branches/meklort/i386/modules/include/utility
A/branches/meklort/i386/modules/include/deque
A/branches/meklort/i386/modules/include/stdexcept
A/branches/meklort/i386/modules/include/associative_base
A/branches/meklort/i386/modules/include/string
A/branches/meklort/i386/modules/include/type_traits
A/branches/meklort/i386/modules/include/cfloat
A/branches/meklort/i386/modules/include/modules
A/branches/meklort/i386/modules/include/set.old
A/branches/meklort/i386/modules/include/cstddef
A/branches/meklort/i386/modules/include/basic_definitions
A/branches/meklort/i386/modules/include/map
A/branches/meklort/i386/modules/include/iostream
A/branches/meklort/i386/modules/include/queue
A/branches/meklort/i386/modules/include/cstdlib
A/branches/meklort/i386/modules/include/streambuf
A/branches/meklort/i386/modules/include/unwind-cxx.h
A/branches/meklort/i386/modules/include/set
A/branches/meklort/i386/modules/include/locale
A/branches/meklort/i386/modules/include
A/branches/meklort/i386/modules/include/ctime
A/branches/meklort/i386/modules/include/vector
A/branches/meklort/i386/modules/include/istream
A/branches/meklort/i386/modules/include/csetjmp
A/branches/meklort/i386/modules/include/complex
A/branches/meklort/i386/modules/include/klibc/endian.h
A/branches/meklort/i386/modules/include/ostream
A/branches/meklort/i386/modules/include/Makefile
A/branches/meklort/i386/modules/include/sstream
A/branches/meklort/i386/modules/include/klibc/extern.h
A/branches/meklort/i386/modules/include/csignal
A/branches/meklort/i386/modules/include/klibc
A/branches/meklort/i386/modules/include/istream_helpers
A/branches/meklort/i386/modules/include/cerrno
A/branches/meklort/i386/modules/include/iterator
A/branches/meklort/i386/modules/include/ostream_helpers
A/branches/meklort/i386/modules/include/climits
A/branches/meklort/i386/modules/include/klibc/diverr.h
A/branches/meklort/i386/modules/include/cstring
A/branches/meklort/i386/modules/include/func_exception
A/branches/meklort/i386/modules/include/cwctype
A/branches/meklort/i386/modules/include/klibc/sysconfig.h
A/branches/meklort/i386/modules/include/valarray
A/branches/meklort/i386/modules/include/klibc/compiler.h
A/branches/meklort/i386/modules/include/cstdio
A/branches/meklort/i386/modules/include/new
A/branches/meklort/i386/modules/include/ios
A/branches/meklort/i386/modules/include/cmath
A/branches/meklort/i386/modules/include/typeinfo
A/branches/meklort/i386/modules/include/klibc/stathelp.h
A/branches/meklort/i386/modules/include/fstream
A/branches/meklort/i386/modules/include/clocale
A/branches/meklort/i386/modules/include/char_traits
A/branches/meklort/i386/modules/include/cassert
A/branches/meklort/i386/modules/include/stack
A/branches/meklort/i386/modules/include/cwchar
A/branches/meklort/i386/modules/include/memory
A/branches/meklort/i386/modules/include/string_iostream
M/branches/meklort/i386/modules/MakeInc.dir
M/branches/meklort/i386/modules/HelloWorld/HelloWorld.cpp
M/branches/meklort/i386/modules/Makefile

File differences

branches/meklort/i386/modules/include/iostream
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*Copyright (C) 2004 Garrett A. Kajmowicz
This file is part of the uClibc++ Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <basic_definitions>
#ifndef __HEADER_STD_IOSTREAM
#define __HEADER_STD_IOSTREAM 1
#include <iosfwd>
#include <ios>
#include <istream>
#include <ostream>
#include <fstream>
#include <string_iostream>
#pragma GCC visibility push(default)
namespace std{
#ifdef __UCLIBCXX_SUPPORT_CIN__
extern istream cin;
#endif
#ifdef __UCLIBCXX_SUPPORT_COUT__
extern ostream cout;
#endif
#ifdef __UCLIBCXX_SUPPORT_CERR__
extern ostream cerr;
#endif
#ifdef __UCLIBCXX_SUPPORT_CLOG__
extern ostream clog;
#endif
#ifdef __UCLIBCXX_SUPPORT_WCIN__
extern wistream wcin;
#endif
#ifdef __UCLIBCXX_SUPPORT_WCOUT__
extern wostream wcout;
#endif
#ifdef __UCLIBCXX_SUPPORT_WCERR__
extern wostream wcerr;
#endif
#ifdef __UCLIBCXX_SUPPORT_WCLOG__
extern wostream wclog;
#endif
template <class charT, class traits> class _UCXXEXPORT basic_iostream :
public basic_istream<charT,traits>, public basic_ostream<charT,traits>
{
public:
// constructor/destructor
explicit _UCXXEXPORT basic_iostream(basic_streambuf<charT,traits>* sb);
virtual _UCXXEXPORT ~basic_iostream();//Below
};
template <class charT, class traits> _UCXXEXPORT
basic_iostream<charT, traits>:: basic_iostream(basic_streambuf<charT,traits>* sb)
: basic_ios<charT, traits>(sb), basic_istream<charT,traits>(sb), basic_ostream<charT,traits>(sb)
{
return;
}
template <class charT, class traits> _UCXXEXPORT basic_iostream<charT, traits>::~basic_iostream(){
return;
}
#ifdef __UCLIBCXX_EXPAND_OSTREAM_CHAR__
#ifdef __UCLIBCXX_EXPAND_ISTREAM_CHAR__
#ifndef __UCLIBCXX_COMPILE_IOSTREAM__
template <> _UCXXEXPORT basic_iostream<char, char_traits<char> >::
basic_iostream(basic_streambuf<char, char_traits<char> >* sb);
template <> _UCXXEXPORT basic_iostream<char, char_traits<char> >::~basic_iostream();
#endif
#endif
#endif
}
#pragma GCC visibility pop
#endif
branches/meklort/i386/modules/include/klibc/compiler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* klibc/compiler.h
*
* Various compiler features
*/
#ifndef _KLIBC_COMPILER_H
#define _KLIBC_COMPILER_H
/* Specific calling conventions */
/* __cdecl is used when we want varadic and non-varadic functions to have
the same binary calling convention. */
#ifdef __i386__
# ifdef __GNUC__
# define __cdecl __attribute__((cdecl,regparm(0)))
# else
/* Most other C compilers have __cdecl as a keyword */
# endif
#else
# define __cdecl/* Meaningless on non-i386 */
#endif
/* How to declare a function that *must* be inlined */
/* Use "extern inline" even in the gcc3+ case to avoid warnings in ctype.h */
#ifdef __GNUC__
# if __GNUC__ >= 3
# ifdef __GNUC_STDC_INLINE__
# define __must_inline extern __inline__ \
__attribute__((__gnu_inline__,__always_inline__))
# else
# define __must_inline extern __inline__ __attribute__((__always_inline__))
# endif
# else
# define __must_inline extern __inline__
# endif
#else
# define __must_inline inline/* Just hope this works... */
#endif
/* How to declare a function that does not return */
#ifdef __GNUC__
# define __noreturn void __attribute__((noreturn))
#else
# define __noreturn void
#endif
/* "const" function:
Many functions do not examine any values except their arguments,
and have no effects except the return value. Basically this is
just slightly more strict class than the `pure' attribute above,
since function is not allowed to read global memory.
Note that a function that has pointer arguments and examines the
data pointed to must _not_ be declared `const'. Likewise, a
function that calls a non-`const' function usually must not be
`const'. It does not make sense for a `const' function to return
`void'.
*/
#ifdef __GNUC__
# define __constfunc __attribute__((const))
#else
# define __constfunc
#endif
#undef __attribute_const__
#define __attribute_const__ __constfunc
/* "pure" function:
Many functions have no effects except the return value and their
return value depends only on the parameters and/or global
variables. Such a function can be subject to common subexpression
elimination and loop optimization just as an arithmetic operator
would be. These functions should be declared with the attribute
`pure'.
*/
#ifdef __GNUC__
# define __purefunc __attribute__((pure))
#else
# define __purefunc
#endif
#undef __attribute_pure__
#define __attribute_pure__ __purefunc
/* Format attribute */
#ifdef __GNUC__
# define __formatfunc(t,f,a) __attribute__((format(t,f,a)))
#else
# define __formatfunc(t,f,a)
#endif
/* malloc() function (returns unaliased pointer) */
#if defined(__GNUC__) && (__GNUC__ >= 3)
# define __mallocfunc __attribute__((malloc))
#else
# define __mallocfunc
#endif
/* likely/unlikely */
#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
# define __likely(x) __builtin_expect(!!(x), 1)
# define __unlikely(x) __builtin_expect(!!(x), 0)
#else
# define __likely(x) (!!(x))
# define __unlikely(x) (!!(x))
#endif
/* Possibly unused function */
#ifdef __GNUC__
# define __unusedfunc__attribute__((unused))
#else
# define __unusedfunc
#endif
/* It's all user space... */
#define __user
/* The bitwise attribute: disallow arithmetric operations */
#ifdef __CHECKER__/* sparse only */
# define __bitwise__attribute__((bitwise))
#else
# define __bitwise
#endif
/* Shut up unused warnings */
#ifdef __GNUC__
# define __attribute_used__ __attribute__((used))
#else
# define __attribute_used__
#endif
/* Compiler pragma to make an alias symbol */
#define __ALIAS(__t, __f, __p, __a) \
__t __f __p __attribute__((weak, alias(#__a)));
#endif
branches/meklort/i386/modules/include/klibc/diverr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
* klibc/diverr.h
*/
#ifndef _KLIBC_DIVERR_H
#define _KLIBC_DIVERR_H
#include <signal.h>
static __inline__ void __divide_error(void)
{
raise(SIGFPE);
}
#endif/* _KLIBC_DIVERR_H */
branches/meklort/i386/modules/include/klibc/endian.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* klibc/endian.h
*
* Like <endian.h>, but export only double-underscore symbols
*/
#ifndef _KLIBC_ENDIAN_H
#define _KLIBC_ENDIAN_H
#include <klibc/compiler.h>
#include <asm/byteorder.h>
/* Linux' asm/byteorder.h defines either __LITTLE_ENDIAN or
__BIG_ENDIAN, but the glibc/BSD-ish macros expect both to be
defined with __BYTE_ORDER defining which is actually used... */
#if defined(__LITTLE_ENDIAN)
# undef __LITTLE_ENDIAN
# define __LITTLE_ENDIAN 1234
# define __BIG_ENDIAN 4321
# define __PDP_ENDIAN 3412
# define __BYTE_ORDER __LITTLE_ENDIAN
#elif defined(__BIG_ENDIAN)
# undef __BIG_ENDIAN
# define __LITTLE_ENDIAN 1234
# define __BIG_ENDIAN 4321
# define __PDP_ENDIAN 3412
# define __BYTE_ORDER __BIG_ENDIAN
#elif defined(__PDP_ENDIAN)
# undef __PDP_ENDIAN
# define __LITTLE_ENDIAN 1234
# define __BIG_ENDIAN 4321
# define __PDP_ENDIAN 3412
# define __BYTE_ORDER __PDP_ENDIAN
#else
# error "Unknown byte order!"
#endif
#endif/* _KLIBC_ENDIAN_H */
branches/meklort/i386/modules/include/klibc/stathelp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
* stathelp.h
*
* Helper macros for <klibc/archstat.h>
*/
#ifndef _KLIBC_STATHELP_H
#define _KLIBC_STATHELP_H
#include <klibc/endian.h>
/*
* Most architectures have a 64-bit field for st_dev and st_rdev,
* but dev_t is 32 bits (uint32_t == unsigned int), so make a
* macro we can use across all architectures.
*/
#if __BYTE_ORDER == __BIG_ENDIAN
# define __stdev64(x)unsigned int __##x, x;
#else
# define __stdev64(x)unsigned int x, __##x;
#endif
#endif/* _KLIBC_STATHELP_H */
branches/meklort/i386/modules/include/klibc/sysconfig.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
* klibc/sysconfig.h
*
* Allows for definitions of some things which may be system-dependent
* NOTE: this file must not result in any output from the preprocessor.
*/
#ifndef _KLIBC_SYSCONFIG_H
#define _KLIBC_SYSCONFIG_H
#include <klibc/archconfig.h>
#include <asm/unistd.h>
/*
* These are the variables that can be defined in <klibc/archconfig.h>.
* For boolean options, #define to 0 to disable, #define to 1 to enable.
*
* If undefined, they will be given defaults here.
*/
/*
* _KLIBC_NO_MMU:
*
*Indicates this architecture doesn't have an MMU, and therefore
*does not have the sys_fork and sys_brk system calls.
*/
/* Default to having an MMU if we can find the fork system call */
#ifndef _KLIBC_NO_MMU
# if defined(__NR_fork)
# define _KLIBC_NO_MMU 0
# else
# define _KLIBC_NO_MMU 1
# endif
#endif
/*
* _KLIBC_REAL_VFORK:
*
*Indicates that this architecture has a real vfork() system call.
*This is the default if sys_vfork exists; if there is an
*architecture-dependent implementation of vfork(), define this
*symbol.
*/
#ifndef _KLIBC_REAL_VFORK
# if defined(__NR_vfork)
# define _KLIBC_REAL_VFORK 1
# else
# define _KLIBC_REAL_VFORK 0
# endif
#endif
/*
* _KLIBC_USE_MMAP2:
*
*Indicates that this architecture should use sys_mmap2 instead
*of sys_mmap. This is the default on 32-bit architectures, assuming
*sys_mmap2 exists.
*/
#ifndef _KLIBC_USE_MMAP2
# if (_BITSIZE == 32 && defined(__NR_mmap2)) || \
(_BITSIZE == 64 && !defined(__NR_mmap))
# define _KLIBC_USE_MMAP2 1
# else
# define _KLIBC_USE_MMAP2 0
# endif
#endif
/*
* _KLIBC_MMAP2_SHIFT:
*
*Indicate the shift of the offset parameter in sys_mmap2.
*On most architectures, this is always 12, but on some
*architectures it can be a different number, or the current
*page size. If this is dependent on the page size, define
*this to an expression which includes __getpageshift().
*/
#ifndef _KLIBC_MMAP2_SHIFT
# define _KLIBC_MMAP2_SHIFT 12
#endif
/*
* _KLIBC_MALLOC_USES_SBRK:
*
*Indicates that malloc() should use sbrk() to obtain raw memory
*from the system, rather than mmap().
*/
/* Default to get memory using mmap() */
#ifndef _KLIBC_MALLOC_USES_SBRK
# define _KLIBC_MALLOC_USES_SBRK 0
#endif
/*
* _KLIBC_MALLOC_CHUNK_SIZE:
*This is the minimum chunk size we will ask the kernel for using
*malloc(); this should be a multiple of the page size and must
*be a power of 2.
*/
#ifndef _KLIBC_MALLOC_CHUNK_SIZE
# define _KLIBC_MALLOC_CHUNK_SIZE65536
#endif
/*
* _KLIBC_SBRK_ALIGNMENT:
*
*This is the minimum alignment for the memory returned by
*sbrk(). It must be a power of 2. If _KLIBC_MALLOC_USES_SBRK
*is set it should be no smaller than the size of struct
*arena_header in malloc.h (== 4 pointers.)
*/
#ifndef _KLIBC_SBRK_ALIGNMENT
# define _KLIBC_SBRK_ALIGNMENT32
#endif
/*
* _KLIBC_USE_RT_SIG:
*
* Indicates that this architecture should use the rt_sig*()
* family of system calls, even if the older system calls are
* provided. This requires that <asm/signal.h> is correct for
* using with the rt_sig*() system calls. This is the default if
* the older system calls are undefined in <asm/unistd.h>.
*
*/
#ifndef _KLIBC_USE_RT_SIG
# ifdef __NR_sigaction
# define _KLIBC_USE_RT_SIG 0
# else
# define _KLIBC_USE_RT_SIG 1
# endif
#endif
/*
* _KLIBC_NEEDS_SA_RESTORER:
*
*Some architectures, like x86-64 and some i386 Fedora kernels,
*do not provide a default sigreturn, and therefore must have
*SA_RESTORER set.
*/
#ifndef _KLIBC_NEEDS_SA_RESTORER
# define _KLIBC_NEEDS_SA_RESTORER 0
#endif
/*
* _KLIBC_STATFS_F_TYPE_64:
*
*This indicates that the f_type, f_bsize, f_namelen,
*f_frsize, and f_spare fields of struct statfs are
*64 bits long. This is normally the case for 64-bit
*platforms, and so is the default for those. See
*usr/include/sys/vfs.h for the exact details.
*/
#ifndef _KLIBC_STATFS_F_TYPE_64
# define _KLIBC_STATFS_F_TYPE_64 (_BITSIZE == 64)
#endif
/*
* _KLIBC_STATFS_F_TYPE_32B:
*
* mips has it's own definition of statfs, which is
* different from any other 32 bit arch.
*/
#ifndef _KLIBC_STATFS_F_TYPE_32B
# define _KLIBC_STATFS_F_TYPE_32B 0
#endif
/*
* _KLIBC_HAS_ARCHSOCKET_H
*
* This architecture has <klibc/archsocket.h>
*/
#ifndef _KLIBC_HAS_ARCHSOCKET_H
# define _KLIBC_HAS_ARCHSOCKET_H 0
#endif
/*
* _KLIBC_SYS_SOCKETCALL
*
*This architecture (e.g. SPARC) advertises socket-related
*system calls, which are not actually implemented. Use
*socketcalls unconditionally instead.
*/
#ifndef _KLIBC_SYS_SOCKETCALL
# define _KLIBC_SYS_SOCKETCALL 0
#endif
#endif /* _KLIBC_SYSCONFIG_H */
branches/meklort/i386/modules/include/klibc/extern.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
* klibc/extern.h
*/
#ifndef _KLIBC_EXTERN_H
#define _KLIBC_EXTERN_H
#ifdef __cplusplus
#define __extern extern "C"
#else
#define __extern extern
#endif
#define __alias(x) __attribute__((weak, alias(x)))
#endif/* _KLIBC_EXTERN_H */
branches/meklort/i386/modules/include/cstdio
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*Copyright (C) 2006 Garrett A. Kajmowicz
This file is part of the uClibc++ Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation version 2.1
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <basic_definitions>
#ifndef __HEADER_CSTDIO
#define __HEADER_CSTDIO 1
namespace std{
using ::FILE;
using ::fpos_t;
using ::clearerr;
using ::fclose;
using ::feof;
using ::ferror;
using ::fflush;
using ::fgetc;
using ::fgetpos;
using ::fgets;
using ::fopen;
using ::fprintf;
using ::fputc;
using ::fputs;
using ::fread;
using ::freopen;
using ::fscanf;
using ::fseek;
using ::fsetpos;
using ::ftell;
using ::fwrite;
using ::getc;
using ::getchar;
using ::gets;
using ::perror;
using ::printf;
using ::putc;
using ::putchar;
using ::puts;
using ::remove;
using ::rename;
using ::rewind;
using ::scanf;
using ::setbuf;
using ::setvbuf;
using ::sprintf;
using ::sscanf;
using ::tmpfile;
using ::tmpnam;
using ::ungetc;
using ::vfprintf;
using ::vprintf;
using ::vsprintf;
}
#endif
branches/meklort/i386/modules/include/cstdarg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// -*- C++ -*- forwarding header.
// Copyright (C) 1997, 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
//
// ISO C++ 14882: 20.4.6 C library
//
/** @file cstdarg
* This is a Standard C++ Library file. You should @c #include this file
* in your programs, rather than any of the "*.h" implementation files.
*
* This is the C++ version of the Standard C Library header @c stdarg.h,
* and its contents are (mostly) the same as that header, but are all
* contained in the namespace @c std.
*/
#ifndef _CPP_CSTDARG
#define _CPP_CSTDARG 1
#pragma GCC system_header
#include <stdarg.h>
// Adhere to section 17.4.1.2 clause 5 of ISO 14882:1998
#ifndef va_end
#define va_end(ap) va_end (ap)
#endif
namespace std
{
using ::va_list;
}
#endif
branches/meklort/i386/modules/include/map.old
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
/*Copyright (C) 2004 Garrett A. Kajmowicz
This file is part of the uClibc++ Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include<memory>
#include<utility>
#include<iterator>
#include <deque>
#include<functional>
#ifndef __STD_HEADER_MAP
#define __STD_HEADER_MAP
#pragma GCC visibility push(default)
namespace std{
template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<T> > class __base_map;
template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<T> > class map;
template<class Key, class T, class Compare = less<Key>, class Allocator = allocator<T> > class multimap;
template<class Key, class T, class Compare, class Allocator> class __map_iter;
template<class Key, class T, class Compare, class Allocator> class __map_citer;
/* The code for the map containers is split up into two classes.
* The first class, __base_map holds all of the data and does much of the iterator-based
* work. Then the classes map and multimap inherit from there. This was done to reduce
* the redundancy of code (And thus errors which might crop up), as well as possibly
* reducing the size of binaries if both map and multimap are used, along with the same
* template parameters.
*/
//All base classes first (__base_map, iterators, value_compare) and it's associated code
template<class Key, class T, class Compare, class Allocator> class _UCXXEXPORT __base_map{
protected:
friend class __map_iter<Key, T, Compare, Allocator>;
friend class __map_citer<Key, T, Compare, Allocator>;
public:
typedef __base_map<Key,T,Compare,Allocator>map_type;
typedef Keykey_type;
typedef Tmapped_type;
typedef pair<Key, T>value_type;
typedef Comparekey_compare;
typedef Allocatorallocator_type;
typedef typename Allocator::referencereference;
typedef typename Allocator::const_referenceconst_reference;
typedef __map_iter<Key, T, Compare, Allocator>iterator;
typedef __map_citer<Key, T, Compare, Allocator>const_iterator;
typedef typename Allocator::size_typesize_type;
typedef typename Allocator::difference_typedifference_type;
typedef typename Allocator::pointerpointer;
typedef typename Allocator::const_pointerconst_pointer;
typedef typename std::reverse_iterator<iterator>reverse_iterator;
typedef typename std::reverse_iterator<const_iterator>const_reverse_iterator;
class value_compare;
explicit __base_map(const Compare& comp = Compare(), const Allocator& al = Allocator());
__base_map(const map_type& x);
~__base_map();
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
bool empty() const;
size_type size() const;
size_type max_size() const;
iterator lower_bound(const key_type& x);
const_iterator lower_bound(const key_type& x) const;
void swap(map_type & x);
void clear();
key_compare key_comp() const;
//value_compare value_comp() const;
protected:
deque<pair<Key, T>, allocator<pair<Key, T> > > data;
Compare c;
};
//Implementations
template<class Key, class T, class Compare, class Allocator> class _UCXXEXPORT __map_citer
: public std::iterator<
bidirectional_iterator_tag,
std::pair<Key, T>,
typename Allocator::difference_type,
std::pair<Key, T>*,
std::pair<Key, T>&
>
{
protected:
typedef __base_map<Key, T, Compare, Allocator> Map;
friend class __base_map<Key, T, Compare, Allocator>;
friend class __base_map<Key, T, Compare, Allocator>::iterator;
friend class map<Key, T, Compare, Allocator>;
friend class multimap<Key, T, Compare, Allocator>;
typename Map::size_type element;
const Map * container;
public:
__map_citer() : element(0), container(0) { }
__map_citer(const typename Map::const_iterator & m)
: element(m.element), container(m.container) { }
__map_citer(typename Map::size_type e, const Map * const c)
: element(e), container(c) { }
~__map_citer() { }
typename Map::value_type operator*() const{
return container->data[element];
}
const typename Map::value_type * operator->() const{
return &(container->data[element]);
}
__map_citer & operator=(const typename Map::const_iterator & m){
element = m.element;
container = m.container;
return *this;
}
bool operator==(const typename Map::const_iterator & m) const {
return (m.element == element && m.container == container);
}
bool operator!=(const typename Map::const_iterator & m) const {
return (m.element != element || m.container != container);
}
__map_citer & operator++(){
++element;
return *this;
}
__map_citer operator++(int){
__map_citer temp(*this);
++element;
return temp;
}
__map_citer & operator--(){
--element;
return *this;
}
__map_citer operator--(int){
__map_citer temp(*this);
--element;
return temp;
}
};
template<class Key, class T, class Compare, class Allocator> class _UCXXEXPORT __map_iter
: public std::iterator<
bidirectional_iterator_tag,
std::pair<Key, T>,
typename Allocator::difference_type,
std::pair<Key, T>*,
std::pair<Key, T>&
>
{
protected:
typedef class __base_map<Key, T, Compare, Allocator> Map;
//FIXME - Find a way to use template parameters or something. This will do for now
friend class __base_map<Key, T, Compare, Allocator>;
friend class __base_map<Key, T, Compare, Allocator>::const_iterator;
friend class map<Key, T, Compare, Allocator>;
friend class multimap<Key, T, Compare, Allocator>;
typename Map::size_type element;
Map * container;
public:
__map_iter() : element(0), container(0) { }
__map_iter(const typename Map::iterator & m)
: element(m.element), container(m.container) { }
__map_iter(typename Map::size_type e, Map * c)
: element(e), container(c) { }
~__map_iter() { }
typename Map::value_type & operator*(){
return container->data[element];
}
const typename Map::value_type & operator*() const{
return container->data[element];
}
typename Map::value_type * operator->(){
return &(container->data[element]);
}
__map_iter & operator=(const typename Map::iterator & m){
element = m.element;
container = m.container;
return *this;
}
bool operator==(const typename Map::iterator & m) const {
return (m.element == element && m.container == container);
}
bool operator!=(const typename Map::iterator & m) const {
return (m.element != element || m.container != container);
}
bool operator==(const typename Map::const_iterator & m) const {
return (m.element == element && m.container == container);
}
bool operator!=(const typename Map::const_iterator & m) const {
return (m.element != element || m.container != container);
}
__map_iter & operator++(){
++element;
return *this;
}
__map_iter operator++(int){
__map_iter temp(*this);
++element;
return temp;
}
__map_iter & operator--(){
--element;
return *this;
}
__map_iter operator--(int){
__map_iter temp(*this);
--element;
return temp;
}
operator typename Map::const_iterator() const{
return typename Map::const_iterator(element, container);
}
};
//Compare the keys of the two items
template<class Key, class T, class Compare, class Allocator> class _UCXXEXPORT
__base_map<Key, T, Compare, Allocator>::value_compare : public binary_function<
typename map<Key, T, Compare, Allocator>::value_type,
typename map<Key, T, Compare, Allocator>::value_type,
bool>
{
friend class __base_map<Key, T, Compare, Allocator>;
protected:
Compare comp;
value_compare(Compare c) : comp(c) { }
~value_compare() { }
public:
bool operator()(const value_type& x, const value_type& y) const {
return comp(x.first, y.first);
}
};
template <class Key, class T, class Compare, class Allocator>
__base_map<Key, T, Compare, Allocator>::__base_map(const Compare& comp, const Allocator&)
: data(), c(comp)
{
}
template <class Key, class T, class Compare, class Allocator>
__base_map<Key, T, Compare, Allocator>::__base_map(const __base_map<Key,T,Compare,Allocator>& x)
: data(x.data), c(x.c)
{
}
template <class Key, class T, class Compare, class Allocator>
__base_map<Key, T, Compare, Allocator>::~__base_map()
{
}
template <class Key, class T, class Compare, class Allocator>
typename __base_map<Key, T, Compare, Allocator>::iterator
__base_map<Key, T, Compare, Allocator>::begin()
{
return iterator(0, this);
}
template <class Key, class T, class Compare, class Allocator>
typename __base_map<Key, T, Compare, Allocator>::const_iterator
__base_map<Key, T, Compare, Allocator>::begin() const
{
return const_iterator(0, this);
}
template <class Key, class T, class Compare, class Allocator>
typename __base_map<Key, T, Compare, Allocator>::iterator
__base_map<Key, T, Compare, Allocator>::end()
{
return iterator(data.size(), this);
}
template <class Key, class T, class Compare, class Allocator>
typename __base_map<Key, T, Compare, Allocator>::const_iterator
__base_map<Key, T, Compare, Allocator>::end() const
{
return const_iterator(data.size(), this);
}
template <class Key, class T, class Compare, class Allocator>
typename __base_map<Key, T, Compare, Allocator>::reverse_iterator
__base_map<Key, T, Compare, Allocator>::rbegin()
{
return reverse_iterator(end());
}
template <class Key, class T, class Compare, class Allocator>
typename __base_map<Key, T, Compare, Allocator>::const_reverse_iterator
__base_map<Key, T, Compare, Allocator>::rbegin() const
{
return const_reverse_iterator(end());
}
template <class Key, class T, class Compare, class Allocator>
typename __base_map<Key, T, Compare, Allocator>::reverse_iterator
__base_map<Key, T, Compare, Allocator>::rend()
{
return reverse_iterator(begin());
}
template <class Key, class T, class Compare, class Allocator>
typename __base_map<Key, T, Compare, Allocator>::const_reverse_iterator
__base_map<Key, T, Compare, Allocator>::rend() const
{
return const_reverse_iterator(begin());
}
template <class Key, class T, class Compare, class Allocator>
bool __base_map<Key, T, Compare, Allocator>::empty() const
{
return (data.size() == 0);
}
template <class Key, class T, class Compare, class Allocator>
typename __base_map<Key, T, Compare, Allocator>::size_type
__base_map<Key, T, Compare, Allocator>::size() const
{
return data.size();
}
template <class Key, class T, class Compare, class Allocator>
typename __base_map<Key, T, Compare, Allocator>::size_type
__base_map<Key, T, Compare, Allocator>::max_size() const
{
return data.max_size();
}
template <class Key, class T, class Compare, class Allocator>
typename __base_map<Key, T, Compare, Allocator>::iterator
__base_map<Key, T, Compare, Allocator>::lower_bound(const key_type &x)
{
size_type low = 0;
size_type high = data.size();
while (low < high) {
size_type i = (low + high) / 2;
if( c(data[i].first, x) ){
low = i + 1;
}else{
high = i;
}
}
return iterator(low, this);
}
template <class Key, class T, class Compare, class Allocator>
typename __base_map<Key, T, Compare, Allocator>::const_iterator
__base_map<Key, T, Compare, Allocator>::lower_bound(const key_type &x) const
{
size_type low = 0;
size_type high = data.size();
while (low < high) {
size_type i = (low + high) / 2;
if( c(data[i].first, x) ){
low = i + 1;
}else{
high = i;
}
}
return const_iterator(low, this);
}
template <class Key, class T, class Compare, class Allocator>
void __base_map<Key, T, Compare, Allocator>::swap(__base_map<Key,T,Compare,Allocator>& m)
{
Compare n = c;
c = m.c;
m.c = n;
data.swap(m.data);
}
template <class Key, class T, class Compare, class Allocator>
void __base_map<Key, T, Compare, Allocator>::clear()
{
data.clear();
}
template <class Key, class T, class Compare, class Allocator>
typename __base_map<Key, T, Compare, Allocator>::key_compare
__base_map<Key, T, Compare, Allocator>::key_comp() const
{
return c;
}
//value_compare value_comp() const;
/* This is the implementation for the map container. As noted above, it deviates
* from ISO spec by deriving from a base class in order to reduce code redundancy.
* More code could be reduced by convirting to virtual functions (thus allowing
* much of the erase and insert code to be duplicated), but that would deviate from
* the specifications too much to be worth the risk.
*/
//Implementation of map
template<class Key, class T, class Compare, class Allocator> class _UCXXEXPORT map
: public __base_map<Key, T, Compare, Allocator>
{
//Default value of allocator does not meet C++ standard specs, but it works for this library
//Deal with it
public:
typedef__base_map<Key, T, Compare, Allocator>base;
typedef typename base::key_typekey_type;
typedef typename base::mapped_typemapped_type;
typedef typename base::value_typevalue_type;
typedef typename base::key_comparekey_compare;
typedef typename base::allocator_typeallocator_type;
typedef typename base::referencereference;
typedef typename base::const_referenceconst_reference;
typedef typename base::iteratoriterator;
typedef typename base::const_iteratorconst_iterator;
typedef typename base::size_typesize_type;
typedef typename base::difference_typedifference_type;
typedef typename base::pointerpointer;
typedef typename base::const_pointerconst_pointer;
typedef typename base::reverse_iteratorreverse_iterator;
typedef typename base::const_reverse_iteratorconst_reverse_iterator;
using base::value_compare;
explicit map(const Compare& comp = Compare(), const Allocator& al = Allocator())
: base(comp, al) { }
template <class InputIterator> map(InputIterator first, InputIterator last,
const Compare& comp = Compare(), const Allocator& = Allocator());
map(const map<Key,T,Compare,Allocator>& x) : base(x) { }
~map() { }
map<Key,T,Compare,Allocator>& operator=(const map<Key,T,Compare,Allocator>& x);
reference operator[](const key_type& k);
pair<iterator, bool> insert(const value_type& x);
iterator insert(iterator position, const value_type& x);
template <class InputIterator> void insert(InputIterator first, InputIterator last);
void erase(iterator position);
size_type erase(const key_type& x);
void erase(iterator first, iterator last);
using base::begin;
using base::end;
using base::rbegin;
using base::rend;
using base::empty;
using base::size;
using base::max_size;
iterator find(const key_type& x);
const_iterator find(const key_type& x) const;
size_type count(const key_type& x) const;
iterator upper_bound(const key_type& x);
const_iterator upper_bound(const key_type& x) const;
pair<iterator,iterator> equal_range(const key_type& x);
pair<const_iterator,const_iterator> equal_range(const key_type& x) const;
protected:
friend class base::iterator;
friend class base::const_iterator;
friend bool operator==(const map<Key,T,Compare,Allocator>& x, const map<Key,T,Compare,Allocator>& y);
using base::data;
using base::c;
};
template <class Key, class T, class Compare, class Allocator> template <class InputIterator>
map<Key, T, Compare, Allocator>::
map(InputIterator first, InputIterator last, const Compare& comp, const Allocator& al)
: base(comp, al)
{
while(first !=last){
insert(*first);
++first;
}
}
template <class Key, class T, class Compare, class Allocator>
map<Key, T, Compare, Allocator>::map<Key,T,Compare,Allocator>&
map<Key, T, Compare, Allocator>::operator=(const map<Key,T,Compare,Allocator>& x)
{
if( &x == this){
return *this;
}
c = x.c;
data = x.data;
return *this;
}
template <class Key, class T, class Compare, class Allocator>
typename map<Key, T, Compare, Allocator>::reference
map<Key, T, Compare, Allocator>::operator[](const key_type & k)
{
/*iterator i = lower_bound(k);
if( !c( i->first, k) && !c(k, i->first) ){
return i->second;
}
pair<Key, T> t;
t.first = k;
t.second = T();
return insert(t).first->second;
*/
//This is from the spec and is quite ugly.
return (*((insert(make_pair(k, T()))).first)).second;
}
template <class Key, class T, class Compare, class Allocator>
pair<typename map<Key, T, Compare, Allocator>::iterator, bool>
map<Key, T, Compare, Allocator>::insert(const value_type& x)
{
pair<typename map<Key, T, Compare, Allocator>::iterator, bool> retval;
//Either set is empty or element to insert goes at the begining
if(data.size() == 0 || c(x.first, data[0].first) ){
data.push_front(x);
retval.first = begin();
retval.second = true;
return retval;
}
//Element to insert goes at the end
if( c(data[data.size() - 1].first, x.first) ){
data.push_back(x);
retval.first = end();
--retval.first;
retval.second = true;
return retval;
}
retval.first = __base_map<Key, T, Compare, Allocator>::lower_bound(x.first);
//No match - this should never happen
if(retval.first == end()){
retval.second = false;
return retval;
}
//If we have an exact match
if( !c( retval.first->first, x.first) && !c(x.first, retval.first->first ) ){
retval.second = false;
return retval;
}
typename deque<pair<Key, T>, allocator<pair<Key, T> > >::iterator q(&data, retval.first.element);
data.insert(q, x);
retval.first = __base_map<Key, T, Compare, Allocator>::lower_bound(x.first); //Need to refind because insert can move data around
retval.second = true;
return retval;
}
template <class Key, class T, class Compare, class Allocator>
typename map<Key, T, Compare, Allocator>::iterator
map<Key, T, Compare, Allocator>::insert(iterator, const value_type& x)
{
//Just reusing code. It's hard to make improvements over existing algo.
//We aren't using the iterator parameter, but it's only a hint and not required to be used.
insert(x);
return find(x.first);
}
template <class Key, class T, class Compare, class Allocator>
template <class InputIterator> void
map<Key, T, Compare, Allocator>::insert(InputIterator first, InputIterator last)
{
while(first !=last){
insert(*first);
++first;
}
}
template <class Key, class T, class Compare, class Allocator> void
map<Key, T, Compare, Allocator>::erase(iterator position)
{
//Create a deque iterator from position information and then
//Use built in erase feature because it is handy.
typename deque<pair<Key, T>, allocator<pair<Key, T> > >::iterator pos(&data, position.element);
data.erase(pos);
}
template <class Key, class T, class Compare, class Allocator>
typename map<Key, T, Compare, Allocator>::size_type
map<Key, T, Compare, Allocator>::erase(const key_type& x)
{
typename map<Key, T, Compare, Allocator>::iterator i = find(x);
if(i!=end()){
erase(i);
return 1;
}
return 0;
}
template <class Key, class T, class Compare, class Allocator>
void map<Key, T, Compare, Allocator>::erase(iterator first, iterator last)
{
typename deque<pair<Key, T>, allocator<pair<Key, T> > >::iterator f(&data, first.element);
typename deque<pair<Key, T>, allocator<pair<Key, T> > >::iterator l(&data, last.element);
data.erase(f, l);
}
template <class Key, class T, class Compare, class Allocator>
typename map<Key, T, Compare, Allocator>::iterator
map<Key, T, Compare, Allocator>::
find(const typename map<Key, T, Compare, Allocator>::key_type& x)
{
if(data.size() == 0){
return end();
}
iterator retval = __base_map<Key, T, Compare, Allocator>::lower_bound(x);
if(retval == end()){
return retval;
}
//Make sure we have an exact match....
if(!c( retval->first, x) && !c(x, retval->first )){
return retval;
}
return end();
}
template <class Key, class T, class Compare, class Allocator>
typename map<Key, T, Compare, Allocator>::const_iterator
map<Key, T, Compare, Allocator>::find(const key_type& x) const
{
if(data.size() == 0){
return end();
}
const_iterator retval = __base_map<Key, T, Compare, Allocator>::lower_bound(x);
if(retval == end()){
return retval;
}
//Make sure we have an exact match....
if(!c( retval->first, x) && !c(x, retval->first )){
return retval;
}
return end();
}
template <class Key, class T, class Compare, class Allocator>
typename map<Key, T, Compare, Allocator>::size_type
map<Key, T, Compare, Allocator>::count(const typename map<Key, T, Compare, Allocator>::key_type& x) const
{
if( find(x) == end()){
return 0;
}
return 1;
}
template <class Key, class T, class Compare, class Allocator>
typename map<Key, T, Compare, Allocator>::iterator
map<Key, T, Compare, Allocator>::upper_bound(const key_type& x)
{
typename map<Key, T, Compare, Allocator>::iterator i = __base_map<Key, T, Compare, Allocator>::lower_bound(x);
if( i != end() && !c(x, i->first) ){
++i;
}
return i;
}
template <class Key, class T, class Compare, class Allocator>
typename map<Key, T, Compare, Allocator>::const_iterator
map<Key, T, Compare, Allocator>::upper_bound(const key_type& x) const
{
typename map<Key, T, Compare, Allocator>::const_iterator i = __base_map<Key, T, Compare, Allocator>::lower_bound(x);
if(i != end() && !c(x, i->first)){
++i;
}
return i;
}
template <class Key, class T, class Compare, class Allocator>
pair<typename map<Key, T, Compare, Allocator>::iterator,
typename map<Key, T, Compare, Allocator>::iterator
> map<Key, T, Compare, Allocator>::equal_range(const key_type& x)
{
pair< typename map<Key, T, Compare, Allocator>::iterator,
typename map<Key, T, Compare, Allocator>::iterator
> retval;
retval.first = __base_map<Key, T, Compare, Allocator>::lower_bound(x);
retval.second = upper_bound(x);
return retval;
}
template <class Key, class T, class Compare, class Allocator>
pair<typename map<Key, T, Compare, Allocator>::const_iterator,
typename map<Key, T, Compare, Allocator>::const_iterator
> map<Key, T, Compare, Allocator>::equal_range(const key_type& x) const
{
pair< typename map<Key, T, Compare, Allocator>::const_iterator,
typename map<Key, T, Compare, Allocator>::const_iterator
> retval;
retval.first = __base_map<Key, T, Compare, Allocator>::lower_bound(x);
retval.second = upper_bound(x);
return retval;
}
template <class Key, class T, class Compare, class Allocator> bool operator==
(const map<Key,T,Compare,Allocator>& x, const map<Key,T,Compare,Allocator>& y)
{
if(x.c == y.c && x.data == y.data){
return true;
}
return false;
}
//Implementation of multimap
template<class Key, class T, class Compare, class Allocator> class _UCXXEXPORT multimap
: public __base_map<Key, T, Compare, Allocator>
{
//Default value of allocator does not meet C++ standard specs, but it works for this library
//Deal with it
public:
typedef__base_map<Key, T, Compare, Allocator>base;
typedef typename base::key_typekey_type;
typedef typename base::mapped_typemapped_type;
typedef typename base::value_typevalue_type;
typedef typename base::key_comparekey_compare;
typedef typename base::allocator_typeallocator_type;
typedef typename base::referencereference;
typedef typename base::const_referenceconst_reference;
typedef typename base::iteratoriterator;
typedef typename base::const_iteratorconst_iterator;
typedef typename base::size_typesize_type;
typedef typename base::difference_typedifference_type;
typedef typename base::pointerpointer;
typedef typename base::const_pointerconst_pointer;
typedef typename base::reverse_iteratorreverse_iterator;
typedef typename base::const_reverse_iteratorconst_reverse_iterator;
explicit multimap(const Compare& comp = Compare(), const Allocator& al = Allocator())
: base(comp, al) { }
template <class InputIterator> multimap(InputIterator first, InputIterator last,
const Compare& comp = Compare(), const Allocator& = Allocator());
multimap(const multimap<Key,T,Compare,Allocator>& x) : base(x) { }
~multimap() { }
multimap<Key,T,Compare,Allocator>& operator=(const multimap<Key,T,Compare,Allocator>& x);
iterator insert(const value_type& x);
iterator insert(iterator position, const value_type& x);
template <class InputIterator> void insert(InputIterator first, InputIterator last);
void erase(iterator position);
size_type erase(const key_type& x);
void erase(iterator first, iterator last);
using base::begin;
using base::end;
using base::rbegin;
using base::rend;
using base::empty;
using base::size;
using base::max_size;
iterator find(const key_type& x);
const_iterator find(const key_type& x) const;
size_type count(const key_type& x) const;
iterator upper_bound(const key_type& x);
const_iterator upper_bound(const key_type& x) const;
pair<iterator,iterator> equal_range(const key_type& x);
pair<const_iterator,const_iterator> equal_range(const key_type& x) const;
protected:
friend class base::iterator;
friend class base::const_iterator;
using base::data;
using base::c;
};
template <class Key, class T, class Compare, class Allocator> template <class InputIterator>
multimap<Key, T, Compare, Allocator>::
multimap(InputIterator first, InputIterator last, const Compare& comp, const Allocator& al)
: base(comp, al)
{
while(first !=last){
insert(*first);
++first;
}
}
template <class Key, class T, class Compare, class Allocator>
multimap<Key, T, Compare, Allocator>::multimap<Key,T,Compare,Allocator>&
multimap<Key, T, Compare, Allocator>::operator=(const multimap<Key,T,Compare,Allocator>& x)
{
if( &x == this){
return *this;
}
c = x.c;
data = x.data;
return *this;
}
template <class Key, class T, class Compare, class Allocator>
typename multimap<Key, T, Compare, Allocator>::iterator
multimap<Key, T, Compare, Allocator>::insert(const value_type &x)
{
iterator retval;
//Either set is empty or element to insert goes at the begining
if(data.size() == 0 || c(x.first, data[0].first) ){
data.push_front(x);
return begin();
}
//Element to insert goes at the end
if( c(data[data.size() - 1].first, x.first) ){
data.push_back(x);
return end();
}
retval = __base_map<Key, T, Compare, Allocator>::lower_bound(x.first);
//No match - this should never happen
if(retval == end()){
return retval;
}
if( !c(x.first, retval->first) ){
++retval;
}
typename deque<pair<Key, T>, allocator<pair<Key, T> > >::iterator q(&data, retval.element);
data.insert(q, x);
return retval;
}
template <class Key, class T, class Compare, class Allocator>
typename multimap<Key, T, Compare, Allocator>::iterator
multimap<Key, T, Compare, Allocator>::insert(iterator position, const value_type& x)
{
//Inserting at begining
if(position == begin() && !c(position->first, x.first) ){
data.push_front(x);
return position;
}
//Inserting at end
if(position == end() && !c(x.first, data[data.size() - 1].first) ){
data.push_back(x);
return position;
}
//Inserting in middle
iterator temp = position;
--temp;
if( !c(position->first, x.first) && !c(x.first, temp->first) ){
typename deque<pair<Key, T>, allocator<pair<Key, T> > >::iterator q(&data, position.element);
data.insert(q, x);
return position;
}
return insert(x);
}
template <class Key, class T, class Compare, class Allocator>
template <class InputIterator> void
multimap<Key, T, Compare, Allocator>::insert(InputIterator first, InputIterator last)
{
while(first !=last){
insert(*first);
++first;
}
}
template <class Key, class T, class Compare, class Allocator> void
multimap<Key, T, Compare, Allocator>::erase(iterator position)
{
//Create a deque iterator from position information and then
//Use built in erase feature because it is handy.
typename deque<pair<Key, T>, allocator<pair<Key, T> > >::iterator pos(&data, position.element);
data.erase(pos);
}
template <class Key, class T, class Compare, class Allocator>
typename multimap<Key, T, Compare, Allocator>::size_type
multimap<Key, T, Compare, Allocator>::erase(const key_type& x)
{
typename multimap<Key, T, Compare, Allocator>::iterator f = __base_map<Key, T, Compare, Allocator>::lower_bound(x);
typename multimap<Key, T, Compare, Allocator>::iterator l = upper_bound(x);
size_type t = l.element - f.element;
erase(f, l);
return t;
}
template <class Key, class T, class Compare, class Allocator>
void multimap<Key, T, Compare, Allocator>::erase(iterator first, iterator last)
{
typename deque<pair<Key, T>, allocator<pair<Key, T> > >::iterator f(&data, first.element);
typename deque<pair<Key, T>, allocator<pair<Key, T> > >::iterator l(&data, last.element);
data.erase(f, l);
}
template <class Key, class T, class Compare, class Allocator>
typename multimap<Key, T, Compare, Allocator>::iterator
multimap<Key, T, Compare, Allocator>::find(const key_type& x)
{
if(data.size() == 0){
return end();
}
iterator retval = __base_map<Key, T, Compare, Allocator>::lower_bound(x);
if(retval == end()){
return retval;
}
if( c(x, retval->first) || c(retval->first, x) ){
return end();
}
while( retval.element > 0 && !c(retval->first, x) && !c(x, retval->first) ){
--retval;
}
if( c(retval->first, x)){
++retval;
}
return retval;
}
template <class Key, class T, class Compare, class Allocator>
typename multimap<Key, T, Compare, Allocator>::const_iterator
multimap<Key, T, Compare, Allocator>::find(const key_type& x) const
{
if(data.size() == 0){
return end();
}
const_iterator retval = __base_map<Key, T, Compare, Allocator>::lower_bound(x);
if(retval == end()){
return retval;
}
if( c(x, retval->first) || c(retval->first, x) ){
return end();
}
while( retval.element > 0 && !c(retval->first, x) && !c(x, retval->first) ){
--retval;
}
if( c(retval->first, x)){
++retval;
}
return retval;
}
template <class Key, class T, class Compare, class Allocator>
typename multimap<Key, T, Compare, Allocator>::size_type
multimap<Key, T, Compare, Allocator>::
count(const typename multimap<Key, T, Compare, Allocator>::key_type& x) const
{
pair< typename multimap<Key, T, Compare, Allocator>::const_iterator,
typename multimap<Key, T, Compare, Allocator>::const_iterator
> temp = equal_range(x);
return temp.second.element - temp.first.element;
}
template <class Key, class T, class Compare, class Allocator>
typename multimap<Key, T, Compare, Allocator>::iterator
multimap<Key, T, Compare, Allocator>::upper_bound(const key_type& x)
{
typename multimap<Key, T, Compare, Allocator>::iterator i = __base_map<Key, T, Compare, Allocator>::lower_bound(x);
while(i != end() && !c(x, i->first)){
++i;
}
return i;
}
template <class Key, class T, class Compare, class Allocator>
typename multimap<Key, T, Compare, Allocator>::const_iterator
multimap<Key, T, Compare, Allocator>::upper_bound(const key_type& x) const
{
typename multimap<Key, T, Compare, Allocator>::const_iterator i = __base_map<Key, T, Compare, Allocator>::lower_bound(x);
while(i != end() && !c(x, i->first)){
++i;
}
return i;
}
template <class Key, class T, class Compare, class Allocator>
pair<typename multimap<Key, T, Compare, Allocator>::iterator,
typename multimap<Key, T, Compare, Allocator>::iterator
> multimap<Key, T, Compare, Allocator>::equal_range(const key_type& x)
{
pair< typename multimap<Key, T, Compare, Allocator>::iterator,
typename multimap<Key, T, Compare, Allocator>::iterator
> retval;
retval.first = __base_map<Key, T, Compare, Allocator>::lower_bound(x);
retval.second = upper_bound(x);
return retval;
}
template <class Key, class T, class Compare, class Allocator>
pair<typename multimap<Key, T, Compare, Allocator>::const_iterator,
typename multimap<Key, T, Compare, Allocator>::const_iterator
> multimap<Key, T, Compare, Allocator>::equal_range(const key_type& x) const
{
pair< typename multimap<Key, T, Compare, Allocator>::const_iterator,
typename multimap<Key, T, Compare, Allocator>::const_iterator
> retval;
retval.first = __base_map<Key, T, Compare, Allocator>::lower_bound(x);
retval.second = upper_bound(x);
return retval;
}
/* Non-member functions. These are at the end because they are not associated with any
particular class. These will be implemented as I figure out exactly what all of
them are supposed to do, and I have time.
*/
template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator<
(const map<Key,T,Compare,Allocator>& x, const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator!=
(const map<Key,T,Compare,Allocator>& x, const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator>
(const map<Key,T,Compare,Allocator>& x, const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator>=
(const map<Key,T,Compare,Allocator>& x, const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator<=
(const map<Key,T,Compare,Allocator>& x, const map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT void swap
(map<Key,T,Compare,Allocator>& x, map<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator==
(const multimap<Key,T,Compare,Allocator>& x, const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator<
(const multimap<Key,T,Compare,Allocator>& x, const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator!=
(const multimap<Key,T,Compare,Allocator>& x, const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator>
(const multimap<Key,T,Compare,Allocator>& x, const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator>=
(const multimap<Key,T,Compare,Allocator>& x, const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT bool operator<=
(const multimap<Key,T,Compare,Allocator>& x, const multimap<Key,T,Compare,Allocator>& y);
template <class Key, class T, class Compare, class Allocator> _UCXXEXPORT void swap
(multimap<Key,T,Compare,Allocator>& x, multimap<Key,T,Compare,Allocator>& y);
}
#pragma GCC visibility pop
#endif
branches/meklort/i386/modules/include/unwind-cxx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// -*- C++ -*- Exception handling and frame unwind runtime interface routines.
// Copyright (C) 2001 Free Software Foundation, Inc.
//
// This file is part of GCC.
//
// GCC is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// GCC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with GCC; see the file COPYING. If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// This is derived from the C++ ABI for IA-64. Where we diverge
// for cross-architecture compatibility are noted with "@@@".
#ifndef _UNWIND_CXX_H
#define _UNWIND_CXX_H 1
// Level 2: C++ ABI
#include <typeinfo>
#include <exception>
#include <cstddef>
#include "unwind.h"
#pragma GCC visibility push(default)
namespace __cxxabiv1
{
#ifdef __UCLIBCXX_EXCEPTION_SUPPORT__
// A C++ exception object consists of a header, which is a wrapper around
// an unwind object header with additional C++ specific information,
// followed by the exception object itself.
struct __cxa_exception
{
// Manage the exception object itself.
std::type_info *exceptionType;
void (*exceptionDestructor)(void *);
// The C++ standard has entertaining rules wrt calling set_terminate
// and set_unexpected in the middle of the exception cleanup process.
std::unexpected_handler unexpectedHandler;
std::terminate_handler terminateHandler;
// The caught exception stack threads through here.
__cxa_exception *nextException;
// How many nested handlers have caught this exception. A negated
// value is a signal that this object has been rethrown.
int handlerCount;
// Cache parsed handler data from the personality routine Phase 1
// for Phase 2 and __cxa_call_unexpected.
int handlerSwitchValue;
const unsigned char *actionRecord;
const unsigned char *languageSpecificData;
_Unwind_Ptr catchTemp;
void *adjustedPtr;
// The generic exception header. Must be last.
_Unwind_Exception unwindHeader;
};
// Each thread in a C++ program has access to a __cxa_eh_globals object.
struct __cxa_eh_globals
{
__cxa_exception *caughtExceptions;
unsigned int uncaughtExceptions;
};
// The __cxa_eh_globals for the current thread can be obtained by using
// either of the following functions. The "fast" version assumes at least
// one prior call of __cxa_get_globals has been made from the current
// thread, so no initialization is necessary.
extern "C" __cxa_eh_globals *__cxa_get_globals () throw();
extern "C" __cxa_eh_globals *__cxa_get_globals_fast () throw();
#endif
#ifdef __UCLIBCXX_EXCEPTION_SUPPORT__
// Allocate memory for the exception plus the thown object.
extern "C" void *__cxa_allocate_exception(std::size_t thrown_size) throw();
// Free the space allocated for the exception.
extern "C" void __cxa_free_exception(void *thrown_exception) throw();
// Throw the exception.
extern "C" void __cxa_throw (void *thrown_exception,
std::type_info *tinfo,
void (*dest) (void *))
__attribute__((noreturn));
// Used to implement exception handlers.
extern "C" void *__cxa_begin_catch (void *) throw();
extern "C" void __cxa_end_catch ();
extern "C" void __cxa_rethrow () __attribute__((noreturn));
#endif
// These facilitate code generation for recurring situations.
extern "C" void __cxa_bad_cast ();
extern "C" void __cxa_bad_typeid ();
// @@@ These are not directly specified by the IA-64 C++ ABI.
// Handles re-checking the exception specification if unexpectedHandler
// throws, and if bad_exception needs to be thrown. Called from the
// compiler.
extern "C" void __cxa_call_unexpected (void *) __attribute__((noreturn));
// Invokes given handler, dying appropriately if the user handler was
// so inconsiderate as to return.
extern void __terminate(std::terminate_handler) __attribute__((noreturn));
extern void __unexpected(std::unexpected_handler) __attribute__((noreturn));
// The current installed user handlers.
extern std::terminate_handler __terminate_handler;
extern std::unexpected_handler __unexpected_handler;
// These are explicitly GNU C++ specific.
// This is the exception class we report -- "GNUCC++\0".
const _Unwind_Exception_Class __gxx_exception_class
= ((((((((_Unwind_Exception_Class) 'G'
<< 8 | (_Unwind_Exception_Class) 'N')
<< 8 | (_Unwind_Exception_Class) 'U')
<< 8 | (_Unwind_Exception_Class) 'C')
<< 8 | (_Unwind_Exception_Class) 'C')
<< 8 | (_Unwind_Exception_Class) '+')
<< 8 | (_Unwind_Exception_Class) '+')
<< 8 | (_Unwind_Exception_Class) '\0');
// GNU C++ personality routine, Version 0.
extern "C" _Unwind_Reason_Code __gxx_personality_v0
(int, _Unwind_Action, _Unwind_Exception_Class,
struct _Unwind_Exception *, struct _Unwind_Context *);
// GNU C++ sjlj personality routine, Version 0.
extern "C" _Unwind_Reason_Code __gxx_personality_sj0
(int, _Unwind_Action, _Unwind_Exception_Class,
struct _Unwind_Exception *, struct _Unwind_Context *);
#ifdef __UCLIBCXX_EXCEPTION_SUPPORT__
// Acquire the C++ exception header from the C++ object.
static inline __cxa_exception *
__get_exception_header_from_obj (void *ptr)
{
return reinterpret_cast<__cxa_exception *>(ptr) - 1;
}
// Acquire the C++ exception header from the generic exception header.
static inline __cxa_exception *
__get_exception_header_from_ue (_Unwind_Exception *exc)
{
return reinterpret_cast<__cxa_exception *>(exc + 1) - 1;
}
#endif
} /* namespace __cxxabiv1 */
#pragma GCC visibility pop
#endif // _UNWIND_CXX_H
branches/meklort/i386/modules/include/iomanip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*Copyright (C) 2005 Garrett A. Kajmowicz
This file is part of the uClibc++ Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <exception>
#include <ios>
#ifndef __STD_IOMANIP
#define __STD_IOMANIP 1
#pragma GCC visibility push(default)
namespace std{
// These are the helper classes which we are going to be using to
// hold the required data
class _UCXXEXPORT __resetiosflags{
public:
ios_base::fmtflags m;
_UCXXEXPORT __resetiosflags(ios_base::fmtflags mask) : m(mask){ }
};
class _UCXXEXPORT __setiosflags{
public:
ios_base::fmtflags m;
_UCXXEXPORT __setiosflags(ios_base::fmtflags mask) : m(mask){ }
};
class _UCXXEXPORT __setbase{
public:
int base;
_UCXXEXPORT __setbase(int b) : base(b){ }
};
class _UCXXEXPORT __setfill{
public:
int character;
_UCXXEXPORT __setfill(int c): character(c){ }
};
class _UCXXEXPORT __setprecision{
public:
int digits;
_UCXXEXPORT __setprecision(int n): digits(n) { }
};
class _UCXXEXPORT __setw{
public:
int width;
_UCXXEXPORT __setw(int n): width(n) { }
};
//Actual manipulator functions
inline __resetiosflags resetiosflags(ios_base::fmtflags mask){
return __resetiosflags(mask);
}
inline __setiosflags setiosflags(ios_base::fmtflags mask){
return __setiosflags(mask);
}
inline __setbase setbase(int b){
return __setbase(b);
}
inline __setfill setfill(int c){
return __setfill(c);
}
inline __setprecision setprecision(int n){
return __setprecision(n);
}
inline __setw setw(int n){
return __setw(n);
}
//How to handle interaction with [i|o]stream classes
template<class Ch, class Tr> _UCXXEXPORT basic_ostream<Ch, Tr>&
operator<<(basic_ostream<Ch, Tr>& os, const __resetiosflags s)
{
os.setf(ios_base::fmtflags(0),s.m);
return os;
}
template<class Ch, class Tr> _UCXXEXPORT basic_istream<Ch, Tr>&
operator>>(basic_istream<Ch, Tr>& is, const __resetiosflags s)
{
is.setf(ios_base::fmtflags(0),s.m);
return is;
}
template<class Ch, class Tr> _UCXXEXPORT basic_ostream<Ch, Tr>&
operator<<(basic_ostream<Ch, Tr>& os, const __setiosflags s)
{
os.setf(s.m);
return os;
}
template<class Ch, class Tr> _UCXXEXPORT basic_ostream<Ch, Tr>&
operator<<(basic_ostream<Ch, Tr>& os, const __setbase s)
{
ios_base::fmtflags f(0);
switch(s.base){
case 8:
f = ios_base::oct;
break;
case 10:
f = ios_base::dec;
break;
case 16:
f = ios_base::hex;
break;
default:
break;
}
os.setf(f, ios_base::basefield);
return os;
}
template<class Ch, class Tr> _UCXXEXPORT basic_ostream<Ch, Tr>&
operator<<(basic_ostream<Ch, Tr>& os, const __setfill s)
{
os.fill(s.character);
return os;
}
template<class Ch, class Tr> _UCXXEXPORT basic_ostream<Ch, Tr>&
operator<<(basic_ostream<Ch, Tr>& os, const __setprecision s)
{
os.precision(s.digits);
return os;
}
template<class Ch, class Tr> _UCXXEXPORT basic_ostream<Ch, Tr>&
operator<<(basic_ostream<Ch, Tr>& os, const __setw s)
{
os.width(s.width);
return os;
}
}
#pragma GCC visibility pop
#endif
branches/meklort/i386/modules/include/numeric
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*Copyright (C) 2004 Garrett A. Kajmowicz
This file is part of the uClibc++ Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <basic_definitions>
#include <exception>
#ifndef __STD_NUMERIC_HEADER
#define __STD_NUMERIC_HEADER 1
#pragma GCC visibility push(default)
namespace std{
template <class InputIterator, class T> _UCXXEXPORT
T accumulate(InputIterator first, InputIterator last, T init)
{
while(first != last){
init = init + *first;
++first;
}
return init;
}
template <class InputIterator, class T, class BinaryOperation> _UCXXEXPORT
T accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op)
{
while(first != last){
init = binary_op(init, *first);
++first;
}
return init;
}
template <class InputIterator1, class InputIterator2, class T> _UCXXEXPORT
T inner_product(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init)
{
while(first1 != last1){
init = init + *first1 * *first2;
++first1;
++first2;
}
return init;
}
template <class InputIterator1, class InputIterator2, class T,
class BinaryOperation1, class BinaryOperation2> _UCXXEXPORT
T inner_product(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init,
BinaryOperation1 binary_op1,
BinaryOperation2 binary_op2)
{
while(first1 != last1){
init = binary_op1(init, binary_op2(*first1, *first2));
++first1;
++first2;
}
return init;
}
template <class InputIterator, class OutputIterator> _UCXXEXPORT
OutputIterator partial_sum(InputIterator first, InputIterator last,
OutputIterator result)
{
OutputIterator temp(result);
*result = *first;
++first;
++result;
while(first != last){
*result = *first + *temp;
temp = result;
++first;
++result;
}
return result;
}
template <class InputIterator, class OutputIterator, class BinaryOperation> _UCXXEXPORT
OutputIterator partial_sum(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation binary_op)
{
OutputIterator temp(result);
*result = *first;
++first;
++result;
while(first != last){
*result = binary_op(*first, *temp);
temp = result;
++first;
++result;
}
return result;
}
template <class InputIterator, class OutputIterator> _UCXXEXPORT
OutputIterator
adjacent_difference(InputIterator first, InputIterator last,
OutputIterator result)
{
OutputIterator temp(first);
*result = *first;
++first;
++result;
while(first != last){
*result = *first - *temp;
temp = first;
++first;
++result;
}
return result;
}
template <class InputIterator, class OutputIterator, class BinaryOperation> _UCXXEXPORT
OutputIterator
adjacent_difference(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation binary_op)
{
OutputIterator temp(first);
*result = *first;
++first;
++result;
while(first != last){
*result = binary_op(*first, *temp);
temp = first;
++first;
++result;
}
return result;
}
}
#pragma GCC visibility pop
#endif
branches/meklort/i386/modules/include/utility
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*Copyright (C) 2004 Garrett A. Kajmowicz
This file is part of the uClibc++ Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <basic_definitions>
#ifndef __STD_HEADER_UTILITY
#define __STD_HEADER_UTILITY 1
#pragma GCC visibility push(default)
namespace std{
namespace rel_ops {
template<class T> inline bool operator!=(const T& x, const T& y){
return !(x == y);
}
template<class T> inline bool operator> (const T& x, const T& y){
return ( y < x);
}
template<class T> inline bool operator<=(const T& x, const T& y){
return !( y < x );
}
template<class T> inline bool operator>=(const T& x, const T& y){
return !(x < y);
}
}
template <class T1, class T2> struct _UCXXEXPORT pair {
typedef T1 first_type;
typedef T2 second_type;
T1 first;
T2 second;
pair() : first(), second() { }
pair(const T1& x, const T2& y) : first(x), second(y) { }
template<class U, class V> pair(const pair<U, V> &p) : first(p.first), second(p.second) { }
};
template <class T1, class T2> bool operator==(const pair<T1,T2>& x, const pair<T1,T2>& y){
using namespace rel_ops;
return (x.first == y.first && x.second==y.second);
}
template <class T1, class T2> bool operator< (const pair<T1,T2>& x, const pair<T1,T2>& y){
return x.first < y.first || (!(y.first < x.first) && x.second < y.second);
}
template <class T1, class T2> bool operator!=(const pair<T1,T2>& x, const pair<T1,T2>& y){
return !(x == y);
}
template <class T1, class T2> bool operator> (const pair<T1,T2>& x, const pair<T1,T2>& y){
return y < x;
}
template <class T1, class T2> bool operator>=(const pair<T1,T2>& x, const pair<T1,T2>& y){
return !(x < y);
}
template <class T1, class T2> bool operator<=(const pair<T1,T2>& x, const pair<T1,T2>& y){
return !(y < x);
}
template <class T1, class T2> pair<T1,T2> make_pair(const T1& x, const T2& y){
return pair<T1,T2>(x, y);
}
}
#pragma GCC visibility pop
#endif//__STD_HEADER_UTILITY
branches/meklort/i386/modules/include/cwchar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*Copyright (C) 2006 Garrett A. Kajmowicz
This file is part of the uClibc++ Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation version 2.1
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <wchar.h>
#include <basic_definitions>
#ifndef __HEADER_CWCHAR
#define __HEADER_CWCHAR 1
namespace std{
using ::mbstate_t;
using ::wint_t;
using ::btowc;
using ::fgetwc;
using ::fgetws;
using ::fputwc;
using ::fputws;
using ::fwide;
using ::fwprintf;
using ::fwscanf;
using ::getwc;
using ::getwchar;
using ::mbrlen;
using ::mbrtowc;
using ::mbsinit;
using ::mbsrtowcs;
using ::putwc;
using ::putwchar;
using ::swprintf;
using ::swscanf;
using ::ungetwc;
using ::vfwprintf;
using ::vswprintf;
using ::vwprintf;
using ::wcrtomb;
using ::wcscat;
using ::wcschr;
using ::wcscmp;
using ::wcscoll;
using ::wcscpy;
using ::wcscspn;
using ::wcsftime;
using ::wcslen;
using ::wcsncat;
using ::wcsncmp;
using ::wcsncpy;
using ::wcspbrk;
using ::wcsrchr;
using ::wcsrtombs;
using ::wcsspn;
using ::wcsstr;
using ::wcstod;
using ::wcstok;
using ::wcstol;
using ::wcstoul;
using ::wcsxfrm;
using ::wctob;
using ::wmemchr;
using ::wmemcmp;
using ::wmemcpy;
using ::wmemmove;
using ::wmemset;
using ::wprintf;
using ::wscanf;
}
#endif
branches/meklort/i386/modules/include/type_traits
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*Copyright (C) 2005 Garrett A. Kajmowicz
This file is part of the uClibc++ Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <basic_definitions>
#include <string.h>
#include <exception>
#include <memory>
#include <char_traits>
#ifndef __HEADER_TYPE_TRAITS
#define __HEADER_TYPE_TRAITS 1
#pragma GCC visibility push(default)
namespace std{
struct _UCXXEXPORT __true_type{};
struct _UCXXEXPORT __false_type{};
template <class I> class _UCXXEXPORT __is_integer{
public:
typedef __false_type value;
};
template <> class _UCXXEXPORT __is_integer <unsigned int>{
public:
typedef __true_type value;
};
template <> class _UCXXEXPORT __is_integer <signed int>{
public:
typedef __true_type value;
};
template <> class _UCXXEXPORT __is_integer <short unsigned int>{
public:
typedef __true_type value;
};
template <> class _UCXXEXPORT __is_integer <short signed int>{
public:
typedef __true_type value;
};
template <> class _UCXXEXPORT __is_integer <char>{
public:
typedef __true_type value;
};
template <> class _UCXXEXPORT __is_integer <signed char>{
public:
typedef __true_type value;
};
template <> class _UCXXEXPORT __is_integer <unsigned char>{
public:
typedef __true_type value;
};
template <> class _UCXXEXPORT __is_integer <long unsigned int>{
public:
typedef __true_type value;
};
template <> class _UCXXEXPORT __is_integer <long signed int>{
public:
typedef __true_type value;
};
}
#pragma GCC visibility pop
#endif
branches/meklort/i386/modules/include/memory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*Copyright (C) 2004 Garrett A. Kajmowicz
This file is part of the uClibc++ Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <new>
#include <cstddef>
#include <cstdlib>
#include <iterator_base>
#include <utility>
#include <cstdio>
#ifndef HEADER_STD_MEMORY
#define HEADER_STD_MEMORY 1
#pragma GCC visibility push(default)
namespace std{
template <class T> class allocator;
// Specialize for void:
template <> class _UCXXEXPORT allocator<void> {
public:
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
template <class U> struct rebind { typedef allocator<U> other; };
};
template <class T> class _UCXXEXPORT allocator{
public:
typedef T value_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
pointer address(reference r) const { return &r; }
const_pointer address(const_reference r) const { return &r; }
allocator() throw(){}
template <class U> allocator(const allocator<U>& ) throw();
~allocator() throw(){}
//Space for n Ts
pointer allocate(size_type n, typename allocator<void>::const_pointer = 0){
return (T*)(::operator new( n * sizeof(T) ));
}
void deallocate(pointer p, size_type){
::operator delete(p);
}
//Use placement new to engage the constructor
void construct(pointer p, const T& val) { new((void*)p) T(val); }
void destroy(pointer p){ ((T*)p)->~T(); }//Call destructor
size_type max_size() const throw();
template<class U> struct rebind { typedef allocator<U> other; };
};
template <class Out, class T> class _UCXXEXPORT raw_storage_iterator
: public iterator<output_iterator_tag, void, void, void, void>
{
Out p;
public:
explicit raw_storage_iterator(Out pp) : p (pp) { }
raw_storage_iterator & operator*() { return *this; }
raw_storage_iterator & operator=(const T& val) {
T* pp = &*p;
new(pp) T(val);
return *this;
}
raw_storage_iterator & operator++() { ++p; return *this; }
raw_storage_iterator operator++(int) {
raw_storage_iterator t = *this;
++p;
return t;
}
};
template <class T> _UCXXEXPORT pair<T*, ptrdiff_t> get_temporary_buffer(ptrdiff_t n){
pair<T*, ptrdiff_t> retval;
retval.first = static_cast<T*>(malloc(n * sizeof(T)));
if(retval.first == 0){
retval.second = 0;
}else{
retval.second = n;
}
return retval;
}
template <class T> _UCXXEXPORT void return_temporary_buffer(T* p){
free(p);
}
template <class T> class _UCXXEXPORT auto_ptr{
private:
T * object;
template <class Y> struct auto_ptr_ref{
Y * p;
};
public:
typedef T element_type;
explicit auto_ptr(T* p =0) throw() : object(p){ }
auto_ptr(auto_ptr& p) throw() : object(p.release()){ }
auto_ptr(auto_ptr_ref<T> r) throw() : object(r.p){
r.p = 0;
}
template<class Y> auto_ptr(auto_ptr<Y>& p) throw() : object(p.release()){ }
auto_ptr& operator=(auto_ptr& p) throw(){
if(&p == this){
return *this;
}
delete object;
object = p.release();
return *this;
}
template<class Y> auto_ptr& operator=(auto_ptr<Y>& p) throw(){
if(&p == this){
return *this;
}
delete object;
object = p.release();
return *this;
}
~auto_ptr(){
delete object;
}
T& operator*() const throw(){
return *object;
}
T* operator->() const throw(){
return object;
}
T* get() const throw(){
return object;
}
T* release() throw(){
T * temp(object);
object = 0;
return temp;
}
void reset(T * p=0) throw(){
if(p != object){
delete object;
object = p;
}
}
template<class Y> operator auto_ptr_ref<Y>() throw(){
auto_ptr_ref<Y> retval;
retval.p = object;
object = 0;
return retval;
}
template<class Y> operator auto_ptr<Y>() throw(){
auto_ptr<Y> retval(object);
object = 0;
return retval;
}
};
}//namespace std
#pragma GCC visibility pop
#endif
branches/meklort/i386/modules/include/modules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
extern "C" {
/*
* Module Loading functionality
* Copyright 2009 Evan Lojewski. All rights reserved.
*
*/
#include <mach-o/loader.h>
#include <mach-o/nlist.h>
// There is a bug with the module system / rebasing / binding
// that causes static variables to be incorrectly rebased or bound
// Disable static variables for the moment
// #define static
#ifndef __BOOT_MODULES_H
#define __BOOT_MODULES_H
#define SYMBOLS_MODULE "Symbols.dylib"
#define SYMBOL_LOOKUP_SYMBOL"_lookup_symbol"
#define STUB_ENTRY_SIZE6
#define SECT_NON_LAZY_SYMBOL_PTR"__nl_symbol_ptr"
#define SECT_SYMBOL_STUBS"__symbol_stub"
#define VALID_FUNCTION(__x__)(__x__ && (void*)__x__ != (void*)0xFFFFFFFF)
extern unsigned long long textAddress;
extern unsigned long long textSection;
typedef struct symbolList_t
{
char* symbol;
unsigned int addr;
struct symbolList_t* next;
} symbolList_t;
typedef struct moduleList_t
{
char* module;
unsigned int version;
unsigned int compat;
struct moduleList_t* next;
} moduleList_t;
typedef struct callbackList_t
{
void(*callback)(void*, void*, void*, void*);
struct callbackList_t* next;
} callbackList_t;
typedef struct moduleHook_t
{
const char* name;
callbackList_t* callbacks;
struct moduleHook_t* next;
} moduleHook_t;
int init_module_system();
void load_all_modules();
/*
* Modules Interface
* execute_hook
*Exexutes a registered hook. All callbaks are
*called in the same order that they were added
*
* register_hook_callback
*registers a void function to be executed when a
*hook is executed.
*/
int execute_hook(const char* name, void*, void*, void*, void*);
void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));
int load_module(char* module);
int is_module_loaded(const char* name);
void module_loaded(const char* name/*, uint32_t version, uint32_t compat*/);
long long add_symbol(char* symbol, long long addr, char is64);
void* parse_mach(void* binary,
int(*dylib_loader)(char*),
long long(*symbol_handler)(char*, long long, char)
);
unsigned int handle_symtable(uint32_t base, struct symtab_command* symtabCommand,
long long(*symbol_handler)(char*, long long, char),
char is64);
unsigned int lookup_all_symbols(const char* name);
int replace_function(const char* symbol, void* newAddress);
//extern unsigned int (*lookup_symbol)(const char*);
#endif /* __BOOT_MODULES_H */
}
branches/meklort/i386/modules/include/set.old
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
/*Copyright (C) 2004 Garrett A. Kajmowicz
This file is part of the uClibc++ Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include<memory>
#include<utility>
#include<iterator>
#include <deque>
#include<functional>
#ifndef __STD_HEADER_SET
#define __STD_HEADER_SET
#pragma GCC visibility push(default)
namespace std{
template<class Key, class Compare = less<Key>, class Allocator = allocator<Key> > class __base_set;
template<class Key, class Compare = less<Key>, class Allocator = allocator<Key> > class set;
template<class Key, class Compare = less<Key>, class Allocator = allocator<Key> > class multiset;
template<class Key, class Compare, class Allocator> class __set_iter;
template<class Key, class Compare, class Allocator> class __set_citer;
template <class Key, class Compare, class Allocator> bool operator==
(const set<Key, Compare, Allocator>& x, const set<Key, Compare, Allocator>& y);
template <class Key, class Compare, class Allocator> bool operator==
(const multiset<Key,Compare,Allocator>& x, const multiset<Key,Compare,Allocator>& y);
/* The code for the set containers is split up into two classes.
* The first class, __base_set holds all of the data and does much of the iterator-based
* work. Then the classes set and multiset inherit from there. This was done to reduce
* the redundancy of code (And thus errors which might crop up), as well as possibly
* reducing the size of binaries if both set and multiset are used, along with the same
* template parameters.
*/
//All base classes first (__base_set, iterators, value_compare) and it's associated code
template<class Key, class Compare, class Allocator> class _UCXXEXPORT __base_set{
protected:
friend class __set_iter<Key, Compare, Allocator>;
friend class __set_citer<Key, Compare, Allocator>;
friend bool operator==<>(const set<Key, Compare, Allocator>& x, const set<Key, Compare, Allocator>& y);
friend bool operator==<>(const multiset<Key, Compare, Allocator>& x, const multiset<Key, Compare, Allocator>& y);
public:
typedef __base_set<Key, Compare, Allocator>set_type;
typedef Keykey_type;
typedef Keyvalue_type;
typedef Comparekey_compare;
typedef Allocatorallocator_type;
typedef typename Allocator::referencereference;
typedef typename Allocator::const_referenceconst_reference;
typedef __set_iter<Key, Compare, Allocator>iterator;
typedef __set_citer<Key, Compare, Allocator>const_iterator;
typedef typename Allocator::size_typesize_type;
typedef typename Allocator::difference_typedifference_type;
typedef typename Allocator::pointerpointer;
typedef typename Allocator::const_pointerconst_pointer;
typedef typename std::reverse_iterator<iterator>reverse_iterator;
typedef typename std::reverse_iterator<const_iterator>const_reverse_iterator;
class value_compare;
explicit __base_set(const Compare& comp = Compare(), const Allocator& al = Allocator());
__base_set(const set_type& x);
~__base_set();
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
bool empty() const;
size_type size() const;
size_type max_size() const;
void swap(set_type & x);
void clear();
key_compare key_comp() const;
protected:
deque<Key, allocator<Key> > data;
Compare c;
};
//Implementations
template<class Key, class Compare, class Allocator> class _UCXXEXPORT __set_citer
: public std::iterator<
bidirectional_iterator_tag,
Key,
typename Allocator::difference_type,
typename Allocator::pointer,
typename Allocator::reference
>
{
protected:
typedef class __base_set<Key, Compare, Allocator> Set;
friend class __base_set<Key, Compare, Allocator>;
friend class __base_set<Key, Compare, Allocator>::iterator;
friend class set<Key, Compare, Allocator>;
friend class multiset<Key, Compare, Allocator>;
typename Set::size_type element;
const Set * container;
public:
__set_citer() : element(0), container(0) { }
__set_citer(const typename Set::const_iterator & m)
: element(m.element), container(m.container) { }
__set_citer(typename Set::size_type e, const Set * const c)
: element(e), container(c) { }
~__set_citer() { }
typename Set::value_type operator*(){
return container->data[element];
}
const typename Set::value_type * operator->() const{
return &(container->data[element]);
}
__set_citer & operator=(const typename Set::const_iterator & m){
element = m.element;
container = m.container;
return *this;
}
bool operator==(const typename Set::const_iterator & m) const {
return (m.element == element && m.container == container);
}
bool operator!=(const typename Set::const_iterator & m) const {
return (m.element != element || m.container != container);
}
__set_citer & operator++(){
++element;
return *this;
}
__set_citer operator++(int){
__set_citer temp(*this);
++element;
return temp;
}
__set_citer & operator--(){
--element;
return *this;
}
__set_citer operator--(int){
__set_citer temp(*this);
--element;
return temp;
}
};
template<class Key, class Compare, class Allocator> class _UCXXEXPORT __set_iter
: public std::iterator<
bidirectional_iterator_tag,
Key,
typename Allocator::difference_type,
typename Allocator::pointer,
typename Allocator::reference
>
{
protected:
typedef __base_set<Key, Compare, Allocator> Set;
//FIXME - Find a way to use template parameters or something. This will do for now
friend class __base_set<Key, Compare, Allocator>;
friend class __base_set<Key, Compare, Allocator>::const_iterator;
friend class set<Key, Compare, Allocator>;
friend class multiset<Key, Compare, Allocator>;
typename Set::size_type element;
Set * container;
public:
__set_iter() : element(0), container(0) { }
__set_iter(const typename Set::iterator & m)
: element(m.element), container(m.container) { }
__set_iter(typename Set::size_type e, Set * c)
: element(e), container(c) { }
~__set_iter() { }
typename Set::value_type & operator*(){
return container->data[element];
}
const typename Set::value_type & operator*() const{
return container->data[element];
}
typename Set::value_type * operator->(){
return &(container->data[element]);
}
__set_iter & operator=(const typename Set::iterator & m){
element = m.element;
container = m.container;
return *this;
}
bool operator==(const typename Set::iterator & m) const {
return (m.element == element && m.container == container);
}
bool operator!=(const typename Set::iterator & m) const {
return (m.element != element || m.container != container);
}
bool operator==(const typename Set::const_iterator & m) const {
return (m.element == element && m.container == container);
}
bool operator!=(const typename Set::const_iterator & m) const {
return (m.element != element || m.container != container);
}
__set_iter & operator++(){
++element;
return *this;
}
__set_iter operator++(int){
__set_iter temp(*this);
++element;
return temp;
}
__set_iter & operator--(){
--element;
return *this;
}
__set_iter operator--(int){
__set_iter temp(*this);
--element;
return temp;
}
//Conversion operator
operator typename Set::const_iterator () const
{
typename Set::const_iterator retval(element, container);
//return typename Set::const_iterator(element, container);
return retval;
}
};
//Compare the keys of the two items
template<class Key, class Compare, class Allocator> class _UCXXEXPORT
__base_set<Key, Compare, Allocator>::value_compare : public binary_function<
typename set<Key, Compare, Allocator>::value_type,
typename set<Key, Compare, Allocator>::value_type,
bool>
{
friend class __base_set<Key, Compare, Allocator>;
protected:
Compare comp;
value_compare(Compare c) : comp(c) { }
~value_compare() { }
public:
bool operator()(const value_type& x, const value_type& y) const {
return comp(x, y);
}
};
template <class Key, class Compare, class Allocator>
__base_set<Key, Compare, Allocator>::__base_set(const Compare& comp, const Allocator&)
: data(), c(comp)
{
}
template <class Key, class Compare, class Allocator>
__base_set<Key, Compare, Allocator>::__base_set(const __base_set<Key, Compare, Allocator>& x)
: data(x.data), c(x.c)
{
}
template <class Key, class Compare, class Allocator>
__base_set<Key, Compare, Allocator>::~__base_set()
{
}
template <class Key, class Compare, class Allocator>
typename __base_set<Key, Compare, Allocator>::iterator
__base_set<Key, Compare, Allocator>::begin()
{
return iterator(0, this);
}
template <class Key, class Compare, class Allocator>
typename __base_set<Key, Compare, Allocator>::const_iterator
__base_set<Key, Compare, Allocator>::begin() const
{
return const_iterator(0, this);
}
template <class Key, class Compare, class Allocator>
typename __base_set<Key, Compare, Allocator>::iterator
__base_set<Key, Compare, Allocator>::end()
{
return iterator(data.size(), this);
}
template <class Key, class Compare, class Allocator>
typename __base_set<Key, Compare, Allocator>::const_iterator
__base_set<Key, Compare, Allocator>::end() const
{
return const_iterator(data.size(), this);
}
template <class Key, class Compare, class Allocator>
typename __base_set<Key, Compare, Allocator>::reverse_iterator
__base_set<Key, Compare, Allocator>::rbegin()
{
return reverse_iterator(end());
}
template <class Key, class Compare, class Allocator>
typename __base_set<Key, Compare, Allocator>::const_reverse_iterator
__base_set<Key, Compare, Allocator>::rbegin() const
{
return const_reverse_iterator(end());
}
template <class Key, class Compare, class Allocator>
typename __base_set<Key, Compare, Allocator>::reverse_iterator
__base_set<Key, Compare, Allocator>::rend()
{
return reverse_iterator(begin());
}
template <class Key, class Compare, class Allocator>
typename __base_set<Key, Compare, Allocator>::const_reverse_iterator
__base_set<Key, Compare, Allocator>::rend() const
{
return const_reverse_iterator(begin());
}
template <class Key, class Compare, class Allocator>
bool __base_set<Key, Compare, Allocator>::empty() const
{
return (data.size() == 0);
}
template <class Key, class Compare, class Allocator>
typename __base_set<Key, Compare, Allocator>::size_type
__base_set<Key, Compare, Allocator>::size() const
{
return data.size();
}
template <class Key, class Compare, class Allocator>
typename __base_set<Key, Compare, Allocator>::size_type
__base_set<Key, Compare, Allocator>::max_size() const
{
return data.max_size();
}
template <class Key, class Compare, class Allocator>
void __base_set<Key, Compare, Allocator>::swap(__base_set<Key, Compare, Allocator>& m)
{
Compare n = c;
c = m.c;
m.c = n;
data.swap(m.data);
}
template <class Key, class Compare, class Allocator>
void __base_set<Key, Compare, Allocator>::clear()
{
data.clear();
}
template <class Key, class Compare, class Allocator>
typename __base_set<Key, Compare, Allocator>::key_compare
__base_set<Key, Compare, Allocator>::key_comp() const
{
return c;
}
//value_compare value_comp() const;
/* This is the implementation for the set container. As noted above, it deviates
* from ISO spec by deriving from a base class in order to reduce code redundancy.
* More code could be reduced by convirting to virtual functions (thus allowing
* much of the erase and insert code to be duplicated), but that would deviate from
* the specifications too much to be worth the risk.
*/
//Implementation of set
template<class Key, class Compare, class Allocator> class _UCXXEXPORT set
: public __base_set<Key, Compare, Allocator>
{
//Default value of allocator does not meet C++ standard specs, but it works for this library
//Deal with it
public:
typedef__base_set<Key, Compare, Allocator>base;
typedef typename base::key_typekey_type;
typedef typename base::value_typevalue_type;
typedef typename base::key_comparekey_compare;
typedef typename base::allocator_typeallocator_type;
typedef typename base::referencereference;
typedef typename base::const_referenceconst_reference;
typedef typename base::iteratoriterator;
typedef typename base::const_iteratorconst_iterator;
typedef typename base::size_typesize_type;
typedef typename base::difference_typedifference_type;
typedef typename base::pointerpointer;
typedef typename base::const_pointerconst_pointer;
typedef typename base::reverse_iteratorreverse_iterator;
typedef typename base::const_reverse_iteratorconst_reverse_iterator;
using base::value_compare;
explicit set(const Compare& comp = Compare(), const Allocator& al = Allocator())
: base(comp, al) { }
template <class InputIterator> set(InputIterator first, InputIterator last,
const Compare& comp = Compare(), const Allocator& = Allocator());
set(const set<Key, Compare,Allocator>& x) : base(x) { }
~set() { }
set<Key, Compare, Allocator>& operator=(const set<Key, Compare, Allocator>& x);
pair<iterator, bool> insert(const value_type& x);
iterator insert(iterator position, const value_type& x);
template <class InputIterator> void insert(InputIterator first, InputIterator last);
void erase(iterator position);
size_type erase(const key_type& x);
void erase(iterator first, iterator last);
using base::begin;
using base::end;
using base::rbegin;
using base::rend;
using base::empty;
using base::size;
using base::max_size;
iterator find(const key_type& x);
const_iterator find(const key_type& x) const;
size_type count(const key_type& x) const;
iterator lower_bound(const key_type& x);
const_iterator lower_bound(const key_type& x) const;
iterator upper_bound(const key_type& x);
const_iterator upper_bound(const key_type& x) const;
pair<iterator,iterator> equal_range(const key_type& x);
pair<const_iterator,const_iterator> equal_range(const key_type& x) const;
protected:
friend class base::iterator;
friend class base::const_iterator;
iterator ifind(const key_type& x); //Core find functionality
const_iterator ifind(const key_type& x) const; //Core find functionality
using base::data;
using base::c;
};
template <class Key, class Compare, class Allocator> template <class InputIterator>
set<Key, Compare, Allocator>::
set(InputIterator first, InputIterator last, const Compare& comp, const Allocator& al)
: base(comp, al)
{
while(first !=last){
insert(*first);
++first;
}
}
template <class Key, class Compare, class Allocator>
typename set<Key, Compare, Allocator>::iterator
set<Key, Compare, Allocator>::ifind(const key_type &x)
{
/* This function is not from the standard. It is an internal
* utility function which returns an iterator to either the
* first matching element, or to the element before which
* an insert should be performed. Will not indicate if the
*insert should be performed before the first element
*/
if(data.size() == 0){
return end();
}
if(data.size() == 1){
if( c(data[0], x) ){
return end();
}
return begin();
}
size_type low;
size_type high;
size_type i;
low = 0;
high = data.size() - 1;
//This algorithm assumes no duplicates in stored information
while(( high - low) > 1){
i = low + ((high - low) /2);
if( c(x, data[i]) ){
high = i;
}else{
low = i;
}
}
if( c(data[low], x) ){ // k >=high
i = high;
}else{
i = low;
}
return iterator(i, this);
}
template <class Key, class Compare, class Allocator>
typename set<Key, Compare, Allocator>::const_iterator
set<Key, Compare, Allocator>::ifind(const key_type &x) const
{
/* This function is not from the standard. It is an internal
* utility function which returns an iterator to either the
* first matching element, or to the element before which
* an insert should be performed. Will not indicate if the
*insert should be performed before the first element
*/
if(data.size() == 0){
return end();
}
if(data.size() == 1){
if( c(data[0], x) ){
return end();
}
return begin();
}
size_type low;
size_type high;
size_type i;
low = 0;
high = data.size() - 1;
//This algorithm assumes no duplicates in stored information
while(( high - low) > 1){
i = low + ((high - low) /2);
if( c(x, data[i]) ){
high = i;
}else{
low = i;
}
}
if( c(data[low], x) ){ // k >=high
i = high;
}else{
i = low;
}
return const_iterator(i, this);
}
template <class Key, class Compare, class Allocator>
set<Key, Compare, Allocator>::set<Key, Compare, Allocator>&
set<Key, Compare, Allocator>::operator=(const set<Key, Compare, Allocator>& x)
{
if( &x == this){
return *this;
}
c = x.c;
data = x.data;
return *this;
}
template <class Key, class Compare, class Allocator>
pair<typename set<Key, Compare, Allocator>::iterator, bool>
set<Key, Compare, Allocator>::insert(const value_type& x)
{
pair<typename set<Key, Compare, Allocator>::iterator, bool> retval;
//Either set is empty or element to insert goes at the begining
if(data.size() == 0 || c(x, data[0]) ){
data.push_front(x);
retval.first = begin();
retval.second = true;
return retval;
}
//Element to insert goes at the end
if( c(data[data.size() - 1], x) ){
data.push_back(x);
retval.first = end();
--retval.first;
retval.second = true;
return retval;
}
retval.first = ifind(x);
//No match - this should never happen
if(retval.first == end()){
retval.second = false;
return retval;
}
//If we have an exact match
if( !c( *(retval.first), x) && !c(x, *(retval.first) ) ){
retval.second = false;
return retval;
}
typename deque<Key, allocator<Key > >::iterator q(&data, retval.first.element);
data.insert(q, x);
retval.first = ifind(x); //Need to refind because insert can move data around
retval.second = true;
return retval;
}
template <class Key, class Compare, class Allocator>
typename set<Key, Compare, Allocator>::iterator
set<Key, Compare, Allocator>::insert(iterator position, const value_type& x)
{
//Just reusing code. It's hard to make improvements over existing algo.
insert(x);
return find(x);
}
template <class Key, class Compare, class Allocator>
template <class InputIterator> void
set<Key, Compare, Allocator>::insert(InputIterator first, InputIterator last)
{
while(first !=last){
insert(*first);
++first;
}
}
template <class Key, class Compare, class Allocator> void
set<Key, Compare, Allocator>::erase(iterator position)
{
//Create a deque iterator from position information and then
//Use built in erase feature because it is handy.
typename deque<Key, allocator<Key> >::iterator pos(&data, position.element);
data.erase(pos);
}
template <class Key, class Compare, class Allocator>
typename set<Key, Compare, Allocator>::size_type
set<Key, Compare, Allocator>::erase(const key_type& x)
{
typename set<Key, Compare, Allocator>::iterator i = find(x);
if(i!=end()){
erase(i);
return 1;
}
return 0;
}
template <class Key, class Compare, class Allocator>
void set<Key, Compare, Allocator>::erase(iterator first, iterator last)
{
typename deque<Key, allocator<Key> >::iterator f(&data, first.element);
typename deque<Key, allocator<Key> >::iterator l(&data, last.element);
data.erase(f, l);
}
template <class Key, class Compare, class Allocator>
typename set<Key, Compare, Allocator>::iterator
set<Key, Compare, Allocator>::
find(const typename set<Key, Compare, Allocator>::key_type& x)
{
if(data.size() == 0){
return end();
}
iterator retval = ifind(x);
if(retval == end()){
return retval;
}
//Make sure we have an exact match....
if(!c( *retval, x) && !c(x, *retval )){
return retval;
}
return end();
}
template <class Key, class Compare, class Allocator>
typename set<Key, Compare, Allocator>::const_iterator
set<Key, Compare, Allocator>::find(const key_type& x) const
{
if(data.size() == 0){
return end();
}
const_iterator retval = ifind(x);
if(retval == end()){
return retval;
}
//Make sure we have an exact match....
if(!c( *retval, x) && !c(x, *retval )){
return retval;
}
return end();
}
template <class Key, class Compare, class Allocator>
typename set<Key, Compare, Allocator>::size_type
set<Key, Compare, Allocator>::count(const typename set<Key, Compare, Allocator>::key_type& x) const
{
if( find(x) == end()){
return 0;
}
return 1;
}
template <class Key, class Compare, class Allocator>
typename set<Key, Compare, Allocator>::iterator
set<Key, Compare, Allocator>::lower_bound(const key_type& x)
{
return find(x);
}
template <class Key, class Compare, class Allocator>
typename set<Key, Compare, Allocator>::const_iterator
set<Key, Compare, Allocator>::lower_bound(const key_type& x) const
{
return find(x);
}
template <class Key, class Compare, class Allocator>
typename set<Key, Compare, Allocator>::iterator
set<Key, Compare, Allocator>::upper_bound(const key_type& x)
{
typename set<Key, Compare, Allocator>::iterator i = find(x);
if(i != end()){
++i;
}
return i;
}
template <class Key, class Compare, class Allocator>
typename set<Key, Compare, Allocator>::const_iterator
set<Key, Compare, Allocator>::upper_bound(const key_type& x) const
{
typename set<Key, Compare, Allocator>::const_iterator i = find(x);
if(i != end()){
++i;
}
return i;
}
template <class Key, class Compare, class Allocator>
pair<typename set<Key, Compare, Allocator>::iterator,
typename set<Key, Compare, Allocator>::iterator
> set<Key, Compare, Allocator>::equal_range(const key_type& x)
{
pair< typename set<Key, Compare, Allocator>::iterator,
typename set<Key, Compare, Allocator>::iterator
> retval;
retval.first = lower_bound(x);
retval.second = upper_bound(x);
return retval;
}
template <class Key, class Compare, class Allocator>
pair<typename set<Key, Compare, Allocator>::const_iterator,
typename set<Key, Compare, Allocator>::const_iterator
> set<Key, Compare, Allocator>::equal_range(const key_type& x) const
{
pair< typename set<Key, Compare, Allocator>::const_iterator,
typename set<Key, Compare, Allocator>::const_iterator
> retval;
retval.first = lower_bound(x);
retval.second = upper_bound(x);
return retval;
}
template <class Key, class Compare, class Allocator> bool operator==
(const set<Key, Compare, Allocator>& x, const set<Key, Compare, Allocator>& y)
{
if(x.data == y.data){
return true;
}
return false;
}
//Implementation of multiset
template<class Key, class Compare, class Allocator> class _UCXXEXPORT multiset
: public __base_set<Key, Compare, Allocator>
{
//Default value of allocator does not meet C++ standard specs, but it works for this library
//Deal with it
public:
typedef__base_set<Key, Compare, Allocator>base;
typedef typename base::key_typekey_type;
typedef typename base::value_typevalue_type;
typedef typename base::key_comparekey_compare;
typedef typename base::allocator_typeallocator_type;
typedef typename base::referencereference;
typedef typename base::const_referenceconst_reference;
typedef typename base::iteratoriterator;
typedef typename base::const_iteratorconst_iterator;
typedef typename base::size_typesize_type;
typedef typename base::difference_typedifference_type;
typedef typename base::pointerpointer;
typedef typename base::const_pointerconst_pointer;
typedef typename base::reverse_iteratorreverse_iterator;
typedef typename base::const_reverse_iteratorconst_reverse_iterator;
explicit multiset(const Compare& comp = Compare(), const Allocator& al = Allocator())
: base(comp, al) { }
template <class InputIterator> multiset(InputIterator first, InputIterator last,
const Compare& comp = Compare(), const Allocator& = Allocator());
multiset(const multiset<Key, Compare, Allocator>& x) : base(x) { }
~multiset() { }
multiset<Key, Compare, Allocator>& operator=(const multiset<Key, Compare, Allocator>& x);
iterator insert(const value_type& x);
iterator insert(iterator position, const value_type& x);
template <class InputIterator> void insert(InputIterator first, InputIterator last);
void erase(iterator position);
size_type erase(const key_type& x);
void erase(iterator first, iterator last);
using base::begin;
using base::end;
using base::rbegin;
using base::rend;
using base::empty;
using base::size;
using base::max_size;
iterator find(const key_type& x);
const_iterator find(const key_type& x) const;
size_type count(const key_type& x) const;
iterator lower_bound(const key_type& x);
const_iterator lower_bound(const key_type& x) const;
iterator upper_bound(const key_type& x);
const_iterator upper_bound(const key_type& x) const;
pair<iterator,iterator> equal_range(const key_type& x);
pair<const_iterator,const_iterator> equal_range(const key_type& x) const;
protected:
friend class base::iterator;
friend class base::const_iterator;
iterator ifind(const key_type& x); //Core find functionality
const_iterator ifind(const key_type& x) const; //Core find functionality
using base::data;
using base::c;
};
template <class Key, class Compare, class Allocator> template <class InputIterator>
multiset<Key, Compare, Allocator>::
multiset(InputIterator first, InputIterator last, const Compare& comp, const Allocator& al)
: base(comp, al)
{
while(first !=last){
insert(*first);
++first;
}
}
template <class Key, class Compare, class Allocator>
typename multiset<Key, Compare, Allocator>::iterator
multiset<Key, Compare, Allocator>::ifind(const key_type &x)
{
/* This function is not from the standard. It is an internal
* utility function which returns an iterator to either the
* first matching element, or to the element before which
* an insert should be performed. end() for error.
*/
if(data.size() == 0){
return end();
}
//Before the first element
if( c(x, data[0]) ){
return begin();
}
//Element is larger than all known elemenst
if( c( data[data.size()-1], x) ){
return end();
}
//Or if it is the last element
if( !c(x, data[size()-1]) ){
return iterator(data.size()-1, this);
}
size_type low;
size_type high;
size_type i=0;
low = 0;
high = data.size() - 1;
//This algorithm will accept duplicates in keys
while( c(data[i+1], x) || c(x, data[i]) || !c(x, data[i+1]) ){
i = low + ((high - low) /2);
if( c( x, data[i]) ){
high = i;
}else{
low = i;
}
}
if( c(data[i], x) ){ // k >=high
++i;
}
return iterator(i, this);
}
template <class Key, class Compare, class Allocator>
typename multiset<Key, Compare, Allocator>::const_iterator
multiset<Key, Compare, Allocator>::ifind(const key_type &x) const
{
/* This function is not from the standard. It is an internal
* utility function which returns an iterator to either the
* first matching element, or to the element before which
* an insert should be performed. end() for error.
*/
if(data.size() == 0){
return end();
}
//Before the first element
if( c(x, data[0]) ){
return begin();
}
//Element is larger than all known elemenst
if( c( data[data.size()-1], x) ){
return end();
}
//Or if it is the last element
if( !c(x, data[size()-1]) ){
return const_iterator(data.size()-1, this);
}
size_type low;
size_type high;
size_type i=0;
low = 0;
high = data.size() - 1;
//This algorithm will accept duplicates in keys
while( c(data[i+1], x) || c(x, data[i]) || !c(x, data[i+1]) ){
i = low + ((high - low) /2);
if( c( x, data[i]) ){
high = i;
}else{
low = i;
}
}
if( c(data[i], x) ){ // k >=high
++i;
}
return const_iterator(i, this);
}
template <class Key, class Compare, class Allocator>
typename multiset<Key, Compare, Allocator>::iterator
multiset<Key, Compare, Allocator>::insert(const value_type &x)
{
iterator retval;
//Either set is empty or element to insert goes at the begining
if(data.size() == 0 || c(x, data[0]) ){
data.push_front(x);
return begin();
}
//Element to insert goes at the end
if( c(data[data.size() - 1], x) ){
data.push_back(x);
return end();
}
retval = ifind(x);
//No match - this should never happen
if(retval == end()){
return retval;
}
if( !c(x, *retval) ){
++retval;
}
typename deque<Key, allocator<Key> >::iterator q(&data, retval.element);
data.insert(q, x);
return retval;
}
template <class Key, class Compare, class Allocator>
typename multiset<Key, Compare, Allocator>::iterator
multiset<Key, Compare, Allocator>::insert(iterator position, const value_type& x)
{
//Inserting at begining
if(position == begin() && !c(*position, x) ){
data.push_front(x);
return position;
}
//Inserting at end
if(position == end() && !c(x, data[data.size() - 1]) ){
data.push_back(x);
return position;
}
//Inserting in middle
iterator temp = position;
--temp;
if( !c( *position, x) && !c(x, *temp) ){
typename deque<Key, allocator<Key> >::iterator q(&data, position.element);
data.insert(q, x);
return position;
}
return insert(x);
}
template <class Key, class Compare, class Allocator>
template <class InputIterator> void
multiset<Key, Compare, Allocator>::insert(InputIterator first, InputIterator last)
{
while(first !=last){
insert(*first);
++first;
}
}
template <class Key, class Compare, class Allocator> void
multiset<Key, Compare, Allocator>::erase(iterator position)
{
//Create a deque iterator from position information and then
//Use built in erase feature because it is handy.
typename deque<Key, allocator<Key> >::iterator pos(&data, position.element);
data.erase(pos);
}
template <class Key, class Compare, class Allocator>
typename multiset<Key, Compare, Allocator>::size_type
multiset<Key, Compare, Allocator>::erase(const key_type& x)
{
typename multiset<Key, Compare, Allocator>::iterator f = lower_bound(x);
typename multiset<Key, Compare, Allocator>::iterator l = upper_bound(x);
size_type t = l.element - f.element;
erase(f, l);
return t;
}
template <class Key, class Compare, class Allocator>
void multiset<Key, Compare, Allocator>::erase(iterator first, iterator last)
{
typename deque<Key, allocator<Key> >::iterator f(&data, first.element);
typename deque<Key, allocator<Key> >::iterator l(&data, last.element);
data.erase(f, l);
}
template <class Key, class Compare, class Allocator>
typename multiset<Key, Compare, Allocator>::iterator
multiset<Key, Compare, Allocator>::find(const key_type& x)
{
if(data.size() == 0){
return end();
}
iterator retval = ifind(x);
if( c(x, *retval) || c(*retval, x) ){
return end();
}
return retval;
}
template <class Key, class Compare, class Allocator>
typename multiset<Key, Compare, Allocator>::const_iterator
multiset<Key, Compare, Allocator>::find(const key_type& x) const
{
if(data.size() == 0){
return end();
}
const_iterator retval = ifind(x);
if( c(x, *retval) || c(*retval, x) ){
return end();
}
return retval;
}
template <class Key, class Compare, class Allocator>
typename multiset<Key, Compare, Allocator>::size_type
multiset<Key, Compare, Allocator>::
count(const typename multiset<Key, Compare, Allocator>::key_type& x) const
{
pair< typename multiset<Key, Compare, Allocator>::const_iterator,
typename multiset<Key, Compare, Allocator>::const_iterator
> temp = equal_range(x);
return temp.second.element - temp.first.element;
}
template <class Key, class Compare, class Allocator>
typename multiset<Key, Compare, Allocator>::iterator
multiset<Key, Compare, Allocator>::lower_bound(const key_type& x)
{
//FIXME - linear search - can we do any better?
typename multiset<Key, Compare, Allocator>::iterator i = find(x);
if(i == end()){
return i;
}
while( i.element > 0 && !c( *i, x) && !c(x, *i) ){
--i;
}
if( c(*i, x)){
++i;
}
return i;
}
template <class Key, class Compare, class Allocator>
typename multiset<Key, Compare, Allocator>::const_iterator
multiset<Key, Compare, Allocator>::lower_bound(const key_type& x) const
{
//FIXME - linear search - can we do any better?
typename multiset<Key, Compare, Allocator>::const_iterator i = find(x);
if(i == end()){
return i;
}
while( i.element >0 && !c( *i, x) && !c(x, *i) ){
--i;
}
if( c( *i, x)){
++i;
}
return i;
}
template <class Key, class Compare, class Allocator>
typename multiset<Key, Compare, Allocator>::iterator
multiset<Key, Compare, Allocator>::upper_bound(const key_type& x)
{
typename multiset<Key, Compare, Allocator>::iterator i = find(x);
if(i != end()){
++i;
}
return i;
}
template <class Key, class Compare, class Allocator>
typename multiset<Key, Compare, Allocator>::const_iterator
multiset<Key, Compare, Allocator>::upper_bound(const key_type& x) const
{
typename multiset<Key, Compare, Allocator>::const_iterator i = find(x);
if(i != end()){
++i;
}
return i;
}
template <class Key, class Compare, class Allocator>
pair<typename multiset<Key, Compare, Allocator>::iterator,
typename multiset<Key, Compare, Allocator>::iterator
> multiset<Key, Compare, Allocator>::equal_range(const key_type& x)
{
pair< typename multiset<Key, Compare, Allocator>::iterator,
typename multiset<Key, Compare, Allocator>::iterator
> retval;
retval.first = lower_bound(x);
retval.second = upper_bound(x);
return retval;
}
template <class Key, class Compare, class Allocator>
pair<typename multiset<Key, Compare, Allocator>::const_iterator,
typename multiset<Key, Compare, Allocator>::const_iterator
> multiset<Key, Compare, Allocator>::equal_range(const key_type& x) const
{
pair< typename multiset<Key, Compare, Allocator>::const_iterator,
typename multiset<Key, Compare, Allocator>::const_iterator
> retval;
retval.first = lower_bound(x);
retval.second = upper_bound(x);
return retval;
}
/* Non-member functions. These are at the end because they are not associated with any
particular class. These will be implemented as I figure out exactly what all of
them are supposed to do, and I have time.
*/
template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator<
(const set<Key,Compare,Allocator>& x, const set<Key,Compare,Allocator>& y)
{
typename set<Key,Compare,Allocator>::const_iterator first1 = x.begin();
typename set<Key,Compare,Allocator>::const_iterator first2 = y.begin();
typename set<Key,Compare,Allocator>::const_iterator last1 = x.end();
typename set<Key,Compare,Allocator>::const_iterator last2 = y.end();
while(first1 != last1 && first2 != last2){
if( *first1 < *first2 ){
return true;
}
if( *first2 < *first1 ){
return false;
}
++first1;
++first2;
}
return first1==last1 && first2 != last2;
}
template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator!=
(const set<Key,Compare,Allocator>& x, const set<Key,Compare,Allocator>& y)
{
typename set<Key,Compare,Allocator>::const_iterator first1 = x.begin();
typename set<Key,Compare,Allocator>::const_iterator first2 = y.begin();
typename set<Key,Compare,Allocator>::const_iterator last1 = x.end();
typename set<Key,Compare,Allocator>::const_iterator last2 = y.end();
while(first1 != last1 && first2 != last2){
if( *first1 != *first2 ){
return true;
}
++first1;
++first2;
}
return first1!=last1 || first2 != last2;
}
template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator>
(const set<Key,Compare,Allocator>& x, const set<Key,Compare,Allocator>& y)
{
typename set<Key,Compare,Allocator>::const_iterator first1 = x.begin();
typename set<Key,Compare,Allocator>::const_iterator first2 = y.begin();
typename set<Key,Compare,Allocator>::const_iterator last1 = x.end();
typename set<Key,Compare,Allocator>::const_iterator last2 = y.end();
while(first1 != last1 && first2 != last2){
if( *first1 > *first2 ){
return true;
}
if( *first2 > *first1 ){
return false;
}
++first1;
++first2;
}
return first1!=last1 && first2 == last2;
}
template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator>=
(const set<Key,Compare,Allocator>& x, const set<Key,Compare,Allocator>& y)
{
typename set<Key,Compare,Allocator>::const_iterator first1 = x.begin();
typename set<Key,Compare,Allocator>::const_iterator first2 = y.begin();
typename set<Key,Compare,Allocator>::const_iterator last1 = x.end();
typename set<Key,Compare,Allocator>::const_iterator last2 = y.end();
while(first1 != last1 && first2 != last2){
if( *first1 > *first2 ){
return true;
}
if( *first2 > *first1 ){
return false;
}
++first1;
++first2;
}
return first1!=last1;
}
template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator<=
(const set<Key,Compare,Allocator>& x, const set<Key,Compare,Allocator>& y)
{
typename set<Key,Compare,Allocator>::const_iterator first1 = x.begin();
typename set<Key,Compare,Allocator>::const_iterator first2 = y.begin();
typename set<Key,Compare,Allocator>::const_iterator last1 = x.end();
typename set<Key,Compare,Allocator>::const_iterator last2 = y.end();
while(first1 != last1 && first2 != last2){
if( *first1 < *first2 ){
return true;
}
if( *first2 < *first1 ){
return false;
}
++first1;
++first2;
}
return first2!=last2;
}
template <class Key, class Compare, class Allocator> _UCXXEXPORT void swap
(set<Key,Compare,Allocator>& x, set<Key,Compare,Allocator>& y)
{
x.swap(y);
}
template <class Key, class Compare, class Allocator> _UCXXEXPORT bool operator==
(const multiset<Key,Compare,Allocator>& x, const multiset<Key,Compare,Allocator>& y)
{
if(x.data == y.da