Class: Hakuban::ObjectDescriptor

Inherits:
FFIObject show all
Defined in:
lib/hakuban/descriptor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FFIObject

#do_and_drop_or_return, #drop, #dropped?, from_ffi_pointer, generate_finalizer, #with_pointer, with_pointers

Constructor Details

#initialize(tags, json) ⇒ ObjectDescriptor

Returns a new instance of ObjectDescriptor.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/hakuban/descriptor.rb', line 12

def initialize(tags, json)
  super()
  Hakuban::hakuban_initialize
  @json = json.freeze
  @tags = Set.new(tags.map { |tag| tag.kind_of?(TagDescriptor) ? tag : TagDescriptor.new(tag) })
  FFIObject.with_pointers(@tags) { |tag_pointers|
    tag_pointers_array = ::FFI::MemoryPointer.new(:pointer, tag_pointers.size)
    tag_pointers_array.write_array_of_pointer(tag_pointers)
    initialize_pointer(FFI::hakuban_object_descriptor_new(@json.to_json,tag_pointers.size,tag_pointers_array).unwrap,:hakuban_object_descriptor_drop,:hakuban_object_descriptor_clone)
  }
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



10
11
12
# File 'lib/hakuban/descriptor.rb', line 10

def json
  @json
end

#tagsObject (readonly)

Returns the value of attribute tags.



10
11
12
# File 'lib/hakuban/descriptor.rb', line 10

def tags
  @tags
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



38
39
40
# File 'lib/hakuban/descriptor.rb', line 38

def ==(other)
  @tags == other.tags and @json == other.json
end

#hashObject



44
45
46
# File 'lib/hakuban/descriptor.rb', line 44

def hash
  [@tags.hash, @json.hash].hash
end

#initialize_copy(original) ⇒ Object



33
34
35
36
# File 'lib/hakuban/descriptor.rb', line 33

def initialize_copy(original)
  super
  @tags = original.tags.map(&:clone)
end

#initialize_from_ffi_pointer(pointer) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/hakuban/descriptor.rb', line 24

def initialize_from_ffi_pointer(pointer)
  super(pointer, :hakuban_object_descriptor_drop,:hakuban_object_descriptor_clone)
  @json = JSON::parse(FFI::hakuban_object_descriptor_json(pointer).clone)
  tags_array = FFI::hakuban_object_descriptor_tags(pointer)
  @tags = tags_array[:pointer].read_array_of_pointer(tags_array[:length]).map { |tag_pointer|
    FFIObject.from_ffi_pointer(TagDescriptor, FFI::hakuban_tag_descriptor_clone(tag_pointer))
  }
end

#inspectObject



48
49
50
# File 'lib/hakuban/descriptor.rb', line 48

def inspect
  "#<ObjectDescriptor @tags={%s}, @json=%p>"%[self.tags.map(&:inspect).join(","), self.json]
end