Class: Rbind::StdMap
- Inherits:
-
RTemplateClass
- Object
- RBase
- RDataType
- RNamespace
- RClass
- RTemplateClass
- Rbind::StdMap
- Defined in:
- lib/rbind/types/std_map.rb
Instance Attribute Summary
Attributes inherited from RTemplateClass
Attributes included from Logger
Attributes inherited from RClass
#attributes, #parent_classes, #polymorphic
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
- #specialize(klass, parameters) ⇒ Object
-
#specialize_ruby_specialization(klass) ⇒ Object
called from RTemplate when ruby_specialize is called for the instance.
Methods inherited from RTemplateClass
#add_type, #do_specialize, #initialize, #resolve_type, #template?
Methods included from Logger
Methods inherited from RClass
#add_attribute, #add_child, #add_parent, #attribute, #basic_type?, #cdelete_method, #child?, #child_class, #child_classes, #constructor?, #empty?, #initialize, #operation, #operations, #parent?, #parent_class, #polymorphic?, #pretty_print, #pretty_print_name, #used_namespaces
Methods inherited from RNamespace
#add_const, #add_const_val, #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?, #enum_hash, #extern?, #initialize, #method_missing, #operation, #operation?, #pretty_print, #pretty_print_name, #root?, #type, #type?, #types, #use_namespace, #used_extern_types
Methods included from Hooks
Methods inherited from RDataType
#==, #basic_type?, #check_type?, #cname, #const?, #container?, #initialize, #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?, #initialize, #map_to_namespace, namespace, #namespace?, normalize, #overwrite_c, #overwrite_ruby, #pretty_print, #rename, #specialize_ruby, split_name, to_cname, #to_s
Constructor Details
This class inherits a constructor from Rbind::RTemplateClass
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Rbind::RNamespace
Instance Method Details
#specialize(klass, parameters) ⇒ Object
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 40 41 |
# File 'lib/rbind/types/std_map.rb', line 3 def specialize(klass,parameters) if parameters.size < 2 raise ArgumentError,"StdMap does require at least two template parameters. Got: #{parameters}}" end map_key_type = parameters.flatten[0] map_value_type = parameters.flatten[1] if parameters.size > 2 map_comp_type = parameters.flatten[2] else map_comp_type = nil end klass.add_operation ROperation.new(klass.name,nil) klass.add_operation ROperation.new(klass.name,nil,RParameter.new("other",klass).to_const) klass.add_operation ROperation.new("size",type("size_t")) klass.add_operation ROperation.new("clear",type("void")) klass.add_operation ROperation.new("empty",type("bool")) klass.add_operation ROperation.new("operator[]",map_value_type.to_ref, RParameter.new("key_type", map_key_type)) klass.add_operation ROperation.new("add",type("void"), RParameter.new("key", map_key_type),RParameter.new("value", map_value_type.to_ref.to_const)) klass.operation("add").overwrite_c do "(*rbind_obj_)[#{map_key_type.basic_type? ? "key" : "*key_"}] = #{map_value_type.basic_type? ? "value" : "*value_"};" end klass.add_operation ROperation.new("at",map_value_type, RParameter.new("key_type",map_key_type)) klass.add_operation ROperation.new("erase",type("void"), RParameter.new("key_type",map_key_type)) klass.add_operation ROperation.new("getKeys",type("std::vector<#{map_key_type}>")) klass.operation("getKeys").overwrite_c do str = %{ auto keys = new std::vector<#{map_key_type}>(); std::transform(std::begin(*rbind_obj_), std::end(*rbind_obj_), std::back_inserter(*keys), [](std::pair<#{map_key_type},#{map_value_type}> const& pair) { return pair.first; }); return toC(keys); } end klass end |
#specialize_ruby_specialization(klass) ⇒ Object
called from RTemplate when ruby_specialize is called for the instance
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rbind/types/std_map.rb', line 44 def specialize_ruby_specialization(klass) %Q$ def to_hash hash = Hash.new keys = get_keys keys.each do |k| hash[k] = self[k] end hash end def []=(key,val) add(key,val) end$ end |