Ruby  3.4.0dev (2024-11-22 revision 37a72b0150ec36b4ea27175039afc28c62207b0c)
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
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 
31 
32 
45 typedef VALUE rb_enumerator_size_func(VALUE recv, VALUE argv, VALUE eobj);
46 
53 typedef struct {
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 
123 
150 VALUE rb_arithmetic_sequence_beg_len_step(VALUE as, long *begp, long *lenp, long *stepp, long len, int err);
151 
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 */
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:74
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:65
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:3848
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:549
VALUE rb_enumeratorize(VALUE recv, VALUE meth, int argc, const VALUE *argv)
Constructs an enumerator.
Definition: enumerator.c:524
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:533
int rb_arithmetic_sequence_extract(VALUE as, rb_arithmetic_sequence_components_t *buf)
Extracts components of the passed arithmetic sequence.
Definition: enumerator.c:3830
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
Pre-1.9 era evaluator APIs (now considered miscellaneous).
Defines rb_intern.
int len
Length of the buffer.
Definition: io.h:8
Block related APIs.
Defines RBIMPL_ATTR_NONNULL.
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition: nonnull.h:27
Decomposed Enumerator::ArithmeicSequence.
Definition: enumerator.h:53
int exclude_end
Whether the endpoint is open or closed.
Definition: enumerator.h:57
VALUE end
"Right" or "highest" endpoint of the sequence.
Definition: enumerator.h:55
VALUE step
Step between a sequence.
Definition: enumerator.h:56
VALUE begin
"Left" or "lowest" endpoint of the sequence.
Definition: enumerator.h:54
Defines VALUE and ID.
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40