Class: SpecTools::MType

Inherits:
Object
  • Object
show all
Extended by:
SpecToolsExtensions
Includes:
SpecToolsExtensions
Defined in:
lib/spectools.rb,
lib/vnmsh.rb

Overview

SpecTools::MType

Represents a Spectrum model type

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SpecToolsExtensions

call_default_extension, call_extension, method_missing, method_missing

Constructor Details

#initialize(handle = nil, name = nil, attrs = Hash.new, visible = false, instantiable = false, derivable = false, destroyable = true, unique = false, required = false, inheritance = nil, landscape = Landscape.new) ⇒ MType

Returns a new instance of MType.



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/spectools.rb', line 289

def initialize(handle = nil, name = nil, attrs=Hash.new, visible = false, instantiable = false, derivable = false, destroyable = true, unique = false, required = false,inheritance = nil, landscape = Landscape.new)
  if  handle.nil? || handle.hex?
    @handle = handle
  else
    raise ArgumentError, "Handle is not a hex code"
  end
  @name = name
  @visible = visible
  @instantiable = instantiable
  @derivable = derivable
  @destroyable = destroyable
  @unique = unique
  @required = required
  @inheritance = inheritance
  @attrs = populate(attrs)
  @landscape = landscape
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SpecToolsExtensions

Instance Attribute Details

#attrsObject

An hash of Attr objects for this model type. When setting this attribute, you may either pass in a valid Hash or an Array of Attr objects



283
284
285
# File 'lib/spectools.rb', line 283

def attrs
  @attrs
end

#derivableObject

Set to true if new model types can be derived from this one



273
274
275
# File 'lib/spectools.rb', line 273

def derivable
  @derivable
end

#destroyableObject

Set to true if models of this type can be destroyed



279
280
281
# File 'lib/spectools.rb', line 279

def destroyable
  @destroyable
end

#handleObject

The model type handle (mth)



265
266
267
# File 'lib/spectools.rb', line 265

def handle
  @handle
end

#inheritanceObject

The type of inheritance



285
286
287
# File 'lib/spectools.rb', line 285

def inheritance
  @inheritance
end

#instantiableObject

Set to true if the model type can be instantiated



271
272
273
# File 'lib/spectools.rb', line 271

def instantiable
  @instantiable
end

#landscapeObject

The landscape on which the MType exists.



287
288
289
# File 'lib/spectools.rb', line 287

def landscape
  @landscape
end

#nameObject

The model type’s name



267
268
269
# File 'lib/spectools.rb', line 267

def name
  @name
end

#requiredObject

Set to true if a model of the type must exist in the database



277
278
279
# File 'lib/spectools.rb', line 277

def required
  @required
end

#uniqueObject

Set to true if only one model of this type can exist



275
276
277
# File 'lib/spectools.rb', line 275

def unique
  @unique
end

#visibleObject

Set to true if the model type is visible



269
270
271
# File 'lib/spectools.rb', line 269

def visible
  @visible
end

Class Method Details

.cli_find(filter = nil, session = nil) ⇒ Object

Use CLI to locate Model Types. Returns an array of MType objects.

filter is a hash of filter types and thier values.

If no filter is passed, returns all MTypes for the connected Landscape. Filter options:

  • :flag - filters on the provided flag

  • Example: MType.cli_find({:flag,:unique})

  • :range - filters on a range of model types

  • Range can either be a single string, an Array of handles, or an Array of MTypes.

  • Example: MType.cli_find({:range,'0x400000-0x500000'})

  • Example: MType.cli_find(:range,['0x400000','0x500000']})

  • :name - filters on the model type’s name (partials accepted)

  • Example: MType.cli_find({:name,'VNM'})

  • :landscape - filters on the given Landscape.

  • Example: MType.cli_find({:landscape,'0x400000'})



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/vnmsh.rb', line 164

def self.cli_find(filter=nil,session=nil)
  session = VNMSH.get_session(session)
  mtypes = Array.new
  if filter && filter[:flag]
    filter[:flag] = case filter[:flag]
    when :visible then 'V'
    when :instantiable then 'I'
    when :derivable then 'D'
    when :nodestroy then 'N'
    when :unique then 'U'
    when :required then 'R'
    end
  end
  mtype_output = session.show_types(filter)
  mtype_output.each do |line|
    mtype = MType.parse(line)
    if filter && filter[:landscape]
      if filter[:landscape].kind_of?(Landscape)
        mtype.landscape = filter[:landscape]
      else
        mtype.landscape = Landscape.new(filter[:landscape])
      end
    else
      mtype.landscape = session.current_landscape
    end
    mtypes.push(mtype)
  end
  return mtypes
end

.cli_parse(line) ⇒ Object

Take a line of CLI show types output and populate a new MType object.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/vnmsh.rb', line 99

def self.cli_parse(line)
  handle,name,flags = line.unpack('A12A1025A11')
  type = MType.new(handle,name)
  flags.chomp.split(/,/).each do |flag|
    case flag
      when 'V'
        type.visible = true
      when 'I'
        type.instantiable = true
      when 'D'
        type.derivable = true
      when 'N'
        type.destroyable = false
      when 'U'
        type.unique = true
      when 'R'
        type.required = true
    end
  end
  return type
    
end

.cli_parse_inheritance(line) ⇒ Object

Take a line of CLI show inheritance output and populate a new MType object.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/vnmsh.rb', line 123

def self.cli_parse_inheritance(line)
  handle,name,flags,inheritance = line.chomp.unpack('A12A18A13A10')
  type = MType.new(handle,name)
  type.inheritance = inheritance
  flags.split(/,/).each do |flag|
    
    case flag
      when 'V'
        type.visible = true
      when 'I'
        type.instantiable = true
      when 'D'
        type.derivable = true
      when 'N'
        type.destroyable = false
      when 'U'
        type.unique = true
      when 'R'
        type.required = true
    end
  end
return type
end

Instance Method Details

#cli_create_model(attrs = nil, lh = nil, session = nil) ⇒ Object

Create a new Model via CLI for this type. attrs is an Array of Attr objects that you want to be set on the model when it is created.



255
256
257
258
# File 'lib/vnmsh.rb', line 255

def cli_create_model(attrs=nil,lh=nil,session=nil)
  session = VNMSH.get_session(session)
  return session.create_model(self,attrs,lh)
end

#cli_get_attrs(filter = nil, session = nil) ⇒ Object

Use CLI to retrieve a hash of Attr objects for a given MType.

filter is a hash of filter types and thier values.

If no filter is given, all attributes are returned.

Filter options.

  • :range - returns attributes whose ID in in the specified range.

  • Range can take a single range string, or an array of MType handles or MTypes.

  • Example: mtype.cli_get_attrs({:range,['0x10000','0x1000a])

  • Example: mtype.cli_get_attrs({:range,'0x10000-0x1000a'})

  • :name - returns attributes whose name contains the specified string.

  • Example: mtype.cli_get_attrs({:name,'Condition'})

  • :flag - returns attributes that have the specified flag set.

  • Example: mtype.cli_get_attrs({:flag,:global})

  • :landscape - returns attributes in the specified landscape.

  • landscape can be a Landscape object or a landscape handle.

  • Example: mtype.cli_get_attrs({:landscape,'0x400000'})



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/vnmsh.rb', line 213

def cli_get_attrs(filter=nil,session=nil)
  unless self.handle.hex?
    raise ArgumentError, 'Must supply a valid model type handle'
  end
  attrs = Hash.new
  session = VNMSH.get_session(session)
  if filter && filter[:flag]
    flag = case filter[:flag]
           when :external then 'E'
           when :readable then 'R'
           when :writable then 'W'
           when :shared then 'S'
           when :list then 'T'
           when :guaranteed then 'G'
           when :global then 'O'
           when :memory then 'M'
           when :database then 'B'
           when :polled then 'P'
           when :logged then 'L'
           when :preserve then 'V'
           else
             raise ArgumentError, 'Invalid flag'
           end
    filter[:flag] = flag
  end
  attr_output = session.show_attributes(:mtype,self,filter,false)
  attr_output.each do |line|
    tmpattr = Attr.parse_mth(line)
    attrs[tmpattr.id] = tmpattr
  end
  return attrs
end

#cli_get_attrs!(filter = nil, session = nil) ⇒ Object

Call cli_get_attrs and populate the MType’s attrs attribute.



247
248
249
250
# File 'lib/vnmsh.rb', line 247

def cli_get_attrs!(filter=nil,session=nil)
  attrs = self.cli_get_attrs(filter,session)
  self.attrs = attrs
end