Class: Warts::Cycle
Instance Attribute Summary collapse
- #element_type ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #derive(*args) ⇒ Object
-
#initialize(type) ⇒ Object
constructor
type should be one of SCAMPER_FILE_OBJ_CYCLE_START,DEF,STOP.
- #list ⇒ Object
- #write_to(file) ⇒ Object
Constructor Details
#initialize(type) ⇒ Object
type should be one of SCAMPER_FILE_OBJ_CYCLE_START,DEF,STOP.
359 360 361 362 363 |
# File 'ext/sclist.c', line 359
static VALUE sccycle_init(VALUE self, VALUE type)
{
rb_ivar_set(self, iv_element_type, type);
return self;
}
|
Instance Attribute Details
#element_type ⇒ Object (readonly)
Class Method Details
.create(list_value, options) ⇒ Object
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'ext/sclist.c', line 502
static VALUE sccycle_s_create(VALUE klass, VALUE list_value, VALUE options)
{
scamper_list_t *list;
scamper_cycle_t *cycle;
VALUE option;
int type;
unsigned int id;
unsigned int start_time, stop_time;
char* hostname;
VALUE retval;
/* See Pragmatic Programmer's book. */
if (TYPE(list_value) != T_DATA || RDATA(list_value)->dfree != sclist_free) {
rb_raise(rb_eTypeError, "wrong list argument type");
}
Data_Get_Struct(list_value, scamper_list_t, list);
if (TYPE(options) != T_HASH) {
rb_raise(rb_eTypeError, "wrong options argument type -- expected hash");
}
option = rb_hash_aref(options, sym_type);
type = (NIL_P(option) ? SCAMPER_FILE_OBJ_CYCLE_START : NUM2INT(option));
if (type < SCAMPER_FILE_OBJ_CYCLE_START
|| type > SCAMPER_FILE_OBJ_CYCLE_STOP) {
rb_raise(rb_eArgError, "invalid cycle type");
}
option = rb_hash_aref(options, sym_id);
id = (NIL_P(option) ? 0 : NUM2UINT(option));
option = rb_hash_aref(options, sym_start_time);
start_time = (NIL_P(option) ? 0 : NUM2UINT(option));
option = rb_hash_aref(options, sym_stop_time);
stop_time = (NIL_P(option) ? 0 : NUM2UINT(option));
EXTRACT_STR_OPTION(cycle, hostname);
cycle = scamper_cycle_alloc(list);
if (!cycle) {
return Qnil;
}
cycle->id = id;
cycle->start_time = start_time;
cycle->stop_time = stop_time;
cycle->hostname = strdup(hostname);
retval = Data_Wrap_Struct(cCycle, 0, sccycle_free, cycle);
if (NIL_P(sccycle_init(retval, INT2FIX(type)))) {
scamper_cycle_free(cycle);
return Qnil;
}
return retval;
}
|
Instance Method Details
#<=>(other) ⇒ Object
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'ext/sclist.c', line 366
static VALUE sccycle_cmp(VALUE self, VALUE other)
{
scamper_cycle_t *self_cycle;
scamper_cycle_t *other_cycle;
if (other == self) {
return INT2FIX(0);
}
/* See Pragmatic Programmer's book. */
if (TYPE(other) != T_DATA || RDATA(other)->dfree != sccycle_free) {
rb_raise(rb_eTypeError, "wrong argument type");
}
Data_Get_Struct(self, scamper_cycle_t, self_cycle);
Data_Get_Struct(other, scamper_cycle_t, other_cycle);
return INT2FIX(self_cycle->id < other_cycle->id ? -1
: (self_cycle->id > other_cycle->id ? 1 : 0));
}
|
#derive(*args) ⇒ Object
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'ext/sclist.c', line 424
static VALUE sccycle_derive(int argc, VALUE *argv, VALUE self)
{
scamper_cycle_t *self_cycle;
scamper_list_t *list;
scamper_cycle_t *cycle;
VALUE options, option;
int type;
unsigned int id;
unsigned int start_time, stop_time;
char* hostname;
VALUE retval;
if (rb_scan_args(argc, argv, "01", &options) == 0) {
options = rb_hash_new();
}
Data_Get_Struct(self, scamper_cycle_t, self_cycle);
if (TYPE(options) != T_HASH) {
rb_raise(rb_eTypeError, "wrong argument type -- expected hash");
}
option = rb_hash_aref(options, sym_list);
if (NIL_P(option)) {
list = self_cycle->list;
}
else {
/* See Pragmatic Programmer's book. */
if (TYPE(option) != T_DATA || RDATA(option)->dfree != sclist_free) {
rb_raise(rb_eTypeError, "wrong list argument type");
}
Data_Get_Struct(option, scamper_list_t, list);
}
option = rb_hash_aref(options, sym_type);
if (NIL_P(option)) {
type = FIX2INT(rb_ivar_get(self, iv_element_type));
}
else {
type = NUM2INT(option);
if (type < SCAMPER_FILE_OBJ_CYCLE_START
|| type > SCAMPER_FILE_OBJ_CYCLE_STOP) {
rb_raise(rb_eArgError, "invalid cycle type");
}
}
option = rb_hash_aref(options, sym_id);
id = (NIL_P(option) ? self_cycle->id : NUM2UINT(option));
option = rb_hash_aref(options, sym_start_time);
start_time = (NIL_P(option) ? self_cycle->start_time : NUM2UINT(option));
option = rb_hash_aref(options, sym_stop_time);
stop_time = (NIL_P(option) ? self_cycle->stop_time : NUM2UINT(option));
EXTRACT_STR_OPTION(self_cycle, hostname);
cycle = scamper_cycle_alloc(list);
if (!cycle) {
return Qnil;
}
cycle->id = id;
cycle->start_time = start_time;
cycle->stop_time = stop_time;
cycle->hostname = strdup(hostname);
retval = Data_Wrap_Struct(cCycle, 0, sccycle_free, cycle);
if (NIL_P(sccycle_init(retval, INT2FIX(type)))) {
scamper_cycle_free(cycle);
return Qnil;
}
return retval;
}
|
#list ⇒ Object
408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'ext/sclist.c', line 408
static VALUE sccycle_list(VALUE self)
{
scamper_cycle_t *cycle;
VALUE retval;
retval = rb_ivar_get(self, iv_list);
if (NIL_P(retval)) {
Data_Get_Struct(self, scamper_cycle_t, cycle);
retval = sclist_create(scamper_list_use(cycle->list));
rb_ivar_set(self, iv_list, retval);
}
return retval;
}
|
#write_to(file) ⇒ Object
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'ext/sclist.c', line 388
static VALUE sccycle_write_to(VALUE self, VALUE file)
{
scamper_cycle_t *cycle;
int type;
Data_Get_Struct(self, scamper_cycle_t, cycle);
type = FIX2INT(rb_ivar_get(self, iv_element_type));
if (type == SCAMPER_FILE_OBJ_CYCLE_START) {
rb_funcall(file, meth_write_cycle_start, 1, self);
}
else if (type == SCAMPER_FILE_OBJ_CYCLE_STOP) {
rb_funcall(file, meth_write_cycle_stop, 1, self);
}
/* else type == SCAMPER_FILE_OBJ_CYCLE_DEF; ignore */
return self;
}
|