Class: Rbind::RClass
- Defined in:
- lib/rbind/core/rclass.rb
Instance Attribute Summary collapse
-
#parent_classes ⇒ Object
readonly
Returns the value of attribute parent_classes.
Attributes inherited from RNamespace
#consts, #operation_alias, #root
Attributes inherited from RDataType
#cdelete_method, #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_parent(klass) ⇒ Object
- #attribute(name) ⇒ Object
- #attributes ⇒ Object
-
#initialize(name, *parent_classes) ⇒ RClass
constructor
A new instance of RClass.
- #operation(name, raise_ = true) ⇒ Object
- #operations ⇒ Object
- #parent_class(name) ⇒ Object
- #pretty_print(pp) ⇒ Object
- #pretty_print_name ⇒ Object
- #used_namespaces ⇒ Object
Methods inherited from RStruct
#add_attribute, #basic_type?, #cdelete_method, #constructor?, #valid_flags
Methods inherited from RNamespace
#add_const, #add_default_types, #add_namespace, #add_operation, #add_simple_type, #add_simple_types, #add_type, #const, #constructor?, #container?, #delete_type, #each_const, #each_container, #each_operation, #each_type, #extern?, #method_missing, #operation?, #root?, #type, #types, #use_namespace
Methods inherited from RDataType
#==, #basic_type?, #check_type?, #cname, #container?, #delete!, #extern?, #generate_signatures, #ptr?, #ref?, #to_ptr, #to_value, #typedef?, #valid_flags
Methods inherited from RBase
#add_flag, basename, #binding, #full_name, #generate_signatures, #ignore?, #map_to_namespace, namespace, #namespace?, normalize, to_cname, #valid_flags, #validate_flags
Constructor Details
#initialize(name, *parent_classes) ⇒ RClass
Returns a new instance of RClass.
6 7 8 9 10 11 12 13 |
# File 'lib/rbind/core/rclass.rb', line 6 def initialize(name,*parent_classes) @parent_classes = Hash.new parent_classes.flatten! parent_classes.each do |p| add_parent(p) end super(name) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Rbind::RNamespace
Instance Attribute Details
#parent_classes ⇒ Object (readonly)
Returns the value of attribute parent_classes.
4 5 6 |
# File 'lib/rbind/core/rclass.rb', line 4 def parent_classes @parent_classes end |
Instance Method Details
#add_parent(klass) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/rbind/core/rclass.rb', line 134 def add_parent(klass) if @parent_classes.has_key? klass.name raise ArgumentError,"#A parent class with the name #{klass.name} already exists" end if klass.full_name == full_name || klass == self raise ArgumentError,"class #{klass.full_name} cannot be parent of its self" end # we have to disable the type check for the parent class # otherwise derived types cannot be parsed klass.check_type = false @parent_classes[klass.name] = klass self end |
#attribute(name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rbind/core/rclass.rb', line 31 def attribute(name) attrib = @attributes[name] attrib ||= begin p = parent_classes.find do |k| k.attribute(name) end a = p.attribute(name).dup if p a.owner = self if a a end end |
#attributes ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rbind/core/rclass.rb', line 15 def attributes attribs = @attributes.values parent_classes.each do |k| others = k.attributes others.delete_if do |other| attribs.inclue? other end others = others.map(&:dup) others.each do |other| other.owner = self end attribs += others end attribs end |
#operation(name, raise_ = true) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rbind/core/rclass.rb', line 89 def operation(name,raise_=true) ops = if @operations.has_key? name @operations[name].dup else [] end parent_classes.each do |k| other_ops = Array(k.operation(name,false)) other_ops.delete_if do |other_op| ops.include? other_op end ops += other_ops end if(ops.size == 1) ops.first elsif ops.empty? raise "#{full_name} has no operation called #{name}." if raise_ else ops end end |
#operations ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rbind/core/rclass.rb', line 43 def operations # temporarily add all base class operations own_ops = @operations.dup parent_classes.each do |k| k.operations.each do |other_ops| next if other_ops.empty? ops = if @operations.has_key?(other_ops.first.name) @operations[other_ops.first.name] else [] end other_ops.delete_if do |other_op| next true if !other_op op = ops.find do |o| o == other_op end next false if !op next true if op.base_class == self next true if op.base_class == other_op.base_class # ambiguous name look up due to multi # inheritance op.ambiguous_name = true other_op.ambiguous_name = true false end other_ops = other_ops.map(&:dup) other_ops.each do |other| old = other.alias add_operation other end end end # copy embedded arrays other wise they might get modified outside result = @operations.values.map(&:dup) @operations = own_ops result end |
#parent_class(name) ⇒ Object
115 116 117 |
# File 'lib/rbind/core/rclass.rb', line 115 def parent_class(name) @parent_classes[name] end |
#pretty_print(pp) ⇒ Object
130 131 132 |
# File 'lib/rbind/core/rclass.rb', line 130 def pretty_print(pp) super end |
#pretty_print_name ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/rbind/core/rclass.rb', line 119 def pretty_print_name str = "class #{full_name}" unless parent_classes.empty? parents = parent_classes.map do |p| p.full_name end str += " : " + parents.join(", ") end str end |
#used_namespaces ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/rbind/core/rclass.rb', line 81 def used_namespaces namespaces = super.clone parent_classes.each do |k| namespaces.merge k.used_namespaces end namespaces end |