Class: ClassHDL::DefStruct

Inherits:
Object
  • Object
show all
Defined in:
lib/tdl/class_hdl/hdl_struct.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sdlm, block) ⇒ DefStruct

Returns a new instance of DefStruct.



52
53
54
55
# File 'lib/tdl/class_hdl/hdl_struct.rb', line 52

def initialize(sdlm,block)
    @sdlm = sdlm
    @block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



91
92
93
94
# File 'lib/tdl/class_hdl/hdl_struct.rb', line 91

def method_missing(method,*args,&block)
    @block = block
    self-(method)
end

Instance Attribute Details

#pre_typeObject

Returns the value of attribute pre_type.



50
51
52
# File 'lib/tdl/class_hdl/hdl_struct.rb', line 50

def pre_type
  @pre_type
end

#sdlmObject

Returns the value of attribute sdlm.



50
51
52
# File 'lib/tdl/class_hdl/hdl_struct.rb', line 50

def sdlm
  @sdlm
end

Instance Method Details

#-(name) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/tdl/class_hdl/hdl_struct.rb', line 57

def -(name)
    all_var_collect = ClassHDL.Struct(name,@sdlm,@pre_type,&@block)
    ## 给sdl_module 定义引用
    if @sdlm.respond_to? name 
        raise TdlError.new(" Can't define struct in module<#{@sdlm.module_name}>,because #{name} be uesed")
    end

    smeta = StructMeta.new(name,@sdlm,all_var_collect)
    @sdlm.define_singleton_method(name) do 
        smeta
    end
    ##
    _vc = @sdlm.instance_variable_get("@_struct_meta_collect_") || []
    # @sdlm.instance_variable_set("@_struct_meta_collect_",[]) unless _vc
    _vc.push smeta

    @sdlm.instance_variable_set("@_struct_meta_collect_",_vc)

    return nil
    # all_collect 
end

#packed(&block) ⇒ Object



85
86
87
88
89
# File 'lib/tdl/class_hdl/hdl_struct.rb', line 85

def packed(&block)
    @pre_type = 'packed'
    @block = block
    self
end

#union(&block) ⇒ Object



79
80
81
82
83
# File 'lib/tdl/class_hdl/hdl_struct.rb', line 79

def union(&block)
    @pre_type = 'union'
    @block = block
    self
end