Ruby: include/ruby/internal/intern/enumerator.h Source File

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

enumerator.h
Go to the documentation of this file.
1#ifndef RBIMPL_INTERN_ENUMERATOR_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_INTERN_ENUMERATOR_H
23#include "ruby/internal/attr/nonnull.h"
24#include "ruby/internal/dllexport.h"
25#include "ruby/internal/intern/eval.h" /* rb_frame_this_func */
26#include "ruby/internal/iterator.h" /* rb_block_given_p */
27#include "ruby/internal/symbol.h"
28#include "ruby/internal/value.h"
29
30 RBIMPL_SYMBOL_EXPORT_BEGIN()
31
32
45typedef VALUE rb_enumerator_size_func(VALUE recv, VALUE argv, VALUE eobj);
46
53typedef struct {
54 VALUE begin;
55 VALUE end;
56 VALUE step;
57 int exclude_end;
58} rb_arithmetic_sequence_components_t;
59
60/* enumerator.c */
61
73 VALUE rb_enumeratorize(VALUE recv, VALUE meth, int argc, const VALUE *argv);
74
89 VALUE rb_enumeratorize_with_size(VALUE recv, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *func);
90
109 VALUE rb_enumeratorize_with_size_kw(VALUE recv, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *func, int kw_splat);
110
111 RBIMPL_ATTR_NONNULL(())
122int rb_arithmetic_sequence_extract(VALUE as, rb_arithmetic_sequence_components_t *buf);
123
124 RBIMPL_ATTR_NONNULL(())
150 VALUE rb_arithmetic_sequence_beg_len_step(VALUE as, long *begp, long *lenp, long *stepp, long len, int err);
151
152 RBIMPL_SYMBOL_EXPORT_END()
153
155#ifndef RUBY_EXPORT
156# define rb_enumeratorize_with_size(obj, id, argc, argv, size_fn) \
157 rb_enumeratorize_with_size(obj, id, argc, argv, (rb_enumerator_size_func *)(size_fn))
158# define rb_enumeratorize_with_size_kw(obj, id, argc, argv, size_fn, kw_splat) \
159 rb_enumeratorize_with_size_kw(obj, id, argc, argv, (rb_enumerator_size_func *)(size_fn), kw_splat)
160#endif
174#define SIZED_ENUMERATOR(obj, argc, argv, size_fn) \
175 rb_enumeratorize_with_size((obj), ID2SYM(rb_frame_this_func()), \
176 (argc), (argv), (size_fn))
177
193#define SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat) \
194 rb_enumeratorize_with_size_kw((obj), ID2SYM(rb_frame_this_func()), \
195 (argc), (argv), (size_fn), (kw_splat))
196
206#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn) do { \
207 if (!rb_block_given_p()) \
208 return SIZED_ENUMERATOR(obj, argc, argv, size_fn); \
209 } while (0)
210
211
226#define RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat) do { \
227 if (!rb_block_given_p()) \
228 return SIZED_ENUMERATOR_KW(obj, argc, argv, size_fn, kw_splat); \
229 } while (0)
230
239#define RETURN_ENUMERATOR(obj, argc, argv) \
240 RETURN_SIZED_ENUMERATOR(obj, argc, argv, 0)
241
256#define RETURN_ENUMERATOR_KW(obj, argc, argv, kw_splat) \
257 RETURN_SIZED_ENUMERATOR_KW(obj, argc, argv, 0, kw_splat)
258
259#endif /* RBIMPL_INTERN_ENUMERATOR_H */
dllexport.h
Tweaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:106
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:97
rb_arithmetic_sequence_beg_len_step
VALUE rb_arithmetic_sequence_beg_len_step(VALUE as, long *begp, long *lenp, long *stepp, long len, int err)
Identical to rb_range_beg_len(), except it takes an instance of Enumerator::ArithmericSequence.
Definition enumerator.c:3870
rb_enumeratorize_with_size
VALUE rb_enumeratorize_with_size(VALUE recv, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *func)
Identical to rb_enumeratorize(), except you can additionally specify the size function of return valu...
Definition enumerator.c:579
rb_enumeratorize
VALUE rb_enumeratorize(VALUE recv, VALUE meth, int argc, const VALUE *argv)
Constructs an enumerator.
Definition enumerator.c:554
rb_enumeratorize_with_size_kw
VALUE rb_enumeratorize_with_size_kw(VALUE recv, VALUE meth, int argc, const VALUE *argv, rb_enumerator_size_func *func, int kw_splat)
Identical to rb_enumeratorize_with_func(), except you can specify how to handle the last element of t...
Definition enumerator.c:563
rb_arithmetic_sequence_extract
int rb_arithmetic_sequence_extract(VALUE as, rb_arithmetic_sequence_components_t *buf)
Extracts components of the passed arithmetic sequence.
Definition enumerator.c:3852
rb_enumerator_size_func
VALUE rb_enumerator_size_func(VALUE recv, VALUE argv, VALUE eobj)
This is the type of functions that rb_enumeratorize_with_size() expects.
Definition enumerator.h:45
eval.h
Pre-1.9 era evaluator APIs (now considered miscellaneous).
symbol.h
Defines rb_intern.
iterator.h
Block related APIs.
nonnull.h
Defines RBIMPL_ATTR_NONNULL.
RBIMPL_ATTR_NONNULL
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition nonnull.h:30
rb_arithmetic_sequence_components_t
Decomposed Enumerator::ArithmeicSequence.
Definition enumerator.h:53
rb_arithmetic_sequence_components_t::exclude_end
int exclude_end
Whether the endpoint is open or closed.
Definition enumerator.h:57
rb_arithmetic_sequence_components_t::end
VALUE end
"Right" or "highest" endpoint of the sequence.
Definition enumerator.h:55
rb_arithmetic_sequence_components_t::step
VALUE step
Step between a sequence.
Definition enumerator.h:56
rb_arithmetic_sequence_components_t::begin
VALUE begin
"Left" or "lowest" endpoint of the sequence.
Definition enumerator.h:54
value.h
Defines VALUE and ID.
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40