///
/// Func_void_std__optional_std__string_.swift
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
///

import NitroModules

/**
 * Wraps a Swift `((_ word: String?) -> Void)` as a class.
 * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
 */
public final class Func_void_std__optional_std__string_ {
  public typealias bridge = margelo.nitro.nitrotexttospeech.bridge.swift

  private let closure: ((_ word: String?) -> Void)

  public init(_ closure: @escaping ((_ word: String?) -> Void)) {
    self.closure = closure
  }

  @inline(__always)
  public func call(word: bridge.std__optional_std__string_) -> Void {
    self.closure({ () -> String? in
      if let __unwrapped = word.value {
        return String(__unwrapped)
      } else {
        return nil
      }
    }())
  }

  /**
   * Casts this instance to a retained unsafe raw pointer.
   * This acquires one additional strong reference on the object!
   */
  @inline(__always)
  public func toUnsafe() -> UnsafeMutableRawPointer {
    return Unmanaged.passRetained(self).toOpaque()
  }

  /**
   * Casts an unsafe pointer to a `Func_void_std__optional_std__string_`.
   * The pointer has to be a retained opaque `Unmanaged<Func_void_std__optional_std__string_>`.
   * This removes one strong reference from the object!
   */
  @inline(__always)
  public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__optional_std__string_ {
    return Unmanaged<Func_void_std__optional_std__string_>.fromOpaque(pointer).takeRetainedValue()
  }
}
