xref: /OK3568_Linux_fs/external/security/rk_tee_user/v2/ta/vector_util/c_iterator.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *
3  * Copyright (c) 1994
4  * Hewlett-Packard Company
5  *
6  * Permission to use, copy, modify, distribute and sell this software
7  * and its documentation for any purpose is hereby granted without fee,
8  * provided that the above copyright notice appear in all copies and
9  * that both that copyright notice and this permission notice appear
10  * in supporting documentation.  Hewlett-Packard Company makes no
11  * representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  *
15  * Copyright (c) 1996
16  * Silicon Graphics Computer Systems, Inc.
17  *
18  * Permission to use, copy, modify, distribute and sell this software
19  * and its documentation for any purpose is hereby granted without fee,
20  * provided that the above copyright notice appear in all copies and
21  * that both that copyright notice and this permission notice appear
22  * in supporting documentation.  Silicon Graphics makes no
23  * representations about the suitability of this software for any
24  * purpose.  It is provided "as is" without express or implied warranty.
25  */
26 
27 /*
28 Copyright (c) 2007 Lao wen bo
29 
30 This software is provided 'as-is', without any express or implied
31 warranty. In no event will the authors be held liable for any damages
32 arising from the use of this software.
33 
34 Permission is granted to anyone to use this software for any purpose,
35 including commercial applications, and to alter it and redistribute it
36 freely, subject to the following restrictions:
37 
38     1. The origin of this software must not be misrepresented; you must not
39     claim that you wrote the original software. If you use this software
40     in a product, an acknowledgment in the product documentation would be
41     appreciated but is not required.
42 
43     2. Altered source versions must be plainly marked as such, and must not be
44     misrepresented as being the original software.
45 
46     3. This notice may not be removed or altered from any source
47     distribution.
48 
49 	Lao wen bo
50 	viewpl(at)gmail.com
51  */
52 
53 #ifndef  _C_ITERATOR_H
54 #define _C_ITERATOR_H
55 
56 #include "c_def.h"
57 
58 #define c_iterator_ft 			_c_iterator_ft
59 #define c_iterator_pft 			_c_iterator_pft
60 #define c_reverse_iterator_ft 		_c_reverse_iterator_ft
61 #define c_reverse_iterator_pft 		_c_reverse_iterator_pft
62 #define c_iterator 			_c_iterator
63 #define c_reverse_iterator 		_c_reverse_iterator
64 #define c_distance 			_c_distance
65 #define c_distance1 			_c_distance1
66 #define c_advance 			_c_advance
67 
68 
69 #define c_get_array_iterator		_c_get_array_iterator
70 #define c_get_array_reverse_iterator	_c_get_array_reverse_iterator
71 
72 
73 #define c_iterator_ref			_c_iterator_ref
74 #define c_iterator_ref_assign		_c_iterator_ref_assign
75 #define c_iterator_diff			_c_iterator_diff
76 #define c_iterator_at			_c_iterator_at
77 #define c_iterator_positive_n		_c_iterator_positvie_n
78 #define c_iterator_negative_n		_c_iterator_negative_n
79 #define c_iterator_equal		_c_iterator_equal
80 #define c_iterator_less			_c_iterator_less
81 
82 
83 typedef struct c_iterator c_iterator, * c_piterator;
84 typedef const c_iterator c_const_iterator;
85 
86 typedef struct c_reverse_iterator  c_reverse_iterator, * c_preverse_iterator;
87 typedef const c_reverse_iterator c_const_reverse_iterator;
88 
89 typedef struct c_iterator_ft c_iterator_ft, * c_iterator_pft;
90 typedef struct c_reverse_iterator_ft c_reverse_iterator_ft, * c_reverse_iterator_pft;
91 
92 typedef ptrdiff_t difference_type;
93 typedef void ** pointer;
94 typedef const void ** const_pointer;
95 typedef void * value_type;
96 typedef size_t size_type;
97 
98 struct c_iterator
99 {
100 	c_iterator_pft _pft;
101 	void * _i;
102 };
103 
104 struct c_reverse_iterator
105 {
106 	c_reverse_iterator_pft _pft;
107 	void * _i;
108 };
109 
110 struct c_iterator_ft
111 {
112     c_iterator (* assign)(c_piterator thiz, const c_piterator val);
113     value_type (* ref)(c_piterator thiz);
114     value_type (* ref_assign)(c_piterator thiz, const value_type val);
115     c_iterator (* inc)(c_piterator thiz);
116     c_iterator (* inc_n)(c_piterator thiz, difference_type n);
117     c_iterator (* dec)(c_piterator thiz);
118     c_iterator (* dec_n)(c_piterator thiz, difference_type n);
119     difference_type (* diff)(c_piterator thiz, const c_piterator val);
120     value_type (* at)(c_piterator thiz, difference_type n);
121     c_iterator (* positive_n)(c_piterator thiz, difference_type n);
122     c_iterator (* negative_n)(c_piterator thiz, difference_type n);
123     c_bool (* equal)(c_piterator thiz, const c_piterator val);
124     c_bool (* less)(c_piterator thiz, const c_piterator val);
125 };
126 
127 struct c_reverse_iterator_ft
128 {
129     c_reverse_iterator (* assign)(c_preverse_iterator thiz, const c_preverse_iterator val);
130     value_type (* ref)(c_preverse_iterator thiz);
131     value_type (* ref_assign)(c_preverse_iterator thiz, const value_type val);
132     c_reverse_iterator (* inc)(c_preverse_iterator thiz);
133     c_reverse_iterator (* inc_n)(c_preverse_iterator thiz, difference_type n);
134     c_reverse_iterator (* dec)(c_preverse_iterator thiz);
135     c_reverse_iterator (* dec_n)(c_preverse_iterator thiz, difference_type n);
136     difference_type (* diff)(c_preverse_iterator thiz, const c_preverse_iterator val);
137     value_type (* at)(c_preverse_iterator thiz, difference_type n);
138     c_reverse_iterator (* positive_n)(c_preverse_iterator thiz, difference_type n);
139     c_reverse_iterator (* negative_n)(c_preverse_iterator thiz, difference_type n);
140     c_bool (* equal)(c_preverse_iterator thiz, const c_preverse_iterator val);
141     c_bool (* less)(c_preverse_iterator thiz, const c_preverse_iterator val);
142 };
143 
144 #define ITER_ASSIGN(X, Y)       (X)._pft->assign(&(X), &(Y))
145 #define ITER_REF(X)             (X)._pft->ref(&(X))
146 #define ITER_REF_ASSIGN(X, Y)   (X)._pft->ref_assign(&(X), Y)
147 #define ITER_INC(X)             (X)._pft->inc(&(X))
148 #define ITER_INC_N(X, Y)        (X)._pft->inc_n(&(X), Y)
149 #define ITER_DEC(X)             (X)._pft->dec(&(X))
150 #define ITER_DEC_N(X, Y)        (X)._pft->dec_n(&(X), Y)
151 #define ITER_DIFF(X, Y)     	(X)._pft->diff(&(X), &(Y))
152 #define ITER_AT(X, Y)           (X)._pft->at(&(X), Y)
153 #define ITER_POSITIVE_N(X, Y)   (X)._pft->positive_n(&(X), Y)
154 #define ITER_NEGATIVE_N(X, Y)   (X)._pft->negative_n(&(X), Y)
155 #define ITER_EQUAL(X, Y)        (X)._pft->equal(&(X), &(Y))
156 #define ITER_LESS(X, Y)         (X)._pft->less(&(X), &(Y))
157 
158 
159 #define CHECK_OUTPUT_ITERATOR(X)            ((X)._pft->ref_assign)
160 #define CHECK_INPUT_ITERATOR(X)             ((X)._pft->ref)
161 #define CHECK_FORWARD_ITERATOR(X)           ((X)._pft->inc)
162 #define CHECK_BIDIRECTIONAL_ITERATOR(X)     ((X)._pft->inc && (X)._pft->dec)
163 #define CHECK_RANDOM_ACCESS_ITERATOR(X)     ((X)._pft->at && (X)._pft->diff)
164 
165 typedef int (* COMPARER)(value_type , value_type);
166 
167 difference_type c_distance(c_iterator first, c_iterator last);
168 void c_distance1(c_iterator first, c_iterator last, difference_type * pn);
169 void c_advance(c_piterator pval, difference_type n);
170 
171 c_iterator c_get_array_iterator(void ** ppt);
172 c_reverse_iterator c_get_array_reverse_iterator(void ** ppt);
173 
174 value_type c_iter_ref(c_iterator x);
175 value_type c_iter_ref_assign(c_iterator x, const value_type val);
176 difference_type c_iter_diff(c_iterator x, c_iterator y);
177 value_type c_iter_at(c_iterator x, difference_type n);
178 c_iterator c_iter_positive_n(c_iterator x, difference_type n);
179 c_iterator c_iter_negative_n(c_iterator x, difference_type n);
180 c_bool c_iter_equal(c_iterator x, c_iterator y);
181 c_bool c_iter_less(c_iterator x, c_iterator y);
182 
183 
184 #endif /* _C_ITERATOR_H */
185