Top Level Namespace
Defined Under Namespace
Modules: RLTK
Instance Method Summary collapse
-
#check_cg_array_type(array, type = RLTK::CG::Type, blame = 'el_types', strict = false) ⇒ Array<Type>
This helper function checks to make sure that an array of objects are all sub-classses of Type or instances of a sub-class of Type.
-
#check_cg_type(o, type = RLTK::CG::Type, blame = 'type', strict = false) ⇒ Type
This helper function checks to make sure that an object is a sub-class of Type or an instance of a sub-class of Type.
-
#make_ptr_to_elements(size_or_values, &block) ⇒ FFI::MemoryPointer
A helper function for creating constant array, vector, and struct types.
Instance Method Details
#check_cg_array_type(array, type = RLTK::CG::Type, blame = 'el_types', strict = false) ⇒ Array<Type>
This helper function checks to make sure that an array of objects are all sub-classses of Type or instances of a sub-class of Type. If a class is present in the array parameter it is expected to be a singleton class and will be instantiated via the instance method.
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 |
# File 'lib/rltk/cg/type.rb', line 529 def check_cg_array_type(array, type = RLTK::CG::Type, blame = 'el_types', strict = false) array.map do |o| if o.is_a?(Class) type_ok = if strict then o == type else o.subclass_of?(type) end if type_ok if o.includes_module?(Singleton) o.instance else raise ArgumentError, "The #{o.name} class (passed in parameter #{blame}) must be instantiated directly." end else raise ArgumentError, "The #{o.name} class (passed in parameter #{blame}) does not inherit from the #{type.name} class." end else type_ok = if strict then o.instance_of(type) else o.is_a?(type) end if type_ok o else raise ArgumentError, "Parameter #{blame} must contain instances of the #{type.name} class." end end end end |
#check_cg_type(o, type = RLTK::CG::Type, blame = 'type', strict = false) ⇒ Type
This helper function checks to make sure that an object is a sub-class of Type or an instance of a sub-class of Type. If a class is passed in the o parameter it is expected to be a singleton class and will be instantiated via the instance method.
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/rltk/cg/type.rb', line 495 def check_cg_type(o, type = RLTK::CG::Type, blame = 'type', strict = false) if o.is_a?(Class) type_ok = if strict then o == type else o.subclass_of?(type) end if type_ok if o.includes_module?(Singleton) o.instance else raise ArgumentError, "The #{o.name} class (passed as parameter #{blame}) must be instantiated directly." end else raise ArgumentError, "The #{o.name} class (passed as parameter #{blame} does not inherit from the #{type.name} class." end else check_type(o, type, blame, strict) end end |
#make_ptr_to_elements(size_or_values, &block) ⇒ FFI::MemoryPointer
A helper function for creating constant array, vector, and struct types. This method should never be used by library users.
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 |
# File 'lib/rltk/cg/value.rb', line 1260 def make_ptr_to_elements(size_or_values, &block) values = case size_or_values when Integer raise ArgumentError, 'Block not given.' if not block_given? ::Array.new(size_or_values, &block) else size_or_values end FFI::MemoryPointer.new(:pointer, values.size).write_array_of_pointer(values) end |