Class: Rbind::RStruct
- Inherits:
-
RNamespace
- Object
- RBase
- RDataType
- RNamespace
- Rbind::RStruct
- Defined in:
- lib/rbind/core/rstruct.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Attributes inherited from RNamespace
#consts, #operation_alias, #operations, #root, #used_namespaces
Attributes inherited from RDataType
#check_type, #extern_package_name, #invalid_value, #ptr, #ref, #typedef
Attributes inherited from RBase
#alias, #cname, #csignature, #flags, #ignore, #name, #namespace, #owner, #signature, #version
Instance Method Summary collapse
- #add_attribute(attr) ⇒ Object
- #attribute(name) ⇒ Object
- #basic_type? ⇒ Boolean
- #cdelete_method ⇒ Object
- #constructor? ⇒ Boolean
-
#initialize(name, *flags) ⇒ RStruct
constructor
A new instance of RStruct.
- #pretty_print(pp) ⇒ Object
- #pretty_print_name ⇒ Object
- #valid_flags ⇒ Object
Methods inherited from RNamespace
#add_const, #add_default_types, #add_namespace, #add_operation, #add_simple_type, #add_simple_types, #add_type, #const, #container?, #delete_type, #each_const, #each_container, #each_operation, #each_type, #extern?, #method_missing, #operation, #operation?, #root?, #type, #types, #use_namespace
Methods inherited from RDataType
#==, #check_type?, #cname, #container?, #delete!, #extern?, #generate_signatures, #ptr?, #ref?, #to_ptr, #to_value, #typedef?
Methods inherited from RBase
#add_flag, basename, #binding, #full_name, #generate_signatures, #ignore?, #map_to_namespace, namespace, #namespace?, normalize, to_cname, #validate_flags
Constructor Details
#initialize(name, *flags) ⇒ RStruct
Returns a new instance of RStruct.
6 7 8 9 |
# File 'lib/rbind/core/rstruct.rb', line 6 def initialize(name,*flags) @attributes = Hash.new super(name,*flags) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Rbind::RNamespace
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/rbind/core/rstruct.rb', line 4 def attributes @attributes end |
Instance Method Details
#add_attribute(attr) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rbind/core/rstruct.rb', line 48 def add_attribute(attr) if attr.namespace? type(attr.namespace).add_attribute(attr) else if @attributes.has_key? attr.name raise "#An attribute with the name #{attr.name} already exists" end attr.owner = self @attributes[attr.name] = attr # add getter and setter methods to the object add_operation(RGetter.new(attr)) add_operation(RSetter.new(attr)) if attr.write? end self end |
#attribute(name) ⇒ Object
32 33 34 |
# File 'lib/rbind/core/rstruct.rb', line 32 def attribute(name) @attributes[name] end |
#basic_type? ⇒ Boolean
11 12 13 |
# File 'lib/rbind/core/rstruct.rb', line 11 def basic_type? false end |
#cdelete_method ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rbind/core/rstruct.rb', line 36 def cdelete_method if @cdelete_method @cdelete_method else if cname =~ /^#{RBase.cprefix}(.*)/ "#{RBase.cprefix}delete_#{$1}" else "#{RBase.cprefix}delete_#{name}" end end end |
#constructor? ⇒ Boolean
19 20 21 22 23 24 25 26 |
# File 'lib/rbind/core/rstruct.rb', line 19 def constructor? ops = Array(operation(name,false)) return false unless ops op = ops.find do |op| op.constructor? end !!op end |
#pretty_print(pp) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rbind/core/rstruct.rb', line 68 def pretty_print(pp) super unless attributes.empty? pp.nest(2) do pp.breakable pp.text "Attributes:" pp.nest(2) do attributes.each do |a| pp.breakable pp.pp(a) end end end end end |
#pretty_print_name ⇒ Object
64 65 66 |
# File 'lib/rbind/core/rstruct.rb', line 64 def pretty_print_name "struct #{full_name}#{" Flags: #{flags.join(", ")}" unless flags.empty?}" end |
#valid_flags ⇒ Object
15 16 17 |
# File 'lib/rbind/core/rstruct.rb', line 15 def valid_flags super << :Simple << :Map end |