WPILibC++  2019.1.1-beta-2-25-g73de336
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
NetworkTableEntry.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #ifndef NTCORE_NETWORKTABLES_NETWORKTABLEENTRY_H_
9 #define NTCORE_NETWORKTABLES_NETWORKTABLEENTRY_H_
10 
11 #include <stdint.h>
12 
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 #include <wpi/StringRef.h>
18 #include <wpi/Twine.h>
19 
20 #include "networktables/NetworkTableType.h"
21 #include "networktables/NetworkTableValue.h"
22 #include "networktables/RpcCall.h"
23 #include "ntcore_c.h"
24 #include "ntcore_cpp.h"
25 
26 namespace nt {
27 
28 using wpi::ArrayRef;
29 using wpi::StringRef;
30 using wpi::Twine;
31 
32 class NetworkTableInstance;
33 
38 class NetworkTableEntry final {
39  public:
43  enum Flags { kPersistent = NT_PERSISTENT };
44 
49 
55  explicit NetworkTableEntry(NT_Entry handle);
56 
62  explicit operator bool() const { return m_handle != 0; }
63 
69  NT_Entry GetHandle() const;
70 
77 
83  bool Exists() const;
84 
90  std::string GetName() const;
91 
97  NetworkTableType GetType() const;
98 
104  unsigned int GetFlags() const;
105 
111  uint64_t GetLastChange() const;
112 
118  EntryInfo GetInfo() const;
119 
125  std::shared_ptr<Value> GetValue() const;
126 
134  bool GetBoolean(bool defaultValue) const;
135 
143  double GetDouble(double defaultValue) const;
144 
152  std::string GetString(StringRef defaultValue) const;
153 
161  std::string GetRaw(StringRef defaultValue) const;
162 
177  std::vector<int> GetBooleanArray(ArrayRef<int> defaultValue) const;
178 
189  std::vector<double> GetDoubleArray(ArrayRef<double> defaultValue) const;
190 
201  std::vector<std::string> GetStringArray(
202  ArrayRef<std::string> defaultValue) const;
203 
210  bool SetDefaultValue(std::shared_ptr<Value> value);
211 
218  bool SetDefaultBoolean(bool defaultValue);
219 
226  bool SetDefaultDouble(double defaultValue);
227 
234  bool SetDefaultString(const Twine& defaultValue);
235 
242  bool SetDefaultRaw(StringRef defaultValue);
243 
250  bool SetDefaultBooleanArray(ArrayRef<int> defaultValue);
251 
258  bool SetDefaultDoubleArray(ArrayRef<double> defaultValue);
259 
266  bool SetDefaultStringArray(ArrayRef<std::string> defaultValue);
267 
274  bool SetValue(std::shared_ptr<Value> value);
275 
282  bool SetBoolean(bool value);
283 
290  bool SetDouble(double value);
291 
298  bool SetString(const Twine& value);
299 
306  bool SetRaw(StringRef value);
307 
314  bool SetBooleanArray(ArrayRef<int> value);
315 
322  bool SetDoubleArray(ArrayRef<double> value);
323 
331 
338  void ForceSetValue(std::shared_ptr<Value> value);
339 
346  void ForceSetBoolean(bool value);
347 
354  void ForceSetDouble(double value);
355 
362  void ForceSetString(const Twine& value);
363 
370  void ForceSetRaw(StringRef value);
371 
379 
387 
395 
401  void SetFlags(unsigned int flags);
402 
408  void ClearFlags(unsigned int flags);
409 
413  void SetPersistent();
414 
418  void ClearPersistent();
419 
425  bool IsPersistent() const;
426 
430  void Delete();
431 
439  void CreateRpc(std::function<void(const RpcAnswer& answer)> callback);
440 
447  void CreatePolledRpc();
448 
458  RpcCall CallRpc(StringRef params);
459 
467  NT_EntryListener AddListener(
468  std::function<void(const EntryNotification& event)> callback,
469  unsigned int flags) const;
470 
476  void RemoveListener(NT_EntryListener entry_listener);
477 
482  bool operator==(const NetworkTableEntry& oth) const {
483  return m_handle == oth.m_handle;
484  }
485 
487  bool operator!=(const NetworkTableEntry& oth) const {
488  return !(*this == oth);
489  }
490 
491  protected:
492  /* Native handle */
493  NT_Entry m_handle;
494 };
495 
496 } // namespace nt
497 
498 #include "networktables/NetworkTableEntry.inl"
499 
500 #endif // NTCORE_NETWORKTABLES_NETWORKTABLEENTRY_H_
bool Exists() const
Determines if the entry currently exists.
Definition: NetworkTableEntry.inl:20
EntryInfo GetInfo() const
Gets combined information about the entry.
Definition: NetworkTableEntry.inl:40
void ForceSetDoubleArray(ArrayRef< double > value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:184
void CreateRpc(std::function< void(const RpcAnswer &answer)> callback)
Create a callback-based RPC entry point.
Definition: NetworkTableEntry.inl:211
Flags
Flag values (as returned by GetFlags()).
Definition: NetworkTableEntry.h:43
void RemoveListener(NT_EntryListener entry_listener)
Remove an entry listener.
Definition: NetworkTableEntry.inl:226
void ClearFlags(unsigned int flags)
Clears flags.
Definition: NetworkTableEntry.inl:197
bool operator==(const NetworkTableEntry &oth) const
Equality operator.
Definition: NetworkTableEntry.h:482
void ForceSetBooleanArray(ArrayRef< int > value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:180
NetworkTables Remote Procedure Call.
Definition: RpcCall.h:24
uint64_t GetLastChange() const
Gets the last time the entry's value was changed.
Definition: NetworkTableEntry.inl:36
NT_EntryListener AddListener(std::function< void(const EntryNotification &event)> callback, unsigned int flags) const
Add a listener for changes to this entry.
Definition: NetworkTableEntry.inl:220
std::vector< std::string > GetStringArray(ArrayRef< std::string > defaultValue) const
Gets the entry's value as a string array.
Definition: NetworkTableEntry.inl:86
void ForceSetString(const Twine &value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:172
std::string GetName() const
Gets the name of the entry (the key).
Definition: NetworkTableEntry.inl:24
NetworkTables Remote Procedure Call (Server Side)
Definition: ntcore_cpp.h:134
NetworkTableEntry()
Construct invalid instance.
Definition: NetworkTableEntry.inl:13
NetworkTableType GetType() const
Gets the type of the entry.
Definition: NetworkTableEntry.inl:28
void ForceSetValue(std::shared_ptr< Value > value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:160
void Delete()
Deletes the entry.
Definition: NetworkTableEntry.inl:209
bool SetDefaultStringArray(ArrayRef< std::string > defaultValue)
Sets the entry's value if it does not exist.
Definition: NetworkTableEntry.inl:123
bool SetDefaultDouble(double defaultValue)
Sets the entry's value if it does not exist.
Definition: NetworkTableEntry.inl:101
NetworkTables Entry Notification.
Definition: ntcore_cpp.h:180
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:41
RpcCall CallRpc(StringRef params)
Call a RPC function.
Definition: NetworkTableEntry.inl:216
std::string GetRaw(StringRef defaultValue) const
Gets the entry's value as a raw.
Definition: NetworkTableEntry.inl:66
void ForceSetRaw(StringRef value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:176
void ForceSetBoolean(bool value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:164
void ClearPersistent()
Stop making value persistent through program restarts.
Definition: NetworkTableEntry.inl:203
NetworkTables Instance.
Definition: NetworkTableInstance.h:53
NetworkTableType
NetworkTable entry type.
Definition: NetworkTableType.h:19
void ForceSetStringArray(ArrayRef< std::string > value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:188
void SetPersistent()
Make value persistent through program restarts.
Definition: NetworkTableEntry.inl:201
bool SetString(const Twine &value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:140
bool SetBoolean(bool value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:132
bool SetRaw(StringRef value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:144
std::string GetString(StringRef defaultValue) const
Gets the entry's value as a string.
Definition: NetworkTableEntry.inl:60
bool operator!=(const NetworkTableEntry &oth) const
Inequality operator.
Definition: NetworkTableEntry.h:487
bool SetDefaultBooleanArray(ArrayRef< int > defaultValue)
Sets the entry's value if it does not exist.
Definition: NetworkTableEntry.inl:113
NetworkTables (ntcore) namespace.
Definition: ITable.h:21
NetworkTables Entry Information.
Definition: ntcore_cpp.h:44
std::vector< int > GetBooleanArray(ArrayRef< int > defaultValue) const
Gets the entry's value as a boolean array.
Definition: NetworkTableEntry.inl:72
unsigned int GetFlags() const
Returns the flags.
Definition: NetworkTableEntry.inl:32
bool SetValue(std::shared_ptr< Value > value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:128
void CreatePolledRpc()
Create a polled RPC entry point.
std::shared_ptr< Value > GetValue() const
Gets the entry's value.
Definition: NetworkTableEntry.inl:44
void ForceSetDouble(double value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:168
double GetDouble(double defaultValue) const
Gets the entry's value as a double.
Definition: NetworkTableEntry.inl:54
bool SetStringArray(ArrayRef< std::string > value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:156
bool SetDefaultString(const Twine &defaultValue)
Sets the entry's value if it does not exist.
Definition: NetworkTableEntry.inl:105
bool SetDefaultDoubleArray(ArrayRef< double > defaultValue)
Sets the entry's value if it does not exist.
Definition: NetworkTableEntry.inl:118
bool SetDefaultValue(std::shared_ptr< Value > value)
Sets the entry's value if it does not exist.
Definition: NetworkTableEntry.inl:93
bool SetDefaultBoolean(bool defaultValue)
Sets the entry's value if it does not exist.
Definition: NetworkTableEntry.inl:97
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
bool GetBoolean(bool defaultValue) const
Gets the entry's value as a boolean.
Definition: NetworkTableEntry.inl:48
NetworkTableInstance GetInstance() const
Gets the instance for the entry.
NT_Entry GetHandle() const
Gets the native handle for the entry.
Definition: NetworkTableEntry.inl:18
bool SetDouble(double value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:136
bool SetDefaultRaw(StringRef defaultValue)
Sets the entry's value if it does not exist.
Definition: NetworkTableEntry.inl:109
NetworkTables Entry.
Definition: NetworkTableEntry.h:38
bool IsPersistent() const
Returns whether the value is persistent through program restarts.
Definition: NetworkTableEntry.inl:205
bool SetBooleanArray(ArrayRef< int > value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:148
std::vector< double > GetDoubleArray(ArrayRef< double > defaultValue) const
Gets the entry's value as a double array.
Definition: NetworkTableEntry.inl:79
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
void SetFlags(unsigned int flags)
Sets flags.
Definition: NetworkTableEntry.inl:193
bool SetDoubleArray(ArrayRef< double > value)
Sets the entry's value.
Definition: NetworkTableEntry.inl:152