Class: Rbind::RBase

Inherits:
Object
  • Object
show all
Defined in:
lib/rbind/core/rbase.rb

Direct Known Subclasses

RAttribute, RDataType, ROperation

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *flags) ⇒ RBase

Returns a new instance of RBase.

Raises:

  • (ArgumentError)


72
73
74
75
76
77
78
79
# File 'lib/rbind/core/rbase.rb', line 72

def initialize(name,*flags)
    name = RBase::normalize(name)
    raise ArgumentError, "no name" unless name && name.size > 0
    @name = RBase::basename(name)
    @namespace = RBase::namespace(name)
    @version = 1
    self.flags = flags.flatten
end

Class Attribute Details

.cprefixObject

Returns the value of attribute cprefix.



16
17
18
# File 'lib/rbind/core/rbase.rb', line 16

def cprefix
  @cprefix
end

Instance Attribute Details

#alias(val = nil) ⇒ Object

Returns the value of attribute alias.



5
6
7
# File 'lib/rbind/core/rbase.rb', line 5

def alias
  @alias
end

#auto_aliasObject

set to true if rbind is aliasing the object



6
7
8
# File 'lib/rbind/core/rbase.rb', line 6

def auto_alias
  @auto_alias
end

#cname(name = nil) ⇒ Object

Returns the value of attribute cname.



4
5
6
# File 'lib/rbind/core/rbase.rb', line 4

def cname
  @cname
end

#csignature(sig = nil) ⇒ Object

Returns the value of attribute csignature.



12
13
14
# File 'lib/rbind/core/rbase.rb', line 12

def csignature
  @csignature
end

#flagsObject

Returns the value of attribute flags.



9
10
11
# File 'lib/rbind/core/rbase.rb', line 9

def flags
  @flags
end

#ignoreObject

Returns the value of attribute ignore.



13
14
15
# File 'lib/rbind/core/rbase.rb', line 13

def ignore
  @ignore
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/rbind/core/rbase.rb', line 3

def name
  @name
end

#namespaceObject

Returns the value of attribute namespace.



7
8
9
# File 'lib/rbind/core/rbase.rb', line 7

def namespace
  @namespace
end

#ownerObject

Returns the value of attribute owner.



8
9
10
# File 'lib/rbind/core/rbase.rb', line 8

def owner
  @owner
end

#signature(sig = nil) ⇒ Object

Returns the value of attribute signature.



11
12
13
# File 'lib/rbind/core/rbase.rb', line 11

def signature
  @signature
end

#versionObject

Returns the value of attribute version.



10
11
12
# File 'lib/rbind/core/rbase.rb', line 10

def version
  @version
end

Class Method Details

.basename(name) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/rbind/core/rbase.rb', line 48

def basename(name)
    name = normalize(name)
    if !!(name =~/.*::(.*)$/)
        $1
    else
        name
    end
end

.namespace(name) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/rbind/core/rbase.rb', line 57

def namespace(name)
    name = normalize(name)
    if !!(name =~/(.*)::.*$/)
        $1
    else
        nil
    end
end

.normalize(name) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/rbind/core/rbase.rb', line 40

def normalize(name)
    name = name.to_s
    if name.split("/n").size > 1
        raise "mulitple lines for a name is not supported: #{name}"
    end
    name.gsub(".","::").gsub(" ","")
end

.to_cname(name) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rbind/core/rbase.rb', line 18

def to_cname(name)
    name = normalize(name)
    cn = "#{cprefix}#{name.gsub("::","_")}"
    cn = cn.gsub("()","_fct")
    cn = cn.gsub("<=","_smaller_equal")
    cn = cn.gsub(">=","_greater_equal")
    cn = cn.gsub("!=","_unequal")
    cn = cn.gsub("==","_equal")
    cn = cn.gsub("&=","_and_set")
    cn = cn.gsub("+=","_add")
    cn = cn.gsub("-=","_sub")
    cn = cn.gsub("+","_plus")
    cn = cn.gsub("-","_minus")
    cn = cn.gsub("*","_mult")
    cn = cn.gsub("/","_div")
    cn = cn.gsub("!","_not")
    cn = cn.gsub("&","_and")
    cn = cn.gsub("<","_smaller")
    cn = cn.gsub(">","_greater")
    cn.gsub("[]","_array")
end

Instance Method Details

#add_flag(*flags) ⇒ Object



131
132
133
134
# File 'lib/rbind/core/rbase.rb', line 131

def add_flag(*flags)
    @flags += flags
    self
end

#bindingObject



178
179
180
# File 'lib/rbind/core/rbase.rb', line 178

def binding
    Kernel.binding
end

#full_nameObject



166
167
168
# File 'lib/rbind/core/rbase.rb', line 166

def full_name
    map_to_namespace(name)
end

#generate_signaturesObject



81
82
83
# File 'lib/rbind/core/rbase.rb', line 81

def generate_signatures
    ["#{full_name}","#{cname}"]
end

#ignore?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/rbind/core/rbase.rb', line 85

def ignore?
    !!@ignore
end

#map_to_namespace(name) ⇒ Object



170
171
172
173
174
175
176
# File 'lib/rbind/core/rbase.rb', line 170

def map_to_namespace(name)
    if namespace
        "#{namespace}::#{name}"
    else
        name
    end
end

#namespace?Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/rbind/core/rbase.rb', line 162

def namespace?
    namespace && namespace.size != 0
end

#pretty_print(pp) ⇒ Object



68
69
70
# File 'lib/rbind/core/rbase.rb', line 68

def pretty_print(pp)
    pp.text "#{signature}#{" Flags: #{flags.join(", ")}" unless flags.empty?}"
end

#valid_flagsObject



136
137
138
# File 'lib/rbind/core/rbase.rb', line 136

def valid_flags
    []
end

#validate_flags(flags, valid_flags = self.valid_flags) ⇒ Object



140
141
142
143
144
145
146
147
# File 'lib/rbind/core/rbase.rb', line 140

def validate_flags(flags,valid_flags = self.valid_flags)
    valid_flags.flatten!
    flags.each do |flag|
        if !valid_flags.include?(flag)
            raise "flag #{flag} is not supported for #{self.class.name}. Supported flags are #{valid_flags}"
        end
    end
end