Class: OGR::FieldDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/ogr/field_definition.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name_or_pointer, type) ⇒ FieldDefinition

Returns a new instance of FieldDefinition.

Parameters:

  • name_or_pointer (String, FFI::Pointer)
  • type (FFI::OGR::FieldType)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ogr/field_definition.rb', line 19

def initialize(name_or_pointer, type)
  pointer = if name_or_pointer.is_a? String
              FFI::OGR::API.OGR_Fld_Create(name_or_pointer, type)
            else
              name_or_pointer
            end

  if !pointer.is_a?(FFI::Pointer) || pointer.null?
    raise OGR::InvalidFieldDefinition, "Unable to create #{self.class.name} from #{name_or_pointer}"
  end

  @c_pointer = FFI::AutoPointer.new(pointer, FieldDefinition.method(:release))
  @c_pointer.autorelease = false
end

Instance Attribute Details

#c_pointerFFI::Pointer (readonly)

Returns C pointer to the C FieldDefn.

Returns:

  • (FFI::Pointer)

    C pointer to the C FieldDefn.



15
16
17
# File 'lib/ogr/field_definition.rb', line 15

def c_pointer
  @c_pointer
end

Class Method Details

.release(pointer) ⇒ Object

Parameters:

  • pointer (FFI::Pointer)


8
9
10
11
12
# File 'lib/ogr/field_definition.rb', line 8

def self.release(pointer)
  return unless pointer && !pointer.null?

  FFI::OGR::API.OGR_Fld_Destroy(pointer)
end

Instance Method Details

#destroy!Object



34
35
36
37
38
# File 'lib/ogr/field_definition.rb', line 34

def destroy!
  FieldDefinition.release(@c_pointer)

  @c_pointer = nil
end

#ignore=(new_value) ⇒ Object

Parameters:

  • new_value (Boolean)


117
118
119
# File 'lib/ogr/field_definition.rb', line 117

def ignore=(new_value)
  FFI::OGR::API.OGR_Fld_SetIgnored(@c_pointer, new_value)
end

#ignored?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/ogr/field_definition.rb', line 112

def ignored?
  FFI::OGR::API.OGR_Fld_IsIgnored(@c_pointer)
end

#justificationFFI::OGR::Justification

Returns:

  • (FFI::OGR::Justification)


72
73
74
# File 'lib/ogr/field_definition.rb', line 72

def justification
  FFI::OGR::API.OGR_Fld_GetJustify(@c_pointer)
end

#justification=(new_value) ⇒ Object

Parameters:

  • new_value (FFI::OGR::Justification)


77
78
79
# File 'lib/ogr/field_definition.rb', line 77

def justification=(new_value)
  FFI::OGR::API.OGR_Fld_SetJustify(@c_pointer, new_value)
end

#nameString

Returns:



59
60
61
62
63
64
# File 'lib/ogr/field_definition.rb', line 59

def name
  name, ptr = FFI::OGR::API.OGR_Fld_GetNameRef(@c_pointer)
  ptr.autorelease = false

  name
end

#name=(new_value) ⇒ Object

Parameters:



67
68
69
# File 'lib/ogr/field_definition.rb', line 67

def name=(new_value)
  FFI::OGR::API.OGR_Fld_SetName(@c_pointer, new_value)
end

#precisionInteger

Returns:



82
83
84
# File 'lib/ogr/field_definition.rb', line 82

def precision
  FFI::OGR::API.OGR_Fld_GetPrecision(@c_pointer)
end

#precision=(new_value) ⇒ Object

Parameters:



87
88
89
# File 'lib/ogr/field_definition.rb', line 87

def precision=(new_value)
  FFI::OGR::API.OGR_Fld_SetPrecision(@c_pointer, new_value)
end

#set(name, type, width, precision, justification) ⇒ Object

Set all defining attributes in one call.

Parameters:

  • name (String)
  • type (FFI::OGR::FieldType)
  • width (Integer)
  • precision (Integer)
  • justification (FFI::OGR::Justification)


47
48
49
50
51
52
53
54
55
56
# File 'lib/ogr/field_definition.rb', line 47

def set(name, type, width, precision, justification)
  FFI::OGR::API.OGR_Fld_Set(
    @c_pointer,
    name,
    type,
    width,
    precision,
    justification
  )
end

#typeFFI::OGR::FieldType

Returns:

  • (FFI::OGR::FieldType)


92
93
94
# File 'lib/ogr/field_definition.rb', line 92

def type
  FFI::OGR::API.OGR_Fld_GetType(@c_pointer)
end

#type=(new_value) ⇒ Object

Parameters:

  • new_value (FFI::OGR::FieldType)


97
98
99
# File 'lib/ogr/field_definition.rb', line 97

def type=(new_value)
  FFI::OGR::API.OGR_Fld_SetType(@c_pointer, new_value)
end

#widthInteger

Returns:



102
103
104
# File 'lib/ogr/field_definition.rb', line 102

def width
  FFI::OGR::API.OGR_Fld_GetWidth(@c_pointer)
end

#width=(new_value) ⇒ Object

Parameters:



107
108
109
# File 'lib/ogr/field_definition.rb', line 107

def width=(new_value)
  FFI::OGR::API.OGR_Fld_SetWidth(@c_pointer, new_value)
end