[ntcore] Commit generated files (#5962)

This commit is contained in:
PJ Reiniger
2023-12-01 18:31:06 -05:00
committed by GitHub
parent 7ed900ae3a
commit 54ab65a63a
127 changed files with 21230 additions and 329 deletions

View File

@@ -0,0 +1,372 @@
// 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
#include <jni.h>
#include <wpi/jni_util.h>
#include "edu_wpi_first_networktables_NetworkTablesJNI.h"
#include "ntcore.h"
using namespace wpi::java;
//
// Globals and load/unload
//
{% for t in types %}
static JClass timestamped{{ t.TypeName }}Cls;
{%- endfor %}
{%- for t in types %}
{%- if t.jni.ToJavaArray == "MakeJObjectArray" %}
static JClass {{ t.jni.jtype }}Cls;
{%- endif %}
{%- endfor %}
static JException illegalArgEx;
static JException indexOobEx;
static JException nullPointerEx;
static const JClassInit classes[] = {
{%- for t in types %}
{"edu/wpi/first/networktables/Timestamped{{ t.TypeName }}", &timestamped{{ t.TypeName }}Cls},
{%- endfor %}
{%- for t in types %}
{%- if t.jni.ToJavaArray == "MakeJObjectArray" %}
{"{{ t.jni.jtypestr }}", &{{ t.jni.jtype }}Cls},
{%- endif %}
{%- endfor %}
};
static const JExceptionInit exceptions[] = {
{"java/lang/IllegalArgumentException", &illegalArgEx},
{"java/lang/IndexOutOfBoundsException", &indexOobEx},
{"java/lang/NullPointerException", &nullPointerEx},
};
namespace nt {
bool JNI_LoadTypes(JNIEnv* env) {
// Cache references to classes
for (auto& c : classes) {
*c.cls = JClass(env, c.name);
if (!*c.cls) {
return false;
}
}
for (auto& c : exceptions) {
*c.cls = JException(env, c.name);
if (!*c.cls) {
return false;
}
}
return true;
}
void JNI_UnloadTypes(JNIEnv* env) {
// Delete global references
for (auto& c : classes) {
c.cls->free(env);
}
for (auto& c : exceptions) {
c.cls->free(env);
}
}
} // namespace nt
static std::vector<int> FromJavaBooleanArray(JNIEnv* env, jbooleanArray jarr) {
CriticalJSpan<const jboolean> ref{env, jarr};
if (!ref) {
return {};
}
std::span<const jboolean> elements{ref};
size_t len = elements.size();
std::vector<int> arr;
arr.reserve(len);
for (size_t i = 0; i < len; ++i) {
arr.push_back(elements[i]);
}
return arr;
}
static std::vector<std::string> FromJavaStringArray(JNIEnv* env, jobjectArray jarr) {
size_t len = env->GetArrayLength(jarr);
std::vector<std::string> arr;
arr.reserve(len);
for (size_t i = 0; i < len; ++i) {
JLocal<jstring> elem{
env, static_cast<jstring>(env->GetObjectArrayElement(jarr, i))};
if (!elem) {
return {};
}
arr.emplace_back(JStringRef{env, elem}.str());
}
return arr;
}
{% for t in types %}
static jobject MakeJObject(JNIEnv* env, nt::Timestamped{{ t.TypeName }} value) {
static jmethodID constructor = env->GetMethodID(
timestamped{{ t.TypeName }}Cls, "<init>", "(JJ{{ t.jni.jtypestr }})V");
{%- if t.jni.JavaObject %}
JLocal<{{ t.jni.jtype }}> val{env, {{ t.jni.ToJavaBegin }}value.value{{ t.jni.ToJavaEnd }}};
return env->NewObject(timestamped{{ t.TypeName }}Cls, constructor,
static_cast<jlong>(value.time),
static_cast<jlong>(value.serverTime), val.obj());
{%- else %}
return env->NewObject(timestamped{{ t.TypeName }}Cls, constructor,
static_cast<jlong>(value.time),
static_cast<jlong>(value.serverTime),
{{ t.jni.ToJavaBegin }}value.value{{ t.jni.ToJavaEnd }});
{%- endif %}
}
{% endfor %}
{%- for t in types %}
static jobjectArray MakeJObject(JNIEnv* env,
std::span<const nt::Timestamped{{ t.TypeName }}> arr) {
jobjectArray jarr =
env->NewObjectArray(arr.size(), timestamped{{ t.TypeName }}Cls, nullptr);
if (!jarr) {
return nullptr;
}
for (size_t i = 0; i < arr.size(); ++i) {
JLocal<jobject> elem{env, MakeJObject(env, arr[i])};
env->SetObjectArrayElement(jarr, i, elem.obj());
}
return jarr;
}
{% endfor %}
{%- for t in types %}
{%- if t.jni.ToJavaArray == "MakeJObjectArray" %}
static jobjectArray MakeJObjectArray(JNIEnv* env, std::span<const {{ t.cpp.ValueType }}> arr) {
jobjectArray jarr =
env->NewObjectArray(arr.size(), {{ t.jni.jtype }}Cls, nullptr);
if (!jarr) {
return nullptr;
}
for (size_t i = 0; i < arr.size(); ++i) {
JLocal<jobject> elem{env, {{ t.jni.ToJavaBegin }}arr[i]{{ t.jni.ToJavaEnd }}};
env->SetObjectArrayElement(jarr, i, elem.obj());
}
return jarr;
}
{% endif %}
{%- endfor %}
extern "C" {
{% for t in types %}
/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: getAtomic{{ t.TypeName }}
* Signature: (I{{ t.jni.jtypestr }})Ledu/wpi/first/networktables/Timestamped{{ t.TypeName }};
*/
JNIEXPORT jobject JNICALL
Java_edu_wpi_first_networktables_NetworkTablesJNI_getAtomic{{ t.TypeName }}
(JNIEnv* env, jclass, jint subentry, {{ t.jni.jtype }} defaultValue)
{
return MakeJObject(env, nt::GetAtomic{{ t.TypeName }}(subentry, {{ t.jni.FromJavaBegin }}defaultValue{{ t.jni.FromJavaEnd }}));
}
/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: readQueue{{ t.TypeName }}
* Signature: (I)[Ledu/wpi/first/networktables/Timestamped{{ t.TypeName }};
*/
JNIEXPORT jobjectArray JNICALL
Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueue{{ t.TypeName }}
(JNIEnv* env, jclass, jint subentry)
{
return MakeJObject(env, nt::ReadQueue{{ t.TypeName }}(subentry));
}
/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: readQueueValues{{ t.TypeName }}
* Signature: (I)[{{ t.jni.jtypestr }}
*/
JNIEXPORT {% if t.jni.JavaObject %}jobject{% else %}{{ t.jni.jtype }}{% endif %}Array JNICALL
Java_edu_wpi_first_networktables_NetworkTablesJNI_readQueueValues{{ t.TypeName }}
(JNIEnv* env, jclass, jint subentry)
{
return {{ t.jni.ToJavaArray }}(env, nt::ReadQueueValues{{ t.TypeName }}(subentry));
}
{% if t.TypeName == "Raw" %}
/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: setRaw
* Signature: (IJ[BII)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_networktables_NetworkTablesJNI_setRaw
(JNIEnv* env, jclass, jint entry, jlong time, jbyteArray value, jint start, jint len)
{
if (!value) {
nullPointerEx.Throw(env, "value is null");
return false;
}
if (start < 0) {
indexOobEx.Throw(env, "start must be >= 0");
return false;
}
if (len < 0) {
indexOobEx.Throw(env, "len must be >= 0");
return false;
}
CriticalJSpan<const jbyte> cvalue{env, value};
if (static_cast<unsigned int>(start + len) > cvalue.size()) {
indexOobEx.Throw(env, "start + len must be smaller than array length");
return false;
}
return nt::SetRaw(entry, cvalue.uarray().subspan(start, len), time);
}
/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: setRawBuffer
* Signature: (IJLjava/nio/ByteBuffer;II)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_networktables_NetworkTablesJNI_setRawBuffer
(JNIEnv* env, jclass, jint entry, jlong time, jobject value, jint start, jint len)
{
if (!value) {
nullPointerEx.Throw(env, "value is null");
return false;
}
if (start < 0) {
indexOobEx.Throw(env, "start must be >= 0");
return false;
}
if (len < 0) {
indexOobEx.Throw(env, "len must be >= 0");
return false;
}
JSpan<const jbyte> cvalue{env, value, static_cast<size_t>(start + len)};
if (!cvalue) {
illegalArgEx.Throw(env, "value must be a native ByteBuffer");
return false;
}
return nt::SetRaw(entry, cvalue.uarray().subspan(start, len), time);
}
{% else %}
/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: set{{ t.TypeName }}
* Signature: (IJ{{ t.jni.jtypestr }})Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_networktables_NetworkTablesJNI_set{{ t.TypeName }}
(JNIEnv*{% if t.jni.JavaObject %} env{% endif %}, jclass, jint entry, jlong time, {{ t.jni.jtype }} value)
{
{%- if t.jni.JavaObject %}
if (!value) {
nullPointerEx.Throw(env, "value cannot be null");
return false;
}
{%- endif %}
return nt::Set{{ t.TypeName }}(entry, {{ t.jni.FromJavaBegin }}value{{ t.jni.FromJavaEnd }}, time);
}
{% endif %}
/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: get{{ t.TypeName }}
* Signature: (I{{ t.jni.jtypestr }}){{ t.jni.jtypestr }}
*/
JNIEXPORT {{ t.jni.jtype }} JNICALL
Java_edu_wpi_first_networktables_NetworkTablesJNI_get{{ t.TypeName }}
(JNIEnv*{% if t.jni.JavaObject %} env{% endif %}, jclass, jint entry, {{ t.jni.jtype }} defaultValue)
{
{%- if t.jni.JavaObject %}
auto val = nt::GetEntryValue(entry);
if (!val || !val.Is{{ t.TypeName }}()) {
return defaultValue;
}
return {{ t.jni.ToJavaBegin }}val.Get{{ t.TypeName }}(){{ t.jni.ToJavaEnd }};
{%- else %}
return nt::Get{{ t.TypeName }}(entry, defaultValue);
{%- endif %}
}
{% if t.TypeName == "Raw" %}
/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: setDefaultRaw
* Signature: (IJ[BII)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefaultRaw
(JNIEnv* env, jclass, jint entry, jlong, jbyteArray defaultValue, jint start, jint len)
{
if (!defaultValue) {
nullPointerEx.Throw(env, "value is null");
return false;
}
if (start < 0) {
indexOobEx.Throw(env, "start must be >= 0");
return false;
}
if (len < 0) {
indexOobEx.Throw(env, "len must be >= 0");
return false;
}
CriticalJSpan<const jbyte> cvalue{env, defaultValue};
if (static_cast<unsigned int>(start + len) > cvalue.size()) {
indexOobEx.Throw(env, "start + len must be smaller than array length");
return false;
}
return nt::SetDefaultRaw(entry, cvalue.uarray().subspan(start, len));
}
/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: setDefaultRawBuffer
* Signature: (IJLjava/nio/ByteBuffer;II)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefaultRawBuffer
(JNIEnv* env, jclass, jint entry, jlong, jobject defaultValue, jint start, jint len)
{
if (!defaultValue) {
nullPointerEx.Throw(env, "value is null");
return false;
}
if (start < 0) {
indexOobEx.Throw(env, "start must be >= 0");
return false;
}
if (len < 0) {
indexOobEx.Throw(env, "len must be >= 0");
return false;
}
JSpan<const jbyte> cvalue{env, defaultValue, static_cast<size_t>(start + len)};
if (!cvalue) {
illegalArgEx.Throw(env, "value must be a native ByteBuffer");
return false;
}
return nt::SetDefaultRaw(entry, cvalue.uarray().subspan(start, len));
}
{% else %}
/*
* Class: edu_wpi_first_networktables_NetworkTablesJNI
* Method: setDefault{{ t.TypeName }}
* Signature: (IJ{{ t.jni.jtypestr }})Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_networktables_NetworkTablesJNI_setDefault{{ t.TypeName }}
(JNIEnv*{% if t.jni.JavaObject %} env{% endif %}, jclass, jint entry, jlong, {{ t.jni.jtype }} defaultValue)
{
{%- if t.jni.JavaObject %}
if (!defaultValue) {
nullPointerEx.Throw(env, "defaultValue cannot be null");
return false;
}
{%- endif %}
return nt::SetDefault{{ t.TypeName }}(entry, {{ t.jni.FromJavaBegin }}defaultValue{{ t.jni.FromJavaEnd }});
}
{% endif %}
{% endfor %}
} // extern "C"

View File

@@ -0,0 +1,109 @@
// 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
#include "ntcore_c_types.h"
#include "Value_internal.h"
#include "ntcore_cpp.h"
using namespace nt;
template <typename T>
static inline std::span<const T> ConvertFromC(const T* arr, size_t size) {
return {arr, size};
}
static inline std::string_view ConvertFromC(const char* arr, size_t size) {
return {arr, size};
}
static std::vector<std::string> ConvertFromC(const NT_String* arr, size_t size) {
std::vector<std::string> v;
v.reserve(size);
for (size_t i = 0; i < size; ++i) {
v.emplace_back(ConvertFromC(arr[i]));
}
return v;
}
{% for t in types %}
static void ConvertToC(const nt::Timestamped{{ t.TypeName }}& in, NT_Timestamped{{ t.TypeName }}* out) {
out->time = in.time;
out->serverTime = in.serverTime;
{%- if t.c.IsArray %}
out->value = ConvertToC<{{ t.c.ValueType[:-1] }}>(in.value, &out->len);
{% else %}
out->value = in.value;
{% endif -%}
}
{% endfor %}
extern "C" {
{% for t in types %}
NT_Bool NT_Set{{ t.TypeName }}(NT_Handle pubentry, int64_t time, {{ t.c.ParamType }} value{% if t.c.IsArray %}, size_t len{% endif %}) {
{%- if t.c.IsArray %}
return nt::Set{{ t.TypeName }}(pubentry, ConvertFromC(value, len), time);
{%- else %}
return nt::Set{{ t.TypeName }}(pubentry, value, time);
{%- endif %}
}
NT_Bool NT_SetDefault{{ t.TypeName }}(NT_Handle pubentry, {{ t.c.ParamType }} defaultValue{% if t.c.IsArray %}, size_t defaultValueLen{% endif %}) {
{%- if t.c.IsArray %}
return nt::SetDefault{{ t.TypeName }}(pubentry, ConvertFromC(defaultValue, defaultValueLen));
{%- else %}
return nt::SetDefault{{ t.TypeName }}(pubentry, defaultValue);
{%- endif %}
}
{{ t.c.ValueType }} NT_Get{{ t.TypeName }}(NT_Handle subentry, {{ t.c.ParamType }} defaultValue{% if t.c.IsArray %}, size_t defaultValueLen, size_t* len{% endif %}) {
{%- if t.c.IsArray %}
auto cppValue = nt::Get{{ t.TypeName }}(subentry, ConvertFromC(defaultValue, defaultValueLen));
return ConvertToC<{{ t.c.ValueType[:-1] }}>(cppValue, len);
{%- else %}
return nt::Get{{ t.TypeName }}(subentry, defaultValue);
{%- endif %}
}
void NT_GetAtomic{{ t.TypeName }}(NT_Handle subentry, {{ t.c.ParamType }} defaultValue{% if t.c.IsArray %}, size_t defaultValueLen{% endif %}, struct NT_Timestamped{{ t.TypeName }}* value) {
{%- if t.c.IsArray %}
auto cppValue = nt::GetAtomic{{ t.TypeName }}(subentry, ConvertFromC(defaultValue, defaultValueLen));
{%- else %}
auto cppValue = nt::GetAtomic{{ t.TypeName }}(subentry, defaultValue);
{%- endif %}
ConvertToC(cppValue, value);
}
void NT_DisposeTimestamped{{ t.TypeName }}(struct NT_Timestamped{{ t.TypeName }}* value) {
{%- if t.TypeName == "StringArray" %}
NT_FreeStringArray(value->value, value->len);
{%- elif t.c.IsArray %}
std::free(value->value);
{%- endif %}
}
struct NT_Timestamped{{ t.TypeName }}* NT_ReadQueue{{ t.TypeName }}(NT_Handle subentry, size_t* len) {
auto arr = nt::ReadQueue{{ t.TypeName }}(subentry);
return ConvertToC<NT_Timestamped{{ t.TypeName }}>(arr, len);
}
void NT_FreeQueue{{ t.TypeName }}(struct NT_Timestamped{{ t.TypeName }}* arr, size_t len) {
for (size_t i = 0; i < len; ++i) {
NT_DisposeTimestamped{{ t.TypeName }}(&arr[i]);
}
std::free(arr);
}
{%- if not t.c.IsArray %}
{{ t.c.ValueType }}* NT_ReadQueueValues{{ t.TypeName }}(NT_Handle subentry, size_t* len) {
auto arr = nt::ReadQueueValues{{ t.TypeName }}(subentry);
return ConvertToC<{{ t.c.ValueType }}>(arr, len);
}
{%- endif %}
{% endfor %}
} // extern "C"

View File

@@ -0,0 +1,134 @@
// 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
#include "ntcore_cpp_types.h"
#include "Handle.h"
#include "InstanceImpl.h"
namespace {
template <nt::ValidType T>
struct ValuesType {
using Vector =
std::vector<typename nt::TypeInfo<std::remove_cvref_t<T>>::Value>;
};
template <>
struct ValuesType<bool> {
using Vector = std::vector<int>;
};
} // namespace
namespace nt {
template <ValidType T>
static inline bool Set(NT_Handle pubentry, typename TypeInfo<T>::View value,
int64_t time) {
if (auto ii = InstanceImpl::Get(Handle{pubentry}.GetInst())) {
return ii->localStorage.SetEntryValue(
pubentry, MakeValue<T>(value, time == 0 ? Now() : time));
} else {
return {};
}
}
template <ValidType T>
static inline bool SetDefault(NT_Handle pubentry,
typename TypeInfo<T>::View defaultValue) {
if (auto ii = InstanceImpl::Get(Handle{pubentry}.GetInst())) {
return ii->localStorage.SetDefaultEntryValue(pubentry,
MakeValue<T>(defaultValue, 1));
} else {
return {};
}
}
template <ValidType T>
static inline Timestamped<typename TypeInfo<T>::Value> GetAtomic(
NT_Handle subentry, typename TypeInfo<T>::View defaultValue) {
if (auto ii = InstanceImpl::Get(Handle{subentry}.GetInst())) {
return ii->localStorage.GetAtomic<T>(subentry, defaultValue);
} else {
return {};
}
}
template <ValidType T>
inline Timestamped<typename TypeInfo<T>::SmallRet> GetAtomic(
NT_Handle subentry,
wpi::SmallVectorImpl<typename TypeInfo<T>::SmallElem>& buf,
typename TypeInfo<T>::View defaultValue) {
if (auto ii = InstanceImpl::Get(Handle{subentry}.GetInst())) {
return ii->localStorage.GetAtomic<T>(subentry, buf, defaultValue);
} else {
return {};
}
}
template <typename T>
static inline std::vector<Timestamped<typename TypeInfo<T>::Value>> ReadQueue(
NT_Handle subentry) {
if (auto ii = InstanceImpl::Get(Handle{subentry}.GetInst())) {
return ii->localStorage.ReadQueue<T>(subentry);
} else {
return {};
}
}
template <typename T>
static inline typename ValuesType<T>::Vector ReadQueueValues(
NT_Handle subentry) {
typename ValuesType<T>::Vector rv;
auto arr = ReadQueue<T>(subentry);
rv.reserve(arr.size());
for (auto&& elem : arr) {
rv.emplace_back(std::move(elem.value));
}
return rv;
}
{% for t in types %}
bool Set{{ t.TypeName }}(NT_Handle pubentry, {{ t.cpp.ParamType }} value, int64_t time) {
return Set<{{ t.cpp.TemplateType }}>(pubentry, value, time);
}
bool SetDefault{{ t.TypeName }}(NT_Handle pubentry, {{ t.cpp.ParamType }} defaultValue) {
return SetDefault<{{ t.cpp.TemplateType }}>(pubentry, defaultValue);
}
{{ t.cpp.ValueType }} Get{{ t.TypeName }}(NT_Handle subentry, {{ t.cpp.ParamType }} defaultValue) {
return GetAtomic<{{ t.cpp.TemplateType }}>(subentry, defaultValue).value;
}
Timestamped{{ t.TypeName }} GetAtomic{{ t.TypeName }}(
NT_Handle subentry, {{ t.cpp.ParamType }} defaultValue) {
return GetAtomic<{{ t.cpp.TemplateType }}>(subentry, defaultValue);
}
std::vector<Timestamped{{ t.TypeName }}> ReadQueue{{ t.TypeName }}(NT_Handle subentry) {
return ReadQueue<{{ t.cpp.TemplateType }}>(subentry);
}
std::vector<{% if t.cpp.ValueType == "bool" %}int{% else %}{{ t.cpp.ValueType }}{% endif %}> ReadQueueValues{{ t.TypeName }}(NT_Handle subentry) {
return ReadQueueValues<{{ t.cpp.TemplateType }}>(subentry);
}
{% if t.cpp.SmallRetType and t.cpp.SmallElemType %}
{{ t.cpp.SmallRetType }} Get{{ t.TypeName }}(
NT_Handle subentry,
wpi::SmallVectorImpl<{{ t.cpp.SmallElemType }}>& buf,
{{ t.cpp.ParamType }} defaultValue) {
return GetAtomic<{{ t.cpp.TemplateType }}>(subentry, buf, defaultValue).value;
}
Timestamped{{ t.TypeName }}View GetAtomic{{ t.TypeName }}(
NT_Handle subentry,
wpi::SmallVectorImpl<{{ t.cpp.SmallElemType }}>& buf,
{{ t.cpp.ParamType }} defaultValue) {
return GetAtomic<{{ t.cpp.TemplateType }}>(subentry, buf, defaultValue);
}
{% endif %}
{% endfor %}
} // namespace nt

View File

@@ -0,0 +1,440 @@
// 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
#pragma once
#include <stdint.h>
{{ cpp.INCLUDES }}
#include <span>
#include <string_view>
#include <vector>
#include <wpi/json_fwd.h>
#include "networktables/Topic.h"
namespace wpi {
template <typename T>
class SmallVectorImpl;
} // namespace wpi
namespace nt {
class {{ TypeName }}Topic;
/**
* NetworkTables {{ TypeName }} subscriber.
*/
class {{ TypeName }}Subscriber : public Subscriber {
public:
using TopicType = {{ TypeName }}Topic;
using ValueType = {{ cpp.ValueType }};
using ParamType = {{ cpp.ParamType }};
using TimestampedValueType = Timestamped{{ TypeName }};
{% if cpp.SmallRetType and cpp.SmallElemType %}
using SmallRetType = {{ cpp.SmallRetType }};
using SmallElemType = {{ cpp.SmallElemType }};
using TimestampedValueViewType = Timestamped{{ TypeName }}View;
{% endif %}
{{ TypeName }}Subscriber() = default;
/**
* Construct from a subscriber handle; recommended to use
* {{TypeName}}Topic::Subscribe() instead.
*
* @param handle Native handle
* @param defaultValue Default value
*/
{{ TypeName }}Subscriber(NT_Subscriber handle, ParamType defaultValue);
/**
* Get the last published value.
* If no value has been published, returns the stored default value.
*
* @return value
*/
ValueType Get() const;
/**
* Get the last published value.
* If no value has been published, returns the passed defaultValue.
*
* @param defaultValue default value to return if no value has been published
* @return value
*/
ValueType Get(ParamType defaultValue) const;
{% if cpp.SmallRetType and cpp.SmallElemType %}
/**
* Get the last published value.
* If no value has been published, returns the stored default value.
*
* @param buf storage for returned value
* @return value
*/
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& buf) const;
/**
* Get the last published value.
* If no value has been published, returns the passed defaultValue.
*
* @param buf storage for returned value
* @param defaultValue default value to return if no value has been published
* @return value
*/
SmallRetType Get(wpi::SmallVectorImpl<SmallElemType>& buf, ParamType defaultValue) const;
{% endif %}
/**
* Get the last published value along with its timestamp
* If no value has been published, returns the stored default value and a
* timestamp of 0.
*
* @return timestamped value
*/
TimestampedValueType GetAtomic() const;
/**
* Get the last published value along with its timestamp.
* If no value has been published, returns the passed defaultValue and a
* timestamp of 0.
*
* @param defaultValue default value to return if no value has been published
* @return timestamped value
*/
TimestampedValueType GetAtomic(ParamType defaultValue) const;
{% if cpp.SmallRetType and cpp.SmallElemType %}
/**
* Get the last published value along with its timestamp.
* If no value has been published, returns the stored default value and a
* timestamp of 0.
*
* @param buf storage for returned value
* @return timestamped value
*/
TimestampedValueViewType GetAtomic(
wpi::SmallVectorImpl<SmallElemType>& buf) const;
/**
* Get the last published value along with its timestamp.
* If no value has been published, returns the passed defaultValue and a
* timestamp of 0.
*
* @param buf storage for returned value
* @param defaultValue default value to return if no value has been published
* @return timestamped value
*/
TimestampedValueViewType GetAtomic(
wpi::SmallVectorImpl<SmallElemType>& buf,
ParamType defaultValue) const;
{% endif %}
/**
* Get an array of all value changes since the last call to ReadQueue.
* Also provides a timestamp for each value.
*
* @note The "poll storage" subscribe option can be used to set the queue
* depth.
*
* @return Array of timestamped values; empty array if no new changes have
* been published since the previous call.
*/
std::vector<TimestampedValueType> ReadQueue();
/**
* Get the corresponding topic.
*
* @return Topic
*/
TopicType GetTopic() const;
private:
ValueType m_defaultValue;
};
/**
* NetworkTables {{ TypeName }} publisher.
*/
class {{ TypeName }}Publisher : public Publisher {
public:
using TopicType = {{ TypeName }}Topic;
using ValueType = {{ cpp.ValueType }};
using ParamType = {{ cpp.ParamType }};
{% if cpp.SmallRetType and cpp.SmallElemType %}
using SmallRetType = {{ cpp.SmallRetType }};
using SmallElemType = {{ cpp.SmallElemType }};
{% endif %}
using TimestampedValueType = Timestamped{{ TypeName }};
{{ TypeName }}Publisher() = default;
/**
* Construct from a publisher handle; recommended to use
* {{TypeName}}Topic::Publish() instead.
*
* @param handle Native handle
*/
explicit {{ TypeName }}Publisher(NT_Publisher handle);
/**
* Publish a new value.
*
* @param value value to publish
* @param time timestamp; 0 indicates current NT time should be used
*/
void Set(ParamType value, int64_t time = 0);
/**
* Publish a default value.
* On reconnect, a default value will never be used in preference to a
* published value.
*
* @param value value
*/
void SetDefault(ParamType value);
/**
* Get the corresponding topic.
*
* @return Topic
*/
TopicType GetTopic() const;
};
/**
* NetworkTables {{ TypeName }} entry.
*
* @note Unlike NetworkTableEntry, the entry goes away when this is destroyed.
*/
class {{ TypeName }}Entry final : public {{ TypeName }}Subscriber,
public {{ TypeName }}Publisher {
public:
using SubscriberType = {{ TypeName }}Subscriber;
using PublisherType = {{ TypeName }}Publisher;
using TopicType = {{ TypeName }}Topic;
using ValueType = {{ cpp.ValueType }};
using ParamType = {{ cpp.ParamType }};
{% if cpp.SmallRetType and cpp.SmallElemType %}
using SmallRetType = {{ cpp.SmallRetType }};
using SmallElemType = {{ cpp.SmallElemType }};
{% endif %}
using TimestampedValueType = Timestamped{{ TypeName }};
{{ TypeName }}Entry() = default;
/**
* Construct from an entry handle; recommended to use
* {{TypeName}}Topic::GetEntry() instead.
*
* @param handle Native handle
* @param defaultValue Default value
*/
{{ TypeName }}Entry(NT_Entry handle, ParamType defaultValue);
/**
* Determines if the native handle is valid.
*
* @return True if the native handle is valid, false otherwise.
*/
explicit operator bool() const { return m_subHandle != 0; }
/**
* Gets the native handle for the entry.
*
* @return Native handle
*/
NT_Entry GetHandle() const { return m_subHandle; }
/**
* Get the corresponding topic.
*
* @return Topic
*/
TopicType GetTopic() const;
/**
* Stops publishing the entry if it's published.
*/
void Unpublish();
};
/**
* NetworkTables {{ TypeName }} topic.
*/
class {{ TypeName }}Topic final : public Topic {
public:
using SubscriberType = {{ TypeName }}Subscriber;
using PublisherType = {{ TypeName }}Publisher;
using EntryType = {{ TypeName }}Entry;
using ValueType = {{ cpp.ValueType }};
using ParamType = {{ cpp.ParamType }};
using TimestampedValueType = Timestamped{{ TypeName }};
{%- if TypeString %}
/** The default type string for this topic type. */
static constexpr std::string_view kTypeString = {{ TypeString }};
{%- endif %}
{{ TypeName }}Topic() = default;
/**
* Construct from a topic handle; recommended to use
* NetworkTableInstance::Get{{TypeName}}Topic() instead.
*
* @param handle Native handle
*/
explicit {{ TypeName }}Topic(NT_Topic handle) : Topic{handle} {}
/**
* Construct from a generic topic.
*
* @param topic Topic
*/
explicit {{ TypeName }}Topic(Topic topic) : Topic{topic} {}
/**
* Create a new subscriber to the topic.
*
* <p>The subscriber is only active as long as the returned object
* is not destroyed.
*
* @note 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.
*
{%- if not TypeString %}
* @param typeString type string
{% endif %}
* @param defaultValue default value used when a default is not provided to a
* getter function
* @param options subscribe options
* @return subscriber
*/
[[nodiscard]]
SubscriberType Subscribe(
{% if not TypeString %}std::string_view typeString, {% endif %}ParamType defaultValue,
const PubSubOptions& options = kDefaultPubSubOptions);
{%- if TypeString %}
/**
* Create a new subscriber to the topic, with specific type string.
*
* <p>The subscriber is only active as long as the returned object
* is not destroyed.
*
* @note 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
*/
[[nodiscard]]
SubscriberType SubscribeEx(
std::string_view typeString, ParamType defaultValue,
const PubSubOptions& options = kDefaultPubSubOptions);
{% endif %}
/**
* Create a new publisher to the topic.
*
* The publisher is only active as long as the returned object
* is not destroyed.
*
* @note 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.
*
{%- if not TypeString %}
* @param typeString type string
{% endif %}
* @param options publish options
* @return publisher
*/
[[nodiscard]]
PublisherType Publish({% if not TypeString %}std::string_view typeString, {% endif %}const PubSubOptions& options = kDefaultPubSubOptions);
/**
* Create a new publisher to the topic, with type string and initial
* properties.
*
* The publisher is only active as long as the returned object
* is not destroyed.
*
* @note 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
*/
[[nodiscard]]
PublisherType PublishEx(std::string_view typeString,
const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions);
/**
* Create a new entry for the topic.
*
* Entries act as a combination of a subscriber and a weak publisher. The
* subscriber is active as long as the entry is not destroyed. The publisher
* is created when the entry is first written to, and remains active until
* either Unpublish() is called or the entry is destroyed.
*
* @note 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.
*
{%- if not TypeString %}
* @param typeString type string
{% endif %}
* @param defaultValue default value used when a default is not provided to a
* getter function
* @param options publish and/or subscribe options
* @return entry
*/
[[nodiscard]]
EntryType GetEntry({% if not TypeString %}std::string_view typeString, {% endif %}ParamType defaultValue,
const PubSubOptions& options = kDefaultPubSubOptions);
{%- if TypeString %}
/**
* Create a new entry for the topic, with specific type string.
*
* Entries act as a combination of a subscriber and a weak publisher. The
* subscriber is active as long as the entry is not destroyed. The publisher
* is created when the entry is first written to, and remains active until
* either Unpublish() is called or the entry is destroyed.
*
* @note 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
*/
[[nodiscard]]
EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue,
const PubSubOptions& options = kDefaultPubSubOptions);
{% endif %}
};
} // namespace nt
#include "networktables/{{ TypeName }}Topic.inc"

View File

@@ -0,0 +1,140 @@
// 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
#pragma once
#include <vector>
#include "networktables/{{ TypeName }}Topic.h"
#include "networktables/NetworkTableType.h"
#include "ntcore_cpp.h"
namespace nt {
inline {{ TypeName }}Subscriber::{{ TypeName }}Subscriber(
NT_Subscriber handle, {{ cpp.ParamType }} defaultValue)
: Subscriber{handle},
m_defaultValue{{ '{' }}{{ cpp.DefaultValueCopy|default('defaultValue') }}} {}
inline {{ cpp.ValueType }} {{ TypeName }}Subscriber::Get() const {
return Get(m_defaultValue);
}
inline {{ cpp.ValueType }} {{ TypeName }}Subscriber::Get(
{{ cpp.ParamType }} defaultValue) const {
return ::nt::Get{{ TypeName }}(m_subHandle, defaultValue);
}
{% if cpp.SmallRetType and cpp.SmallElemType %}
inline {{ cpp.SmallRetType }} {{ TypeName }}Subscriber::Get(wpi::SmallVectorImpl<{{ cpp.SmallElemType }}>& buf) const {
return Get(buf, m_defaultValue);
}
inline {{ cpp.SmallRetType }} {{ TypeName }}Subscriber::Get(wpi::SmallVectorImpl<{{ cpp.SmallElemType }}>& buf, {{ cpp.ParamType }} defaultValue) const {
return nt::Get{{ TypeName }}(m_subHandle, buf, defaultValue);
}
{% endif %}
inline Timestamped{{ TypeName }} {{ TypeName }}Subscriber::GetAtomic() const {
return GetAtomic(m_defaultValue);
}
inline Timestamped{{ TypeName }} {{ TypeName }}Subscriber::GetAtomic(
{{ cpp.ParamType }} defaultValue) const {
return ::nt::GetAtomic{{ TypeName }}(m_subHandle, defaultValue);
}
{% if cpp.SmallRetType and cpp.SmallElemType %}
inline Timestamped{{ TypeName }}View {{ TypeName }}Subscriber::GetAtomic(wpi::SmallVectorImpl<{{ cpp.SmallElemType }}>& buf) const {
return GetAtomic(buf, m_defaultValue);
}
inline Timestamped{{ TypeName }}View {{ TypeName }}Subscriber::GetAtomic(wpi::SmallVectorImpl<{{ cpp.SmallElemType }}>& buf, {{ cpp.ParamType }} defaultValue) const {
return nt::GetAtomic{{ TypeName }}(m_subHandle, buf, defaultValue);
}
{% endif %}
inline std::vector<Timestamped{{ TypeName }}>
{{ TypeName }}Subscriber::ReadQueue() {
return ::nt::ReadQueue{{ TypeName }}(m_subHandle);
}
inline {{ TypeName }}Topic {{ TypeName }}Subscriber::GetTopic() const {
return {{ TypeName }}Topic{::nt::GetTopicFromHandle(m_subHandle)};
}
inline {{ TypeName }}Publisher::{{ TypeName }}Publisher(NT_Publisher handle)
: Publisher{handle} {}
inline void {{ TypeName }}Publisher::Set({{ cpp.ParamType }} value,
int64_t time) {
::nt::Set{{ TypeName }}(m_pubHandle, value, time);
}
inline void {{ TypeName }}Publisher::SetDefault({{ cpp.ParamType }} value) {
::nt::SetDefault{{ TypeName }}(m_pubHandle, value);
}
inline {{ TypeName }}Topic {{ TypeName }}Publisher::GetTopic() const {
return {{ TypeName }}Topic{::nt::GetTopicFromHandle(m_pubHandle)};
}
inline {{ TypeName }}Entry::{{ TypeName }}Entry(
NT_Entry handle, {{ cpp.ParamType }} defaultValue)
: {{ TypeName }}Subscriber{handle, defaultValue},
{{ TypeName }}Publisher{handle} {}
inline {{ TypeName }}Topic {{ TypeName }}Entry::GetTopic() const {
return {{ TypeName }}Topic{::nt::GetTopicFromHandle(m_subHandle)};
}
inline void {{ TypeName }}Entry::Unpublish() {
::nt::Unpublish(m_pubHandle);
}
inline {{ TypeName }}Subscriber {{ TypeName }}Topic::Subscribe(
{% if not TypeString %}std::string_view typeString, {% endif %}{{ cpp.ParamType }} defaultValue,
const PubSubOptions& options) {
return {{ TypeName }}Subscriber{
::nt::Subscribe(m_handle, NT_{{ cpp.TYPE_NAME }}, {{ TypeString|default('typeString') }}, options),
defaultValue};
}
{%- if TypeString %}
inline {{ TypeName }}Subscriber {{ TypeName }}Topic::SubscribeEx(
std::string_view typeString, {{ cpp.ParamType }} defaultValue,
const PubSubOptions& options) {
return {{ TypeName }}Subscriber{
::nt::Subscribe(m_handle, NT_{{ cpp.TYPE_NAME }}, typeString, options),
defaultValue};
}
{% endif %}
inline {{ TypeName }}Publisher {{ TypeName }}Topic::Publish(
{% if not TypeString %}std::string_view typeString, {% endif %}const PubSubOptions& options) {
return {{ TypeName }}Publisher{
::nt::Publish(m_handle, NT_{{ cpp.TYPE_NAME }}, {{ TypeString|default('typeString') }}, options)};
}
inline {{ TypeName }}Publisher {{ TypeName }}Topic::PublishEx(
std::string_view typeString,
const wpi::json& properties, const PubSubOptions& options) {
return {{ TypeName }}Publisher{
::nt::PublishEx(m_handle, NT_{{ cpp.TYPE_NAME }}, typeString, properties, options)};
}
inline {{ TypeName }}Entry {{ TypeName }}Topic::GetEntry(
{% if not TypeString %}std::string_view typeString, {% endif %}{{ cpp.ParamType }} defaultValue,
const PubSubOptions& options) {
return {{ TypeName }}Entry{
::nt::GetEntry(m_handle, NT_{{ cpp.TYPE_NAME }}, {{ TypeString|default('typeString') }}, options),
defaultValue};
}
{%- if TypeString %}
inline {{ TypeName }}Entry {{ TypeName }}Topic::GetEntryEx(
std::string_view typeString, {{ cpp.ParamType }} defaultValue,
const PubSubOptions& options) {
return {{ TypeName }}Entry{
::nt::GetEntry(m_handle, NT_{{ cpp.TYPE_NAME }}, typeString, options),
defaultValue};
}
{% endif %}
} // namespace nt

View File

@@ -0,0 +1,154 @@
// 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
#pragma once
#include <stdint.h>
#include "ntcore_c.h"
#ifdef __cplusplus
extern "C" {
#endif
{% for t in types %}
/**
* Timestamped {{ t.TypeName }}.
* @ingroup ntcore_c_api
*/
struct NT_Timestamped{{ t.TypeName }} {
/**
* Time in local time base.
*/
int64_t time;
/**
* Time in server time base. May be 0 or 1 for locally set values.
*/
int64_t serverTime;
/**
* Value.
*/
{{ t.c.ValueType }} value;
{%- if t.c.IsArray %}
/**
* Value length.
*/
size_t len;
{% endif %}
};
/**
* @defgroup ntcore_{{ t.TypeName }}_cfunc {{ t.TypeName }} Functions
* @ingroup ntcore_c_api
* @{
*/
/**
* Publish a new value.
*
* @param pubentry publisher or entry handle
* @param time timestamp; 0 indicates current NT time should be used
* @param value value to publish
{%- if t.c.IsArray %}
* @param len length of value
{% endif %}
*/
NT_Bool NT_Set{{ t.TypeName }}(NT_Handle pubentry, int64_t time, {{ t.c.ParamType }} value{% if t.c.IsArray %}, size_t len{% endif %});
/**
* Publish a default value.
* On reconnect, a default value will never be used in preference to a
* published value.
*
* @param pubentry publisher or entry handle
* @param defaultValue default value
{%- if t.c.IsArray %}
* @param defaultValueLen length of default value
{% endif %}
*/
NT_Bool NT_SetDefault{{ t.TypeName }}(NT_Handle pubentry, {{ t.c.ParamType }} defaultValue{% if t.c.IsArray %}, size_t defaultValueLen{% endif %});
/**
* Get the last published value.
* If no value has been published, returns the passed defaultValue.
*
* @param subentry subscriber or entry handle
* @param defaultValue default value to return if no value has been published
{%- if t.c.IsArray %}
* @param defaultValueLen length of default value
* @param len length of returned value (output)
{% endif %}
* @return value
*/
{{ t.c.ValueType }} NT_Get{{ t.TypeName }}(NT_Handle subentry, {{ t.c.ParamType }} defaultValue{% if t.c.IsArray %}, size_t defaultValueLen, size_t* len{% endif %});
/**
* Get the last published value along with its timestamp.
* If no value has been published, returns the passed defaultValue and a
* timestamp of 0.
*
* @param subentry subscriber or entry handle
* @param defaultValue default value to return if no value has been published
{%- if t.c.IsArray %}
* @param defaultValueLen length of default value
{% endif %}
* @param value timestamped value (output)
*/
void NT_GetAtomic{{ t.TypeName }}(NT_Handle subentry, {{ t.c.ParamType }} defaultValue{% if t.c.IsArray %}, size_t defaultValueLen{% endif %}, struct NT_Timestamped{{ t.TypeName }}* value);
/**
* Disposes a timestamped value (as returned by NT_GetAtomic{{ t.TypeName }}).
*
* @param value timestamped value
*/
void NT_DisposeTimestamped{{ t.TypeName }}(struct NT_Timestamped{{ t.TypeName }}* value);
/**
* Get an array of all value changes since the last call to ReadQueue.
* Also provides a timestamp for each value.
*
* @note The "poll storage" subscribe option can be used to set the queue
* depth.
*
* @param subentry subscriber or entry handle
* @param len length of returned array (output)
* @return Array of timestamped values; NULL if no new changes have
* been published since the previous call.
*/
struct NT_Timestamped{{ t.TypeName }}* NT_ReadQueue{{ t.TypeName }}(NT_Handle subentry, size_t* len);
/**
* Frees a timestamped array of values (as returned by NT_ReadQueue{{ t.TypeName }}).
*
* @param arr array
* @param len length of array
*/
void NT_FreeQueue{{ t.TypeName }}(struct NT_Timestamped{{ t.TypeName }}* arr, size_t len);
{%- if not t.c.IsArray %}
/**
* Get an array of all value changes since the last call to ReadQueue.
*
* @note The "poll storage" subscribe option can be used to set the queue
* depth.
*
* @param subentry subscriber or entry handle
* @param len length of returned array (output)
* @return Array of values; NULL if no new changes have
* been published since the previous call.
*/
{{ t.c.ValueType }}* NT_ReadQueueValues{{ t.TypeName }}(NT_Handle subentry, size_t* len);
{%- endif %}
/** @} */
{% endfor %}
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -0,0 +1,144 @@
// 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
#pragma once
#include <stdint.h>
#include <span>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "ntcore_c.h"
namespace wpi {
template <typename T>
class SmallVectorImpl;
} // namespace wpi
namespace nt {
/**
* Timestamped value.
* @ingroup ntcore_cpp_handle_api
*/
template <typename T>
struct Timestamped {
Timestamped() = default;
Timestamped(int64_t time, int64_t serverTime, T value)
: time{time}, serverTime{serverTime}, value{std::move(value)} {}
/**
* Time in local time base.
*/
int64_t time = 0;
/**
* Time in server time base. May be 0 or 1 for locally set values.
*/
int64_t serverTime = 0;
/**
* Value.
*/
T value = {};
};
{% for t in types %}
/**
* Timestamped {{ t.TypeName }}.
* @ingroup ntcore_cpp_handle_api
*/
using Timestamped{{ t.TypeName }} = Timestamped<{{ t.cpp.ValueType }}>;
{% if t.cpp.SmallRetType %}
/**
* Timestamped {{ t.TypeName }} view (for SmallVector-taking functions).
* @ingroup ntcore_cpp_handle_api
*/
using Timestamped{{ t.TypeName }}View = Timestamped<{{ t.cpp.SmallRetType }}>;
{% endif %}
/**
* @defgroup ntcore_{{ t.TypeName }}_func {{ t.TypeName }} Functions
* @ingroup ntcore_cpp_handle_api
* @{
*/
/**
* Publish a new value.
*
* @param pubentry publisher or entry handle
* @param value value to publish
* @param time timestamp; 0 indicates current NT time should be used
*/
bool Set{{ t.TypeName }}(NT_Handle pubentry, {{ t.cpp.ParamType }} value, int64_t time = 0);
/**
* Publish a default value.
* On reconnect, a default value will never be used in preference to a
* published value.
*
* @param pubentry publisher or entry handle
* @param defaultValue default value
*/
bool SetDefault{{ t.TypeName }}(NT_Handle pubentry, {{ t.cpp.ParamType }} defaultValue);
/**
* Get the last published value.
* If no value has been published, returns the passed defaultValue.
*
* @param subentry subscriber or entry handle
* @param defaultValue default value to return if no value has been published
* @return value
*/
{{ t.cpp.ValueType }} Get{{ t.TypeName }}(NT_Handle subentry, {{ t.cpp.ParamType }} defaultValue);
/**
* Get the last published value along with its timestamp.
* If no value has been published, returns the passed defaultValue and a
* timestamp of 0.
*
* @param subentry subscriber or entry handle
* @param defaultValue default value to return if no value has been published
* @return timestamped value
*/
Timestamped{{ t.TypeName }} GetAtomic{{ t.TypeName}}(NT_Handle subentry, {{ t.cpp.ParamType }} defaultValue);
/**
* Get an array of all value changes since the last call to ReadQueue.
* Also provides a timestamp for each value.
*
* @note The "poll storage" subscribe option can be used to set the queue
* depth.
*
* @param subentry subscriber or entry handle
* @return Array of timestamped values; empty array if no new changes have
* been published since the previous call.
*/
std::vector<Timestamped{{ t.TypeName }}> ReadQueue{{ t.TypeName }}(NT_Handle subentry);
/**
* Get an array of all value changes since the last call to ReadQueue.
*
* @note The "poll storage" subscribe option can be used to set the queue
* depth.
*
* @param subentry subscriber or entry handle
* @return Array of values; empty array if no new changes have
* been published since the previous call.
*/
std::vector<{% if t.cpp.ValueType == "bool" %}int{% else %}{{ t.cpp.ValueType }}{% endif %}> ReadQueueValues{{ t.TypeName }}(NT_Handle subentry);
{% if t.cpp.SmallRetType and t.cpp.SmallElemType %}
{{ t.cpp.SmallRetType }} Get{{ t.TypeName }}(NT_Handle subentry, wpi::SmallVectorImpl<{{ t.cpp.SmallElemType }}>& buf, {{ t.cpp.ParamType }} defaultValue);
Timestamped{{ t.TypeName }}View GetAtomic{{ t.TypeName }}(
NT_Handle subentry,
wpi::SmallVectorImpl<{{ t.cpp.SmallElemType }}>& buf,
{{ t.cpp.ParamType }} defaultValue);
{% endif %}
/** @} */
{% endfor %}
} // namespace nt