Class: Rbind::StdString

Inherits:
RClass show all
Defined in:
lib/rbind/types/std_string.rb

Instance Attribute Summary

Attributes inherited from RClass

#attributes, #parent_classes

Attributes inherited from RNamespace

#consts, #operation_alias, #operations, #root, #type_alias, #used_namespaces

Attributes inherited from RDataType

#cdelete_method, #check_type, #invalid_value, #typedef

Attributes inherited from RBase

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

Instance Method Summary collapse

Methods inherited from RClass

#add_attribute, #add_parent, #attribute, #basic_type?, #cdelete_method, #constructor?, #empty?, #operation, #operations, #parent_class, #pretty_print, #pretty_print_name, #used_namespaces

Methods inherited from RNamespace

#add_const, #add_default_types, #add_namespace, #add_operation, #add_simple_type, #add_simple_types, #add_type, #add_type_alias, #const, #constructor?, #container?, default_operators, #delete_type, #each_const, #each_container, #each_operation, #each_type, #empty?, #extern?, #method_missing, #operation, #operation?, #pretty_print, #pretty_print_name, #root?, #type, #types, #use_namespace

Methods inherited from RDataType

#==, #basic_type?, #check_type?, #cname, #const?, #container?, #ownership?, #ptr?, #raw?, #ref?, #remove_const, #remove_ownership, #remove_ptr, #remove_ref, #template?, #to_const, #to_ownership, #to_ptr, #to_raw, #to_ref, #to_single_ptr, #typedef?

Methods inherited from RBase

basename, #binding, #delete!, #doc?, #extern?, #full_name, #generate_signatures, #ignore?, #map_to_namespace, namespace, #namespace?, normalize, #pretty_print, #rename, #specialize_ruby, split_name, to_cname, #to_s

Constructor Details

#initialize(name, root) ⇒ StdString

Returns a new instance of StdString.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rbind/types/std_string.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 = string.to_const
    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).to_const)
    add_operation ROperation.new(self.name,nil,RParameter.new("str",string).to_const,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).to_const)
    add_operation ROperation.new("swap",void,RParameter.new("other",self))

    specialize_ruby do
%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
end

Dynamic Method Handling

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