Class: OpenCV::CvSeq
- Inherits:
-
Object
- Object
- OpenCV::CvSeq
- Includes:
- Enumerable
- Defined in:
- ext/opencv/cvseq.cpp
Instance Method Summary collapse
-
#[](index) ⇒ Object
Return sequence-block at index.
-
#clear ⇒ self
Clears sequence.
-
#each {|obj| ... } ⇒ self
Calls block once for each sequence-block in self, passing that sequence-block as a parameter.
-
#each_index {|index| ... } ⇒ self
Same as CvSeq#each, but passes the index of the element instead of the element itself.
-
#empty? ⇒ Boolean
Return
true
if contain no object, otherwize returnfalse
. -
#first ⇒ Object?
Return first sequence-block.
-
#h_next ⇒ nil
Return the sequence horizontally located in next.
-
#h_prev ⇒ nil
Return the sequence horizontally located in previous.
-
#new(seq_flags, storage = nil) ⇒ CvSeq
constructor
Constructor.
-
#insert(index, obj) ⇒ self
Inserts the given values before element with the given index (which may be negative).
-
#last ⇒ Object?
Return last sequence-block.
-
#pop ⇒ Object?
Remove the last sequence-block from self and return it, or
nil
if the sequence is empty. -
#push(obj, ...) ⇒ self
(also: #<<)
Append - Pushes the given object(s) on the end of this sequence.
-
#remove(index) ⇒ Object?
(also: #delete_at)
Deletes the elements at the specified index.
-
#shift ⇒ Object?
(also: #pop_front)
Returns the first element of self and removes it (shifting all other elements down by one).
-
#total ⇒ Integer
(also: #length, #size)
Return total number of sequence-block.
-
#unshift ⇒ self
(also: #push_front)
Prepends objects to the front of sequence.
-
#v_next ⇒ nil
Return the sequence vertically located in next.
-
#v_prev ⇒ nil
Return the sequence vertically located in previous.
Constructor Details
#new(seq_flags, storage = nil) ⇒ CvSeq
Constructor
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'ext/opencv/cvseq.cpp', line 172
VALUE
rb_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE seq_flags_value, storage_value;
rb_scan_args(argc, argv, "11", &seq_flags_value, &storage_value);
int seq_flags = 0;
if (TYPE(seq_flags_value) == T_CLASS) { // To maintain backward compatibility
seq_flags_value = class2seq_flags_value(seq_flags_value);
}
Check_Type(seq_flags_value, T_FIXNUM);
seq_flags = FIX2INT(seq_flags_value);
DATA_PTR(self) = create_seq(seq_flags, sizeof(CvSeq), storage_value);
return self;
}
|
Instance Method Details
#[](index) ⇒ Object
Return sequence-block at index.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'ext/opencv/cvseq.cpp', line 220
VALUE
rb_aref(VALUE self, VALUE index)
{
CvSeq *seq = CVSEQ(self);
int idx = NUM2INT(index);
if (seq->total == 0) {
return Qnil;
}
if (idx >= seq->total) {
rb_raise(rb_eIndexError, "index %d out of sequence", idx);
}
VALUE result = Qnil;
try {
VALUE klass = seqblock_class(seq);
if (RTEST(rb_class_inherited_p(klass, rb_cInteger))) {
result = INT2NUM(*CV_GET_SEQ_ELEM(int, seq, idx));
}
else {
result = REFER_OBJECT(klass, cvGetSeqElem(seq, idx), self);
}
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return result;
}
|
#clear ⇒ self
Clears sequence. Removes all elements from the sequence.
446 447 448 449 450 451 452 453 454 455 456 |
# File 'ext/opencv/cvseq.cpp', line 446
VALUE
rb_clear(VALUE self)
{
try {
cvClearSeq(CVSEQ(self));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return self;
}
|
#each {|obj| ... } ⇒ self
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
# File 'ext/opencv/cvseq.cpp', line 521
VALUE
rb_each(VALUE self)
{
CvSeq *seq = CVSEQ(self);
if (seq->total > 0) {
VALUE klass = seqblock_class(seq);
try {
if (klass == rb_cInteger)
for (int i = 0; i < seq->total; ++i)
rb_yield(INT2NUM(*CV_GET_SEQ_ELEM(int, seq, i)));
else
for (int i = 0; i < seq->total; ++i)
rb_yield(REFER_OBJECT(klass, cvGetSeqElem(seq, i), self));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
}
return self;
}
|
#each_index {|index| ... } ⇒ self
Same as CvSeq#each, but passes the index of the element instead of the element itself.
548 549 550 551 552 553 554 555 |
# File 'ext/opencv/cvseq.cpp', line 548
VALUE
rb_each_index(VALUE self)
{
CvSeq *seq = CVSEQ(self);
for(int i = 0; i < seq->total; ++i)
rb_yield(INT2NUM(i));
return self;
}
|
#empty? ⇒ Boolean
Return true
if contain no object, otherwize return false
.
208 209 210 211 212 |
# File 'ext/opencv/cvseq.cpp', line 208
VALUE
rb_empty_q(VALUE self)
{
return CVSEQ(self)->total == 0 ? Qtrue : Qfalse;
}
|
#first ⇒ Object?
Return first sequence-block.
254 255 256 257 258 |
# File 'ext/opencv/cvseq.cpp', line 254
VALUE
rb_first(VALUE self)
{
return rb_aref(self, INT2FIX(0));
}
|
#h_next ⇒ nil
Return the sequence horizontally located in next. Return nil
if not existing.
296 297 298 299 300 301 302 303 304 |
# File 'ext/opencv/cvseq.cpp', line 296
VALUE
rb_h_next(VALUE self)
{
CvSeq *seq = CVSEQ(self);
if (seq->h_next)
return new_sequence(CLASS_OF(self), seq->h_next, seqblock_class(seq), lookup_root_object(seq));
else
return Qnil;
}
|
#h_prev ⇒ nil
Return the sequence horizontally located in previous. Return nil
if not existing.
279 280 281 282 283 284 285 286 287 |
# File 'ext/opencv/cvseq.cpp', line 279
VALUE
rb_h_prev(VALUE self)
{
CvSeq *seq = CVSEQ(self);
if (seq->h_prev)
return new_sequence(CLASS_OF(self), seq->h_prev, seqblock_class(seq), lookup_root_object(seq));
else
return Qnil;
}
|
#insert(index, obj) ⇒ self
Inserts the given values before element with the given index (which may be negative).
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
# File 'ext/opencv/cvseq.cpp', line 564
VALUE
rb_insert(VALUE self, VALUE index, VALUE object)
{
Check_Type(index, T_FIXNUM);
CvSeq *seq = CVSEQ(self);
VALUE klass = seqblock_class(seq);
if (!rb_obj_is_kind_of(object, klass))
rb_raise(rb_eTypeError, "arguments should be %s.", rb_class2name(klass));
try {
if (klass == rb_cInteger) {
int n = NUM2INT(object);
cvSeqInsert(seq, NUM2INT(index), &n);
}
else
cvSeqInsert(seq, NUM2INT(index), DATA_PTR(object));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return self;
}
|
#last ⇒ Object?
Return last sequence-block.
266 267 268 269 270 |
# File 'ext/opencv/cvseq.cpp', line 266
VALUE
rb_last(VALUE self)
{
return rb_aref(self, INT2FIX(-1));
}
|
#pop ⇒ Object?
Remove the last sequence-block from self and return it, or nil
if the sequence is empty.
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'ext/opencv/cvseq.cpp', line 414
VALUE
rb_pop(VALUE self)
{
CvSeq *seq = CVSEQ(self);
if (seq->total == 0)
return Qnil;
VALUE object = Qnil;
VALUE klass = seqblock_class(seq);
try {
if (klass == rb_cInteger) {
int n = 0;
cvSeqPop(seq, &n);
object = INT2FIX(n);
}
else {
object = GENERIC_OBJECT(klass, malloc(seq->elem_size));
cvSeqPop(seq, DATA_PTR(object));
}
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return object;
}
|
#push(obj, ...) ⇒ self Also known as: <<
Append - Pushes the given object(s) on the end of this sequence. This expression return the sequence itself, so several append may be chained together.
401 402 403 404 405 |
# File 'ext/opencv/cvseq.cpp', line 401
VALUE
rb_push(VALUE self, VALUE args)
{
return rb_seq_push(self, args, CV_BACK);
}
|
#remove(index) ⇒ Object? Also known as: delete_at
Deletes the elements at the specified index.
592 593 594 595 596 597 598 599 600 601 602 |
# File 'ext/opencv/cvseq.cpp', line 592
VALUE
rb_remove(VALUE self, VALUE index)
{
try {
cvSeqRemove(CVSEQ(self), NUM2INT(index));
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return self;
}
|
#shift ⇒ Object? Also known as: pop_front
Returns the first element of self and removes it (shifting all other elements down by one). Returns nil
if the array is empty.
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
# File 'ext/opencv/cvseq.cpp', line 483
VALUE
rb_shift(VALUE self)
{
CvSeq *seq = CVSEQ(self);
if (seq->total == 0)
return Qnil;
VALUE object = Qnil;
try {
if (seqblock_class(seq) == rb_cInteger) {
int n = 0;
cvSeqPopFront(seq, &n);
object = INT2NUM(n);
}
else {
object = GENERIC_OBJECT(seqblock_class(seq), malloc(seq->elem_size));
cvSeqPopFront(seq, DATA_PTR(object));
}
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return object;
}
|
#total ⇒ Integer Also known as: length, size
Return total number of sequence-block.
196 197 198 199 200 |
# File 'ext/opencv/cvseq.cpp', line 196
VALUE
rb_total(VALUE self)
{
return INT2NUM(CVSEQ(self)->total);
}
|
#unshift ⇒ self Also known as: push_front
Prepends objects to the front of sequence. other elements up one.
464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'ext/opencv/cvseq.cpp', line 464
VALUE
rb_unshift(VALUE self, VALUE args)
{
VALUE result = Qnil;
try {
result = rb_seq_push(self, args, CV_FRONT);
}
catch (cv::Exception& e) {
raise_cverror(e);
}
return result;
}
|
#v_next ⇒ nil
Return the sequence vertically located in next. Return nil
if not existing.
330 331 332 333 334 335 336 337 338 |
# File 'ext/opencv/cvseq.cpp', line 330
VALUE
rb_v_next(VALUE self)
{
CvSeq *seq = CVSEQ(self);
if (seq->v_next)
return new_sequence(CLASS_OF(self), seq->v_next, seqblock_class(seq), lookup_root_object(seq));
else
return Qnil;
}
|
#v_prev ⇒ nil
Return the sequence vertically located in previous. Return nil
if not existing.
313 314 315 316 317 318 319 320 321 |
# File 'ext/opencv/cvseq.cpp', line 313
VALUE
rb_v_prev(VALUE self)
{
CvSeq *seq = CVSEQ(self);
if (seq->v_prev)
return new_sequence(CLASS_OF(self), seq->v_prev, seqblock_class(seq), lookup_root_object(seq));
else
return Qnil;
}
|