Class: EventMachine::FastFileReader::Mapper
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | ext/fastfilereader/rubymain.cpp |
Class Method Summary
-
.new
constructor
mod_func
mapper_new.
Instance Method Summary
-
#close
mapper_close.
-
#get_chunk
mapper_get_chunk.
-
#size
mapper_size.
Constructor Details
.new (mod_func)
mapper_new
# File 'ext/fastfilereader/rubymain.cpp', line 48
static VALUE mapper_new (VALUE self, VALUE filename)
{
Mapper_t *m = new Mapper_t (StringValueCStr (filename));
if (!m)
rb_raise (rb_eStandardError, "No Mapper Object");
VALUE v = Data_Wrap_Struct (Mapper, 0, mapper_dt, (void*)m);
return v;
}
Instance Method Details
#close
mapper_close
# File 'ext/fastfilereader/rubymain.cpp', line 85
static VALUE mapper_close (VALUE self)
{
Mapper_t *m = NULL;
Data_Get_Struct (self, Mapper_t, m);
if (!m)
rb_raise (rb_eStandardError, "No Mapper Object");
m->Close();
return Qnil;
}
#get_chunk
mapper_get_chunk
# File 'ext/fastfilereader/rubymain.cpp', line 62
static VALUE mapper_get_chunk (VALUE self, VALUE start, VALUE length)
{
Mapper_t *m = NULL;
Data_Get_Struct (self, Mapper_t, m);
if (!m)
rb_raise (rb_eStandardError, "No Mapper Object");
// TODO, what if some moron sends us a negative start value?
unsigned _start = NUM2INT (start);
unsigned _length = NUM2INT (length);
if ((_start + _length) > m->GetFileSize())
rb_raise (rb_eStandardError, "Mapper Range Error");
const char *chunk = m->GetChunk (_start);
if (!chunk)
rb_raise (rb_eStandardError, "No Mapper Chunk");
return rb_str_new (chunk, _length);
}
#size
mapper_size
# File 'ext/fastfilereader/rubymain.cpp', line 99
static VALUE mapper_size (VALUE self)
{
Mapper_t *m = NULL;
Data_Get_Struct (self, Mapper_t, m);
if (!m)
rb_raise (rb_eStandardError, "No Mapper Object");
return INT2NUM (m->GetFileSize());
}