001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package org.wpilib.networktables; 006 007/** NetworkTables topic information. */ 008public final class TopicInfo { 009 /** Topic handle. */ 010 public final int topic; 011 012 /** Topic name. */ 013 public final String name; 014 015 /** Topic type. */ 016 public final NetworkTableType type; 017 018 /** Topic type string. */ 019 public final String typeStr; 020 021 /** 022 * Constructor. This should generally only be used internally to NetworkTables. 023 * 024 * @param inst Instance 025 * @param handle Topic handle 026 * @param name Name 027 * @param type Type (integer version of {@link NetworkTableType}) 028 * @param typeStr Type string 029 */ 030 public TopicInfo(NetworkTableInstance inst, int handle, String name, int type, String typeStr) { 031 this.m_inst = inst; 032 this.topic = handle; 033 this.name = name; 034 this.type = NetworkTableType.getFromInt(type); 035 this.typeStr = typeStr; 036 } 037 038 /* Network table instance. */ 039 private final NetworkTableInstance m_inst; 040 041 /* Cached topic object. */ 042 private Topic m_topicObject; 043 044 /** 045 * Get the instance. 046 * 047 * @return Instance 048 */ 049 public NetworkTableInstance getInstance() { 050 return m_inst; 051 } 052 053 /** 054 * Get the topic as an object. 055 * 056 * @return Topic 057 */ 058 public Topic getTopic() { 059 if (m_topicObject == null) { 060 m_topicObject = new Topic(m_inst, topic); 061 } 062 return m_topicObject; 063 } 064}