00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CU_PTR_SEQ_H
00019 #define CU_PTR_SEQ_H
00020
00021 #include <cu/fwd.h>
00022 #include <cu/inherit.h>
00023 #include <cu/clos.h>
00024
00025 CU_BEGIN_DECLARATIONS
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 struct cu_ptr_source
00047 {
00048 void *(*get)(cu_ptr_source_t self);
00049 };
00050
00051
00052 CU_SINLINE void
00053 cu_ptr_source_init(cu_ptr_source_t source,
00054 void *(*get)(cu_ptr_source_t))
00055 {
00056 source->get = get;
00057 }
00058
00059
00060
00061 CU_SINLINE void *
00062 cu_ptr_source_get(cu_ptr_source_t source)
00063 { return source->get(source); }
00064
00065
00066
00067 struct cu_ptr_sink
00068 {
00069 void (*put)(cu_ptr_sink_t self, void *elt);
00070 };
00071
00072
00073 CU_SINLINE void
00074 cu_ptr_sink_init(cu_ptr_sink_t sink,
00075 void (*put)(cu_ptr_sink_t, void *elt))
00076 {
00077 sink->put = put;
00078 }
00079
00080
00081 CU_SINLINE void
00082 cu_ptr_sink_put(cu_ptr_sink_t sink, void *elt)
00083 { sink->put(sink, elt); }
00084
00085
00086
00087 struct cu_ptr_junction
00088 {
00089 cu_inherit (cu_ptr_source);
00090 cu_inherit (cu_ptr_sink);
00091 };
00092
00093
00094 CU_SINLINE void
00095 cu_ptr_junction_init(cu_ptr_junction_t junction,
00096 void *(*get)(cu_ptr_source_t),
00097 void (*put)(cu_ptr_sink_t, void *))
00098 {
00099 cu_ptr_source_init(cu_to(cu_ptr_source, junction), get);
00100 cu_ptr_sink_init(cu_to(cu_ptr_sink, junction), put);
00101 }
00102
00103
00104 CU_SINLINE void *
00105 cu_ptr_junction_get(cu_ptr_junction_t junction)
00106 { return cu_ptr_source_get(cu_to(cu_ptr_source, junction)); }
00107
00108
00109 CU_SINLINE void
00110 cu_ptr_junction_put(cu_ptr_junction_t junction, void *elt)
00111 { cu_ptr_sink_put(cu_to(cu_ptr_sink, junction), elt); }
00112
00113
00114 CU_SINLINE cu_ptr_source_t
00115 cu_ptr_junction_source(cu_ptr_junction_t junction)
00116 { return cu_to(cu_ptr_source, junction); }
00117
00118
00119 CU_SINLINE cu_ptr_sink_t
00120 cu_ptr_junction_sink(cu_ptr_junction_t junction)
00121 { return cu_to(cu_ptr_sink, junction); }
00122
00123
00124
00125 struct cu_ptr_sinktor
00126 {
00127 cu_inherit (cu_ptr_sink);
00128 void *(*finish)(cu_ptr_sinktor_t self);
00129 };
00130
00131
00132 CU_SINLINE void
00133 cu_ptr_sinktor_init(cu_ptr_sinktor_t sinktor,
00134 void (*put)(cu_ptr_sink_t, void *),
00135 void *(*finish)(cu_ptr_sinktor_t sinktor))
00136 {
00137 cu_ptr_sink_init(cu_to(cu_ptr_sink, sinktor), put);
00138 sinktor->finish = finish;
00139 }
00140
00141
00142 CU_SINLINE void
00143 cu_ptr_sinktor_put(cu_ptr_sinktor_t sinktor, void *elt)
00144 { cu_ptr_sink_put(cu_to(cu_ptr_sink, sinktor), elt); }
00145
00146
00147 CU_SINLINE void *
00148 cu_ptr_sinktor_finish(cu_ptr_sinktor_t sinktor)
00149 { return sinktor->finish(sinktor); }
00150
00151
00152 CU_SINLINE cu_ptr_sink_t
00153 cu_ptr_sinktor_sink(cu_ptr_sinktor_t sinktor)
00154 { return cu_to(cu_ptr_sink, sinktor); }
00155
00156
00157
00158 struct cu_ptr_junctor
00159 {
00160 cu_inherit (cu_ptr_junction);
00161 void *(*finish)(cu_ptr_junctor_t self);
00162 };
00163
00164
00165 CU_SINLINE void
00166 cu_ptr_junctor_init(cu_ptr_junctor_t junctor,
00167 void *(*get)(cu_ptr_source_t),
00168 void (*put)(cu_ptr_sink_t, void *),
00169 void *(*finish)(cu_ptr_junctor_t))
00170 {
00171 cu_ptr_junction_init(cu_to(cu_ptr_junction, junctor), get, put);
00172 junctor->finish = finish;
00173 }
00174
00175
00176 CU_SINLINE void *
00177 cu_ptr_junctor_get(cu_ptr_junctor_t junctor)
00178 { return cu_ptr_junction_get(cu_to(cu_ptr_junction, junctor)); }
00179
00180
00181 CU_SINLINE void
00182 cu_ptr_junctor_put(cu_ptr_junctor_t junctor, void *elt)
00183 { cu_ptr_junction_put(cu_to(cu_ptr_junction, junctor), elt); }
00184
00185
00186 CU_SINLINE void *
00187 cu_ptr_junctor_finish(cu_ptr_junctor_t junctor)
00188 { return junctor->finish(junctor); }
00189
00190
00191 CU_SINLINE cu_ptr_junction_t
00192 cu_ptr_junctor_junction(cu_ptr_junctor_t junctor)
00193 { return cu_to(cu_ptr_junction, junctor); }
00194
00195
00196 CU_SINLINE cu_ptr_source_t
00197 cu_ptr_junctor_source(cu_ptr_junctor_t junctor)
00198 { return cu_to2(cu_ptr_source, cu_ptr_junction, junctor); }
00199
00200
00201 CU_SINLINE cu_ptr_sink_t
00202 cu_ptr_junctor_sink(cu_ptr_junctor_t junctor)
00203 { return cu_to2(cu_ptr_sink, cu_ptr_junction, junctor); }
00204
00205
00206
00207
00208
00209
00210 cu_ptr_junction_t cu_ptr_junction_from_source_sink(cu_ptr_source_t source,
00211 cu_ptr_sink_t sink);
00212
00213 cu_ptr_junctor_t cu_ptr_junctor_from_source_sinktor(cu_ptr_source_t source,
00214 cu_ptr_sinktor_t sinktor);
00215
00216 struct cu_ptr_array_source
00217 {
00218 cu_inherit (cu_ptr_source);
00219 void **cur, **end;
00220 };
00221
00222
00223 void cu_ptr_array_source_init(cu_ptr_array_source_t src,
00224 void **begin, void **end);
00225
00226
00227 cu_ptr_source_t cu_ptr_source_from_array(void **begin, void **end);
00228
00229 extern struct cu_ptr_source cuP_empty_ptr_source;
00230 extern struct cu_ptr_sink cuP_empty_ptr_sink;
00231 extern struct cu_ptr_junction cuP_empty_ptr_junction;
00232
00233
00234 CU_SINLINE cu_ptr_source_t cu_empty_ptr_source()
00235 { return &cuP_empty_ptr_source; }
00236
00237
00238
00239 CU_SINLINE cu_ptr_sink_t cu_empty_ptr_sink()
00240 { return &cuP_empty_ptr_sink; }
00241
00242
00243
00244
00245 CU_SINLINE cu_ptr_junction_t cu_empty_ptr_junction()
00246 { return &cuP_empty_ptr_junction; }
00247
00248
00249
00250 cu_ptr_junctor_t cu_empty_ptr_junctor(void *result);
00251
00252
00253
00254
00255
00256
00257
00258
00259 size_t cu_ptr_source_count(cu_ptr_source_t source);
00260
00261
00262
00263 cu_bool_t cu_ptr_source_iterA(cu_clop(f, cu_bool_t, void *),
00264 cu_ptr_source_t source);
00265
00266
00267
00268 cu_bool_t cu_ptr_source_iterE(cu_clop(f, cu_bool_t, void *),
00269 cu_ptr_source_t source);
00270
00271 cu_bool_t cu_ptr_source_bareA(cu_bool_t (*f)(void *), cu_ptr_source_t source);
00272 cu_bool_t cu_ptr_source_bareE(cu_bool_t (*f)(void *), cu_ptr_source_t source);
00273
00274
00275 void cu_ptr_source_iter(cu_clop(f, void, void *), cu_ptr_source_t source);
00276
00277
00278
00279
00280
00281
00282 int cu_ptr_source_compare(cu_clop(f, int, void *, void *),
00283 cu_ptr_source_t source0, cu_ptr_source_t source1);
00284
00285
00286 void cu_ptr_source_sink_short(cu_ptr_source_t source, cu_ptr_sink_t sink);
00287
00288
00289
00290
00291 void **cu_ptr_source_store(cu_ptr_source_t source, size_t array_size,
00292 void **array_out);
00293
00294
00295
00296
00297 void cu_ptr_junction_short(cu_ptr_junction_t junction);
00298
00299
00300
00301 void cu_ptr_source_sink_image(cu_clop(f, void *, void *),
00302 cu_ptr_source_t source, cu_ptr_sink_t sink);
00303
00304
00305
00306 void cu_ptr_source_sink_image_cfn(void *(*f)(void *),
00307 cu_ptr_source_t source, cu_ptr_sink_t sink);
00308
00309
00310
00311
00312
00313 void cu_ptr_junction_image(cu_clop(f, void *, void *),
00314 cu_ptr_junction_t junction);
00315
00316
00317
00318 void cu_ptr_junction_image_cfn(void *(*f)(void *), cu_ptr_junction_t junction);
00319
00320
00321
00322 void *cu_ptr_junctor_image(cu_clop(f, void *, void *),
00323 cu_ptr_junctor_t junctor);
00324
00325
00326
00327 void *cu_ptr_junctor_image_cfn(void *(*f)(void *), cu_ptr_junctor_t junctor);
00328
00329
00330
00331 void cu_ptr_source_sink_filter(cu_clop(f, cu_bool_t, void *),
00332 cu_ptr_source_t source, cu_ptr_sink_t sink);
00333
00334
00335
00336
00337
00338 void cu_ptr_junction_filter(cu_clop(f, cu_bool_t, void *),
00339 cu_ptr_junction_t junction);
00340
00341
00342
00343 void *cu_ptr_junctor_filter(cu_clop(f, cu_bool_t, void *),
00344 cu_ptr_junctor_t junctor);
00345
00346
00347
00348 CU_END_DECLARATIONS
00349
00350 #define cu_ptr_source_forall cu_ptr_source_iterA
00351 #define cu_ptr_source_forsome cu_ptr_source_iterE
00352
00353 #endif