本文整理汇总了C++中enumerator_ptr函数的典型用法代码示例。如果您正苦于以下问题:C++ enumerator_ptr函数的具体用法?C++ enumerator_ptr怎么用?C++ enumerator_ptr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enumerator_ptr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: enumerator_init_copy
/* :nodoc: */
static VALUE
enumerator_init_copy(VALUE obj, SEL sel, VALUE orig)
{
struct enumerator *ptr0, *ptr1;
ptr0 = enumerator_ptr(orig);
if (ptr0->fib) {
/* Fibers cannot be copied */
rb_raise(rb_eTypeError, "can't copy execution context");
}
Data_Get_Struct(obj, struct enumerator, ptr1);
if (!ptr1) {
rb_raise(rb_eArgError, "unallocated enumerator");
}
GC_WB(&ptr1->obj, ptr0->obj);
ptr1->sel = ptr0->sel;
if (ptr0->args != 0) {
GC_WB(&ptr1->args, ptr0->args);
}
ptr1->fib = 0;
return obj;
}
示例2: enumerator_init_copy
/* :nodoc: */
static VALUE
enumerator_init_copy(VALUE obj, VALUE orig)
{
struct enumerator *ptr0, *ptr1;
if (!OBJ_INIT_COPY(obj, orig)) return obj;
ptr0 = enumerator_ptr(orig);
if (ptr0->fib) {
/* Fibers cannot be copied */
rb_raise(rb_eTypeError, "can't copy execution context");
}
TypedData_Get_Struct(obj, struct enumerator, &enumerator_data_type, ptr1);
if (!ptr1) {
rb_raise(rb_eArgError, "unallocated enumerator");
}
ptr1->obj = ptr0->obj;
ptr1->meth = ptr0->meth;
ptr1->args = ptr0->args;
ptr1->fib = 0;
ptr1->lookahead = Qundef;
ptr1->feedvalue = Qundef;
ptr1->size = ptr0->size;
ptr1->size_fn = ptr0->size_fn;
return obj;
}
示例3: enumerator_rewind
static VALUE
enumerator_rewind(VALUE obj)
{
struct enumerator *e = enumerator_ptr(obj);
e->fib = 0;
e->dst = Qnil;
e->no_next = Qfalse;
return obj;
}
示例4: enumerator_peek_values
static VALUE
enumerator_peek_values(VALUE obj)
{
struct enumerator *e = enumerator_ptr(obj);
if (e->lookahead == Qundef) {
e->lookahead = get_next_values(obj, e);
}
return e->lookahead;
}
示例5: enumerator_init_copy
/* :nodoc: */
static VALUE
enumerator_init_copy(VALUE obj, VALUE orig)
{
struct enumerator *ptr0, *ptr1;
ptr0 = enumerator_ptr(orig);
if (ptr0->fib) {
/* Fibers cannot be copied */
rb_raise(rb_eTypeError, "can't copy execution context");
}
ptr1 = enumerator_ptr(obj);
ptr1->obj = ptr0->obj;
ptr1->meth = ptr0->meth;
ptr1->args = ptr0->args;
ptr1->fib = 0;
return obj;
}
示例6: next_i
static VALUE
next_i(VALUE curr, VALUE obj)
{
struct enumerator *e = enumerator_ptr(obj);
VALUE nil = Qnil;
VALUE result;
result = rb_block_call(obj, id_each, 0, 0, next_ii, obj);
e->stop_exc = rb_exc_new2(rb_eStopIteration, "iteration reached an end");
rb_ivar_set(e->stop_exc, id_result, result);
return rb_fiber_yield(1, &nil);
}
示例7: enumerator_feed
static VALUE
enumerator_feed(VALUE obj, VALUE v)
{
struct enumerator *e = enumerator_ptr(obj);
if (e->feedvalue != Qundef) {
rb_raise(rb_eTypeError, "feed value already set");
}
e->feedvalue = v;
return Qnil;
}
示例8: next_ii
static VALUE
next_ii(VALUE i, VALUE obj, int argc, VALUE *argv)
{
struct enumerator *e = enumerator_ptr(obj);
VALUE feedvalue = Qnil;
VALUE args = rb_ary_new4(argc, argv);
rb_fiber_yield(1, &args);
if (e->feedvalue != Qundef) {
feedvalue = e->feedvalue;
e->feedvalue = Qundef;
}
return feedvalue;
}
示例9: enumerator_next_values
static VALUE
enumerator_next_values(VALUE obj)
{
struct enumerator *e = enumerator_ptr(obj);
VALUE vs;
if (e->lookahead != Qundef) {
vs = e->lookahead;
e->lookahead = Qundef;
return vs;
}
return get_next_values(obj, e);
}
示例10: enumerator_block_call
static VALUE
enumerator_block_call(VALUE obj, rb_block_call_func *func, VALUE arg)
{
int argc = 0;
VALUE *argv = 0;
const struct enumerator *e = enumerator_ptr(obj);
ID meth = e->meth;
if (e->args) {
argc = RARRAY_LENINT(e->args);
argv = RARRAY_PTR(e->args);
}
return rb_block_call(e->obj, meth, argc, argv, func, arg);
}
示例11: enumerator_rewind
static VALUE
enumerator_rewind(VALUE obj)
{
struct enumerator *e = enumerator_ptr(obj);
rb_check_funcall(e->obj, id_rewind, 0, 0);
e->fib = 0;
e->dst = Qnil;
e->lookahead = Qundef;
e->feedvalue = Qundef;
e->stop_exc = Qfalse;
return obj;
}
示例12: enumerator_init
static VALUE
enumerator_init(VALUE enum_obj, VALUE obj, VALUE meth, int argc, VALUE *argv)
{
struct enumerator *ptr = enumerator_ptr(enum_obj);
ptr->obj = obj;
ptr->meth = rb_to_id(meth);
if (argc) GC_WB(&ptr->args, rb_ary_new4(argc, argv));
ptr->fib = 0;
ptr->dst = Qnil;
ptr->no_next = Qfalse;
return enum_obj;
}
示例13: obj_to_enum
/*
* call-seq:
* obj.to_enum(method = :each, *args) -> enum
* obj.enum_for(method = :each, *args) -> enum
* obj.to_enum(method = :each, *args) {|*args| block} -> enum
* obj.enum_for(method = :each, *args){|*args| block} -> enum
*
* Creates a new Enumerator which will enumerate by calling +method+ on
* +obj+, passing +args+ if any.
*
* If a block is given, it will be used to calculate the size of
* the enumerator without the need to iterate it (see Enumerator#size).
*
* === Examples
*
* str = "xyz"
*
* enum = str.enum_for(:each_byte)
* enum.each { |b| puts b }
* # => 120
* # => 121
* # => 122
*
* # protect an array from being modified by some_method
* a = [1, 2, 3]
* some_method(a.to_enum)
*
* It is typical to call to_enum when defining methods for
* a generic Enumerable, in case no block is passed.
*
* Here is such an example, with parameter passing and a sizing block:
*
* module Enumerable
* # a generic method to repeat the values of any enumerable
* def repeat(n)
* raise ArgumentError, "#{n} is negative!" if n < 0
* unless block_given?
* return to_enum(__method__, n) do # __method__ is :repeat here
* sz = size # Call size and multiply by n...
* sz * n if sz # but return nil if size itself is nil
* end
* end
* each do |*val|
* n.times { yield *val }
* end
* end
* end
*
* %i[hello world].repeat(2) { |w| puts w }
* # => Prints 'hello', 'hello', 'world', 'world'
* enum = (1..14).repeat(3)
* # => returns an Enumerator when called without a block
* enum.first(4) # => [1, 1, 1, 2]
* enum.size # => 42
*/
static VALUE
obj_to_enum(int argc, VALUE *argv, VALUE obj)
{
VALUE enumerator, meth = sym_each;
if (argc > 0) {
--argc;
meth = *argv++;
}
enumerator = rb_enumeratorize_with_size(obj, meth, argc, argv, 0);
if (rb_block_given_p()) {
enumerator_ptr(enumerator)->size = rb_block_proc();
}
return enumerator;
}
示例14: enumerator_block_call
static VALUE
enumerator_block_call(VALUE obj, VALUE (*func)(ANYARGS), VALUE arg)
{
struct enumerator *e;
int argc = 0;
const VALUE *argv = 0;
e = enumerator_ptr(obj);
if (e->args != 0) {
argc = RARRAY_LEN(e->args);
argv = RARRAY_PTR(e->args);
}
return rb_objc_block_call(e->obj, e->sel, argc, (VALUE *)argv,
func, arg);
}
示例15: enumerator_each
/*
* call-seq:
* enum.each {...}
*
* Iterates the given block using the object and the method specified
* in the first place.
*
*/
static VALUE
enumerator_each(VALUE obj)
{
struct enumerator *e;
int argc = 0;
VALUE *argv = 0;
if (!rb_block_given_p()) return obj;
e = enumerator_ptr(obj);
if (e->args) {
argc = RARRAY_LEN(e->args);
argv = RARRAY_PTR(e->args);
}
return rb_block_call(e->method, SYM2ID(sym_call), argc, argv, e->iter, (VALUE)e);
}