// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY

package org.wpilib.networktables;

/** NetworkTables String topic. */
public final class StringTopic extends Topic {
  /** The default type string for this topic type. */
  public static final String TYPE_STRING = "string";

  /**
   * Construct from a generic topic.
   *
   * @param topic Topic
   */
  public StringTopic(Topic topic) {
    super(topic.m_inst, topic.m_handle);
  }

  /**
   * Constructor; use NetworkTableInstance.getStringTopic() instead.
   *
   * @param inst Instance
   * @param handle Native handle
   */
  public StringTopic(NetworkTableInstance inst, int handle) {
    super(inst, handle);
  }

  /**
   * Create a new subscriber to the topic.
   *
   * <p>The subscriber is only active as long as the returned object
   * is not closed.
   *
   * <p>Subscribers that do not match the published data type do not return
   * any values. To determine if the data type matches, use the appropriate
   * Topic functions.
   *
   * @param defaultValue default value used when a default is not provided to a
   *        getter function
   * @param options subscribe options
   * @return subscriber
   */
  public StringSubscriber subscribe(
      String defaultValue,
      PubSubOption... options) {
    return new StringEntryImpl(
        this,
        NetworkTablesJNI.subscribe(
            m_handle, NetworkTableType.STRING.getValue(),
            "string", options),
        defaultValue);
  }

  /**
   * Create a new subscriber to the topic, with specified type string.
   *
   * <p>The subscriber is only active as long as the returned object
   * is not closed.
   *
   * <p>Subscribers that do not match the published data type do not return
   * any values. To determine if the data type matches, use the appropriate
   * Topic functions.
   *
   * @param typeString type string
   * @param defaultValue default value used when a default is not provided to a
   *        getter function
   * @param options subscribe options
   * @return subscriber
   */
  public StringSubscriber subscribeEx(
      String typeString,
      String defaultValue,
      PubSubOption... options) {
    return new StringEntryImpl(
        this,
        NetworkTablesJNI.subscribe(
            m_handle, NetworkTableType.STRING.getValue(),
            typeString, options),
        defaultValue);
  }

  /**
   * Create a new publisher to the topic.
   *
   * <p>The publisher is only active as long as the returned object
   * is not closed.
   *
   * <p>It is not possible to publish two different data types to the same
   * topic. Conflicts between publishers are typically resolved by the server on
   * a first-come, first-served basis. Any published values that do not match
   * the topic's data type are dropped (ignored). To determine if the data type
   * matches, use the appropriate Topic functions.
   *
   * @param options publish options
   * @return publisher
   */
  public StringPublisher publish(
      PubSubOption... options) {
    return new StringEntryImpl(
        this,
        NetworkTablesJNI.publish(
            m_handle, NetworkTableType.STRING.getValue(),
            "string", options),
        "");
  }

  /**
   * Create a new publisher to the topic, with type string and initial properties.
   *
   * <p>The publisher is only active as long as the returned object
   * is not closed.
   *
   * <p>It is not possible to publish two different data types to the same
   * topic. Conflicts between publishers are typically resolved by the server on
   * a first-come, first-served basis. Any published values that do not match
   * the topic's data type are dropped (ignored). To determine if the data type
   * matches, use the appropriate Topic functions.
   *
   * @param typeString type string
   * @param properties JSON properties
   * @param options publish options
   * @return publisher
   * @throws IllegalArgumentException if properties is not a JSON object
   */
  public StringPublisher publishEx(
      String typeString,
      String properties,
      PubSubOption... options) {
    return new StringEntryImpl(
        this,
        NetworkTablesJNI.publishEx(
            m_handle, NetworkTableType.STRING.getValue(),
            typeString, properties, options),
        "");
  }

  /**
   * Create a new entry for the topic.
   *
   * <p>Entries act as a combination of a subscriber and a weak publisher. The
   * subscriber is active as long as the entry is not closed. The publisher is
   * created when the entry is first written to, and remains active until either
   * unpublish() is called or the entry is closed.
   *
   * <p>It is not possible to use two different data types with the same
   * topic. Conflicts between publishers are typically resolved by the server on
   * a first-come, first-served basis. Any published values that do not match
   * the topic's data type are dropped (ignored), and the entry will show no new
   * values if the data type does not match. To determine if the data type
   * matches, use the appropriate Topic functions.
   *
   * @param defaultValue default value used when a default is not provided to a
   *        getter function
   * @param options publish and/or subscribe options
   * @return entry
   */
  public StringEntry getEntry(
      String defaultValue,
      PubSubOption... options) {
    return new StringEntryImpl(
        this,
        NetworkTablesJNI.getEntry(
            m_handle, NetworkTableType.STRING.getValue(),
            "string", options),
        defaultValue);
  }

  /**
   * Create a new entry for the topic, with specified type string.
   *
   * <p>Entries act as a combination of a subscriber and a weak publisher. The
   * subscriber is active as long as the entry is not closed. The publisher is
   * created when the entry is first written to, and remains active until either
   * unpublish() is called or the entry is closed.
   *
   * <p>It is not possible to use two different data types with the same
   * topic. Conflicts between publishers are typically resolved by the server on
   * a first-come, first-served basis. Any published values that do not match
   * the topic's data type are dropped (ignored), and the entry will show no new
   * values if the data type does not match. To determine if the data type
   * matches, use the appropriate Topic functions.
   *
   * @param typeString type string
   * @param defaultValue default value used when a default is not provided to a
   *        getter function
   * @param options publish and/or subscribe options
   * @return entry
   */
  public StringEntry getEntryEx(
      String typeString,
      String defaultValue,
      PubSubOption... options) {
    return new StringEntryImpl(
        this,
        NetworkTablesJNI.getEntry(
            m_handle, NetworkTableType.STRING.getValue(),
            typeString, options),
        defaultValue);
  }

}
