<commit_before>//
//  GLibValue.swift
//  GLibObject
//
//  Created by <NAME> on 17/4/17.
//  Copyright © 2016, 2017 <NAME>.  All rights reserved.
//
#if os(macOS) || os(iOS) || os(tvOS)
    import Darwin
#else
    import Glibc
#endif
import CGLib
import GLib

public extension ValueProtocol {
    /// Set the receiver up to hold a value of the given type
    ///
    /// - Parameter type: the type of value to hold
    public func set(type: GType) { _ = init_(gType: type) }

    /// Generic Value accessor.
    ///
    /// - Returns: an optional String if stored as the value
    public func get() -> String { return string }
    /// Generic Value accessor.
    ///
    /// - Returns: a Bool if stored as the value
    public func get() -> Bool { return boolean }
    /// Generic Value accessor.
    ///
    /// - Returns: a Double if stored as the value
    public func get() -> Double { return double }
    /// Generic Value accessor.
    ///
    /// - Returns: a Float if stored as the value
    public func get() -> Float { return float }
    /// Generic Value accessor.
    ///
    /// - Returns: an Int if stored as the value
    public func get() -> Int { return Int(long) }
    /// Generic Value accessor.
    ///
    /// - Returns: a UInt if stored as the value
    public func get() -> UInt { return UInt(ulong) }
    /// Generic Value accessor.
    ///
    /// - Returns: an Int if stored as the value
    public func get() -> Int64 { return Int64(int64) }
    /// Generic Value accessor.
    ///
    /// - Returns: a UInt if stored as the value
    public func get() -> UInt64 { return UInt64(uint64) }
    /// Generic Value accessor.
    ///
    /// - Returns: an Int if stored as the value
    public func get() -> Int32 { return Int32(int) }
    /// Generic Value accessor.
    ///
    /// - Returns: a UInt if stored as the value
    public func get() -> UInt32 { return UInt32(uint) }
    /// Generic Value accessor.
    ///
    /// - Returns: an Int8 if stored as the value
    public func get() -> Int8 { return Int8(schar) }
    /// Generic Value accessor.
    ///
    /// - Returns: an optional UInt if stored as the value
    public func get() -> UInt8 { return UInt8(uchar) }
    /// Generic Value copier.
    ///
    /// - Returns: a `Value` containing a copy of the receiver
    public func get() -> Value { return Value(self) }
    /// Generic Value accessor.
    ///
    /// - Returns: an optional Object reference if stored as the value
    public func get() -> ObjectRef? {
        let ptr = object
        return ptr.map { ObjectRef($0.assumingMemoryBound(to: GObject.self)) }
    }
    /// Generic Value accessor.
    ///
    /// - Returns: an optional ParamSpec reference if stored as the value
    public func get() -> ParamSpec? {
        let ptr = param
        return ptr.map { ParamSpec($0) }
    }
    /// Generic Value accessor.
    ///
    /// - Returns: an optional Variant reference if stored as the value
    public func get() -> Variant? {
        let ptr = variant
        return ptr.map { Variant($0) }
    }
    /// Generic Value accessor.
    ///
    /// - Returns: an optional pointer if stored as the value
    public func get<T>() -> UnsafeMutablePointer<T>? {
        let ptr = pointer
        return ptr.map { $0.assumingMemoryBound(to: T.self) }
    }
    /// Generic Value accessor for unknown types.
    ///
    /// - Returns: nil
    public func get<T>() -> T? {
        if typeCheckValueHolds(type: .boolean) { return boolean as? T }
        if typeCheckValueHolds(type: .string)  { return string  as? T }
        if typeCheckValueHolds(type: .double)  { return double  as? T }
        if typeCheckValueHolds(type: .float)   { let f = float  ; return f as? T ?? Double(f) as? T }
        if typeCheckValueHolds(type: .long)    { let l = long   ; return l as? T ?? Int(l)    as? T }
        if typeCheckValueHolds(type: .ulong)   { let u = ulong  ; return u as? T ?? UInt(u)   as? T }
        if typeCheckValueHolds(type: .int)     { let i = int    ; return i as? T ?? Int32(i)  as? T }
        if typeCheckValueHolds(type: .uint)    { let u = uint   ; return u as? T ?? UInt32(u) as? T }
        if typeCheckValueHolds(type: .int64)   { let i = int64  ; return i as? T ?? Int64(i)  as? T }
        if typeCheckValueHolds(type: .uint64)  { let u = uint64 ; return u as? T ?? UInt64(u) as? T }
        if typeCheckValueHolds(type: .char)    { let i = schar  ; return i as? T ?? Int8(i)   as? T }
        if typeCheckValueHolds(type: .uchar)   { let u = uchar  ; return u as? T ?? UInt8(u)  as? T }
        if typeCheckValueHolds(type: .object)  { let o = object ; return o.flatMap { ObjectRef(raw: $0) as? T } ?? o.flatMap { ObjectRef(raw: $0) as? T } }
        if typeCheckValueHolds(type: .param)   { let o = param  ; return o.flatMap { ParamSpecRef($0) as? T } ?? o.flatMap { ParamSpec($0) as? T } }
        g_warn_message("GLibObject", #file, #line, #function, "Cannot retrieve value of type \(gtype) to type \(T.self)")
        return nil
    }

    /// Generic value copier.
    ///
    /// - Parameter value: original `Value` to copy
    public func set(_ value: ValueBase) { ptr.pointee = value.ptr.pointee }

    /// Generic value copier.
    ///
    /// - Parameter value: original `ValueRef` to copy
    public func set(_ value: ValueRef) { ptr.pointee = value.ptr.pointee }

    /// Generic value copier.
    ///
    /// - Parameter value: original value of kind `ValueProtocol` to copy
    public func set(_ value: ValueProtocol) { ptr.pointee = value.ptr.pointee }

    /// Generic value setter.
    ///
    /// - Parameter value: String value to set
    public func set(_ value: String) { set(type: .string) ; setString(vString: value) }

    /// Generic value setter.<commit_msg>Use g_value_copy() to copy values<commit_after>//
//  GLibValue.swift
//  GLibObject
//
//  Created by <NAME> on 17/4/17.
//  Copyright © 2016, 2017 <NAME>.  All rights reserved.
//
#if os(macOS) || os(iOS) || os(tvOS)
    import Darwin
#else
    import Glibc
#endif
import CGLib
import GLib

public extension ValueProtocol {
    /// Set the receiver up to hold a value of the given type
    ///
    /// - Parameter type: the type of value to hold
    public func set(type: GType) { _ = init_(gType: type) }

    /// Generic Value accessor.
    ///
    /// - Returns: an optional String if stored as the value
    public func get() -> String { return string }
    /// Generic Value accessor.
    ///
    /// - Returns: a Bool if stored as the value
    public func get() -> Bool { return boolean }
    /// Generic Value accessor.
    ///
    /// - Returns: a Double if stored as the value
    public func get() -> Double { return double }
    /// Generic Value accessor.
    ///
    /// - Returns: a Float if stored as the value
    public func get() -> Float { return float }
    /// Generic Value accessor.
    ///
    /// - Returns: an Int if stored as the value
    public func get() -> Int { return Int(long) }
    /// Generic Value accessor.
    ///
    /// - Returns: a UInt if stored as the value
    public func get() -> UInt { return UInt(ulong) }
    /// Generic Value accessor.
    ///
    /// - Returns: an Int if stored as the value
    public func get() -> Int64 { return Int64(int64) }
    /// Generic Value accessor.
    ///
    /// - Returns: a UInt if stored as the value
    public func get() -> UInt64 { return UInt64(uint64) }
    /// Generic Value accessor.
    ///
    /// - Returns: an Int if stored as the value
    public func get() -> Int32 { return Int32(int) }
    /// Generic Value accessor.
    ///
    /// - Returns: a UInt if stored as the value
    public func get() -> UInt32 { return UInt32(uint) }
    /// Generic Value accessor.
    ///
    /// - Returns: an Int8 if stored as the value
    public func get() -> Int8 { return Int8(schar) }
    /// Generic Value accessor.
    ///
    /// - Returns: an optional UInt if stored as the value
    public func get() -> UInt8 { return UInt8(uchar) }
    /// Generic Value copier.
    ///
    /// - Returns: a `Value` containing a copy of the receiver
    public func get() -> Value { return Value(self) }
    /// Generic Value accessor.
    ///
    /// - Returns: an optional Object reference if stored as the value
    public func get() -> ObjectRef? {
        let ptr = object
        return ptr.map { ObjectRef($0.assumingMemoryBound(to: GObject.self)) }
    }
    /// Generic Value accessor.
    ///
    /// - Returns: an optional ParamSpec reference if stored as the value
    public func get() -> ParamSpec? {
        let ptr = param
        return ptr.map { ParamSpec($0) }
    }
    /// Generic Value accessor.
    ///
    /// - Returns: an optional Variant reference if stored as the value
    public func get() -> Variant? {
        let ptr = variant
        return ptr.map { Variant($0) }
    }
    /// Generic Value accessor.
    ///
    /// - Returns: an optional pointer if stored as the value
    public func get<T>() -> UnsafeMutablePointer<T>? {
        let ptr = pointer
        return ptr.map { $0.assumingMemoryBound(to: T.self) }
    }
    /// Generic Value accessor for unknown types.
    ///
    /// - Returns: nil
    public func get<T>() -> T? {
        if typeCheckValueHolds(type: .boolean) { return boolean as? T }
        if typeCheckValueHolds(type: .string)  { return string  as? T }
        if typeCheckValueHolds(type: .double)  { return double  as? T }
        if typeCheckValueHolds(type: .float)   { let f = float  ; return f as? T ?? Double(f) as? T }
        if typeCheckValueHolds(type: .long)    { let l = long   ; return l as? T ?? Int(l)    as? T }
        if typeCheckValueHolds(type: .ulong)   { let u = ulong  ; return u as? T ?? UInt(u)   as? T }
        if typeCheckValueHolds(type: .int)     { let i = int    ; return i as? T ?? Int32(i)  as? T }
        if typeCheckValueHolds(type: .uint)    { let u = uint   ; return u as? T ?? UInt32(u) as? T }
        if typeCheckValueHolds(type: .int64)   { let i = int64  ; return i as? T ?? Int64(i)  as? T }
        if typeCheckValueHolds(type: .uint64)  { let u = uint64 ; return u as? T ?? UInt64(u) as? T }
        if typeCheckValueHolds(type: .char)    { let i = schar  ; return i as? T ?? Int8(i)   as? T }
        if typeCheckValueHolds(type: .uchar)   { let u = uchar  ; return u as? T ?? UInt8(u)  as? T }
        if typeCheckValueHolds(type: .object)  { let o = object ; return o.flatMap { ObjectRef(raw: $0) as? T } ?? o.flatMap { ObjectRef(raw: $0) as? T } }
        if typeCheckValueHolds(type: .param)   { let o = param  ; return o.flatMap { ParamSpecRef($0) as? T } ?? o.flatMap { ParamSpec($0) as? T } }
        g_warn_message("GLibObject", #file, #line, #function, "Cannot retrieve value of type \(gtype) to type \(T.self)")
        return nil
    }

    /// Generic value copier.
    ///
    /// - Parameter value: original `Value` to copy
    public func set(_ value: ValueBase) { unset() ; set(type: value.ptr.pointee.g_type) ; g_value_copy(value.ptr, ptr) }

    /// Generic value copier.
    ///
    /// - Parameter value: original `ValueRef` to copy
    public func set(_ value: ValueRef) { unset() ; set(type: value.ptr.pointee.g_type) ; g_value_copy(value.ptr, ptr) }

    /// Generic value copier.
    ///
    /// - Parameter value: original value of kind `ValueProtocol` to copy
    public func set(_ value: ValueProtocol) { unset() ; set(type: value.ptr.pointee.g_type) ; g_value_copy(value.ptr, ptr) }

    /// Generic value setter.
    ///
    /// - Parameter value: String value to set
    public func set(_ value: String) { unset() ; set(type: .string) ; setString(vString: value) }

    /// Generic value setter.
{'fraction_non_alphanumeric': 0.1347785108388313, 'fraction_numerical': 0.010967354982435095, 'mean_word_length': 2.0764364786505007, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4702901', 'n_tokens_mistral': 3695, 'n_tokens_neox': 3626, 'n_words': 1305}