class GObject::GValue

def get

Returns:
  • (Any) - the value held by the GValue
def get
  gtype = self[:gtype]
  fundamental = ::GObject.g_type_fundamental gtype
  result = nil
  case gtype
  when GBOOL_TYPE
    result = ::GObject.g_value_get_boolean(self) != 0
  when GINT_TYPE
    result = ::GObject.g_value_get_int self
  when GUINT64_TYPE
    result = ::GObject.g_value_get_uint64 self
  when GDOUBLE_TYPE
    result = ::GObject.g_value_get_double self
  when GSTR_TYPE
    result = ::GObject.g_value_get_string self
  when Vips::REFSTR_TYPE
    len = Vips::SizeStruct.new
    result = ::Vips.vips_value_get_ref_string self, len
  when Vips::ARRAY_INT_TYPE
    len = Vips::IntStruct.new
    array = Vips.vips_value_get_array_int self, len
    result = array.get_array_of_int32 0, len[:value]
  when Vips::ARRAY_DOUBLE_TYPE
    len = Vips::IntStruct.new
    array = Vips.vips_value_get_array_double self, len
    result = array.get_array_of_double 0, len[:value]
  when Vips::ARRAY_IMAGE_TYPE
    len = Vips::IntStruct.new
    array = Vips.vips_value_get_array_image self, len
    result = array.get_array_of_pointer 0, len[:value]
    result.map! do |pointer|
      ::GObject.g_object_ref pointer
      Vips::Image.new pointer
    end
  when Vips::BLOB_TYPE
    len = Vips::SizeStruct.new
    array = Vips.vips_value_get_blob self, len
    result = array.get_bytes 0, len[:value]
  else
    case fundamental
    when GFLAGS_TYPE
      result = ::GObject.g_value_get_flags self
    when GENUM_TYPE
      enum_value = ::GObject.g_value_get_enum(self)
      result = GValue.to_nick self[:gtype], enum_value
    when GOBJECT_TYPE
      obj = ::GObject.g_value_get_object self
      # g_value_get_object() does not add a ref ... we need to add
      # one to match the unref in gobject release
      ::GObject.g_object_ref obj
      result = Vips::Image.new obj
    else
      raise Vips::Error, "unimplemented gtype for get: " \
        "#{::GObject.g_type_name gtype} (#{gtype})"
    end
  end
  # GLib::logger.debug("GObject::GValue.get") {
  #     "result = #{result.inspect[0..50]}"
  # }
  result
end