class DataMetaDom::DataType

DataMeta DOM Data Type, including the base type, length if any and scale if any.

For command line details either check the new method's source or the README.rdoc file, the usage section.

Attributes

length[R]

For those data types that have a dimension, such as length. See DIMMED_TYPES on the util.rb.

scale[R]

For those data types that have a scale. See SCALE_TYPES on the util.rb.

type[RW]

Base type; either one of the standard types, see STANDARD_TYPES on the util.rb or fully named custom type such as a Record, an Enum, a Map, a BitSet.

Use case of changing the type: multiple versions in one VM process.

Public Class Methods

canDim(type) click to toggle source

The type may or may not feature a length

# File lib/dataMetaDom/dataType.rb, line 44
def canDim(type)
    DIMMED_TYPES.member?(type) || OPT_DIMMABLE.member?(type)
end
mustDim(type) click to toggle source

The type must feature a length > 0

# File lib/dataMetaDom/dataType.rb, line 39
def mustDim(type)
    DIMMED_TYPES.member?(type)
end
mustNotDim(type) click to toggle source

The type must not feature a length

# File lib/dataMetaDom/dataType.rb, line 34
def mustNotDim(type)
    !DIMMED_TYPES.member?(type) && !OPT_DIMMABLE.member?(type)
end
new(t, len=nil, scale=nil) click to toggle source

Creates the instance with the given base type, the length and the scale

# File lib/dataMetaDom/dataType.rb, line 74
def initialize(t, len=nil, scale=nil)
    raise ArgumentError, "The type #{t} can not have length" if DataType.mustNotDim(t) && len

    raise ArgumentError, "The type #{type} must have length > 0, but \"#{len}\" specified" \
      if DataType.mustDim(t) && (!len || len < 1)

    @type = t.to_sym
    @length = len
    @scale = scale
end
parse(src, textual) click to toggle source

Parses type definition from DataMeta DOM source, raising errors if anything is wrong. Returns a new instance of the DataType.

# File lib/dataMetaDom/dataType.rb, line 52
def parse(src, textual)
    r = textual.scan(/([\w\.]+)(\[[\d\.]+\])?/)
    raise "Invalid data type spec #{textual}" unless r
    typeSpec, dimSpec = r[0]
    type = typeSpec.to_sym
    raise "The type #{type} can not be dimensioned" if DataType.mustNotDim(type) && dimSpec && !dimSpec.empty?
    raise "The type #{type} must be dimensioned" if DataType.mustDim(type) && (!dimSpec || dimSpec.empty?)
    length = nil; scale = nil
    unless !dimSpec || dimSpec.empty?
        raise "Invalid dimension format '#{dimSpec}'" unless dimSpec.scan(/^\[(\d+)\.?(\d+)?\]$/)
        length = $1.to_i
        scale = $2 ? $2.to_i : nil
    end
    @type = DataMetaDom.fullTypeName(src.namespace, type)
    DataType.new @type, length, scale
end

Public Instance Methods

length_spec() click to toggle source

Builds a length (dimension) and scale specification for this type according to the DataMeta DOM syntax. If the type does not have a dimension (no length, no scale), returns empty string.

# File lib/dataMetaDom/dataType.rb, line 89
def length_spec; @length && @length != 0 ? "[#{@length}" + (@scale ? '.' + @scale.to_s : '') + ']' : '' end
to_s() click to toggle source

Textual representation of this isntance, includes the type spec with the length spec.

# File lib/dataMetaDom/dataType.rb, line 92
def to_s; "#{@type}#{length_spec}" end