Class: Svn::AprArray

Inherits:
FFI::AutoPointer
  • Object
show all
Includes:
Enumerable
Defined in:
lib/svn/apr_utils.rb

Defined Under Namespace

Modules: C

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, type) ⇒ AprArray

Returns a new instance of AprArray.



197
198
199
200
201
# File 'lib/svn/apr_utils.rb', line 197

def initialize( ptr, type )
  super( ptr )
  @type = type
  @pointers = []
end

Class Method Details

.create(type, nelts, pool = RootPool) ⇒ Object

creates a new AprArray of nelts elements of type; allocation is done in pool, which defaults to Svn::RootPool



206
207
208
209
# File 'lib/svn/apr_utils.rb', line 206

def create( type, nelts, pool=RootPool )
  ptr = C.create( pool, nelts, FFI::Pointer.size )
  new( ptr, type )
end

.create_from(rb_arr, type, pool = RootPool) ⇒ Object



211
212
213
# File 'lib/svn/apr_utils.rb', line 211

def create_from( rb_arr, type, pool=RootPool )
  create( type, rb_arr.size ).copy_from( rb_arr )
end

.releaseObject



215
216
217
# File 'lib/svn/apr_utils.rb', line 215

def release
  # memory will be released with the allocation pool
end

Instance Method Details

#copy_from(arr) ⇒ Object



283
284
285
286
287
288
# File 'lib/svn/apr_utils.rb', line 283

def copy_from( arr )
  arr.each do |el|
    self << el
  end
  self
end

#popObject



290
291
292
293
# File 'lib/svn/apr_utils.rb', line 290

def pop
  location = C.pop( self )
  Utils.content_for( location.read_pointer, @type )
end

#push(el) ⇒ Object Also known as: add, <<



266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/svn/apr_utils.rb', line 266

def push( el )
  # turn element into a pointer
  ptr = Utils.pointer_for( el, @type )
  # get the array element location and write ptr there
  location = C.push( self )
  location.write_pointer( ptr )

  # because the pointers passed in are referenced in native code, keep
  # track of the pointers so they aren't garbage collected until this hash
  # is destroyed
  @pointers << ptr

  el
end