Class: Dub::Namespace

Inherits:
Object
  • Object
show all
Includes:
MemberExtraction
Defined in:
lib/dub/namespace.rb

Direct Known Subclasses

Group

Constant Summary collapse

@@namespaces =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MemberExtraction

#get_member, #ignore_member?, #insert_member, #make_member, #member, #members_prefix, #parse_members, #template_method

Constructor Details

#initialize(name, xml, current_dir) ⇒ Namespace

Returns a new instance of Namespace.


15
16
17
18
19
20
21
22
23
24
# File 'lib/dub/namespace.rb', line 15

def initialize(name, xml, current_dir)
  @@namespaces[name] = self
  @name, @xml, @current_dir = name, xml, current_dir
  @class_alias = {}
  @alias_names = []
  @enums   = []
  @defines = []
  @ignores = []
  parse_xml
end

Instance Attribute Details

#definesObject

Returns the value of attribute defines


13
14
15
# File 'lib/dub/namespace.rb', line 13

def defines
  @defines
end

#enumsObject

Returns the value of attribute enums


13
14
15
# File 'lib/dub/namespace.rb', line 13

def enums
  @enums
end

#gen=(generator) ⇒ Object

Sets the attribute gen

Parameters:

  • value

    the value to set the attribute gen to.


13
14
15
# File 'lib/dub/namespace.rb', line 13

def gen=(value)
  @gen = value
end

#headerObject

Returns the value of attribute header


13
14
15
# File 'lib/dub/namespace.rb', line 13

def header
  @header
end

#nameObject

Returns the value of attribute name


13
14
15
# File 'lib/dub/namespace.rb', line 13

def name
  @name
end

#parentObject

Returns the value of attribute parent


13
14
15
# File 'lib/dub/namespace.rb', line 13

def parent
  @parent
end

#prefixObject

Returns the value of attribute prefix


13
14
15
# File 'lib/dub/namespace.rb', line 13

def prefix
  @prefix
end

#xmlObject

Returns the value of attribute xml


13
14
15
# File 'lib/dub/namespace.rb', line 13

def xml
  @xml
end

Class Method Details

.find(name) ⇒ Object


8
9
10
# File 'lib/dub/namespace.rb', line 8

def self.find(name)
  @@namespaces[name]
end

Instance Method Details

#[](name) ⇒ Object


90
91
92
# File 'lib/dub/namespace.rb', line 90

def [](name)
  get_member(name.to_s) || klass(name.to_s)
end

#bind(generator) ⇒ Object


26
27
28
# File 'lib/dub/namespace.rb', line 26

def bind(generator)
  self.gen = generator.namespace_generator
end

#class_generatorObject


39
40
41
# File 'lib/dub/namespace.rb', line 39

def class_generator
  @gen && @gen.class_generator
end

#classesObject


107
108
109
110
111
112
113
114
115
116
# File 'lib/dub/namespace.rb', line 107

def classes
  @classes ||= begin
    list = []
    @classes_hash.each do |name, member|
      list << get_class(name, @classes_hash)
    end
    list.compact!
    list.sort
  end
end

#full_typeObject


69
70
71
# File 'lib/dub/namespace.rb', line 69

def full_type
  @parent ? "#{@parent.full_type}::#{name}" : name
end

#function(name) ⇒ Object


94
95
96
97
# File 'lib/dub/namespace.rb', line 94

def function(name)
  member = get_member(name.to_s)
  member.kind_of?(Function) ? member : nil
end

#function_generatorObject


43
44
45
# File 'lib/dub/namespace.rb', line 43

def function_generator
  @gen && @gen.function_generator
end

#generatorObject Also known as: gen


35
36
37
# File 'lib/dub/namespace.rb', line 35

def generator
  @gen
end

#has_constants?Boolean

Returns:

  • (Boolean)

127
128
129
# File 'lib/dub/namespace.rb', line 127

def has_constants?
  has_enums? || has_defines?
end

#has_defines?Boolean

Returns:

  • (Boolean)

140
141
142
# File 'lib/dub/namespace.rb', line 140

def has_defines?
  !@defines.empty?
end

#has_enums?Boolean

Returns:

  • (Boolean)

136
137
138
# File 'lib/dub/namespace.rb', line 136

def has_enums?
  !@enums.empty?
end

#has_functions?Boolean

FIXME: test

Returns:

  • (Boolean)

132
133
134
# File 'lib/dub/namespace.rb', line 132

def has_functions?
  members && members != []
end

#id_name(name = self.name) ⇒ Object


82
83
84
# File 'lib/dub/namespace.rb', line 82

def id_name(name = self.name)
  prefix ? "#{prefix}.#{name}" : name
end

#ignore(list) ⇒ Object


61
62
63
64
65
66
67
# File 'lib/dub/namespace.rb', line 61

def ignore(list)
  list = [list].flatten
  @ignores += list
  self.classes.reject! {|k| list.include?(k.name) }
  @ignores.uniq!
  @gen_members = nil
end

#klass(name) ⇒ Object


99
100
101
# File 'lib/dub/namespace.rb', line 99

def klass(name)
  get_class(name.to_s, @classes_hash) || get_alias(name.to_s)
end

#lib_nameObject


73
74
75
# File 'lib/dub/namespace.rb', line 73

def lib_name
  @lib_name || (prefix ? "#{prefix}_#{name}" : name)
end

#lib_name=(name) ⇒ Object

FIXME: test


78
79
80
# File 'lib/dub/namespace.rb', line 78

def lib_name=(name)
  @lib_name = name
end

#membersObject


118
119
120
121
122
123
124
125
# File 'lib/dub/namespace.rb', line 118

def members
  list = super(@ignores)
  if self.generator
    @gen_members ||= self.generator.members_list(list)
  else
    list
  end
end

#merge!(group) ⇒ Object


53
54
55
56
57
58
59
# File 'lib/dub/namespace.rb', line 53

def merge!(group)
  raise "Can only merge with a Group" unless group.kind_of?(Group)
  @defines += group.defines
  @enums   += group.enums

  # TODO: do we need to merge classes and members ? I don't think so (they should be in namespace).
end

#register_alias(name, klass) ⇒ Object


144
145
146
# File 'lib/dub/namespace.rb', line 144

def register_alias(name, klass)
  @class_alias[name] = klass
end

#template_class(name) ⇒ Object


103
104
105
# File 'lib/dub/namespace.rb', line 103

def template_class(name)
  get_class(name.to_s, @t_classes_hash)
end

#to_sObject


49
50
51
# File 'lib/dub/namespace.rb', line 49

def to_s
  @gen.namespace(self)
end