Class: Rbind::RString

Inherits:
RClass show all
Defined in:
lib/rbind/core/rstring.rb

Instance Attribute Summary

Attributes inherited from RClass

#parent_classes

Attributes inherited from RStruct

#attributes

Attributes inherited from RNamespace

#consts, #operation_alias, #operations, #root, #types_alias, #used_namespaces

Attributes inherited from RDataType

#cdelete_method, #check_type, #extern_package_name, #invalid_value, #ptr, #ref, #typedef

Attributes inherited from RBase

#alias, #auto_alias, #cname, #csignature, #flags, #ignore, #name, #namespace, #owner, #signature, #version

Instance Method Summary collapse

Methods inherited from RClass

#add_parent, #attribute, #attributes, #operation, #operations, #parent_class, #pretty_print, #pretty_print_name, #used_namespaces

Methods inherited from RStruct

#add_attribute, #attribute, #basic_type?, #cdelete_method, #constructor?, #pretty_print, #pretty_print_name, #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, #operation?, #pretty_print, #pretty_print_name, #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, #pretty_print, to_cname, #valid_flags, #validate_flags

Constructor Details

#initialize(name, root) ⇒ RString

Returns a new instance of RString.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rbind/core/rstring.rb', line 3

def initialize(name,root)
    super(name)

    size_t = root.type("size_t")
    char = root.type("char")
    string = root.type("c_string")
    const_string = root.type("const_c_string")
    bool = root.type("bool")
    void = root.type("void")
    int = root.type("int")
    
    add_operation ROperation.new(self.name,nil)
    add_operation ROperation.new(self.name,nil,RParameter.new("other",self))
    add_operation ROperation.new(self.name,nil,RParameter.new("str",string),RParameter.new("size",size_t))
    add_operation ROperation.new("size",size_t)
    add_operation ROperation.new("length",size_t)
    add_operation ROperation.new("operator[]",char,RParameter.new("idx",size_t))
    add_operation ROperation.new("c_str",const_string)
    add_operation ROperation.new("empty",bool)
    add_operation ROperation.new("clear",void)
    add_operation ROperation.new("compare",int,RParameter.new("other",self))
    add_operation ROperation.new("swap",void,RParameter.new("other",self).add_flag(:IO))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rbind::RNamespace

Instance Method Details

#specialize_rubyObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rbind/core/rstring.rb', line 27

def specialize_ruby
%Q$         def self.to_native(obj,context)
        if obj.is_a? ::String
            str = obj.to_str
            Std::String.new(str,str.length).__obj_ptr__
        else
            rbind_to_native(obj,context)
        end
    end
    def to_s
        c_str
    end$
end