WPILibC++  unspecified
NetworkTableEntry.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2017-2018. 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 <llvm/StringRef.h>
18 #include <llvm/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 llvm::ArrayRef;
29 using llvm::StringRef;
30 using llvm::Twine;
31 
32 class NetworkTableInstance;
33 
35 class NetworkTableEntry final {
36  public:
40  enum Flags { kPersistent = NT_PERSISTENT };
41 
46 
51  explicit NetworkTableEntry(NT_Entry handle);
52 
57  explicit operator bool() const { return m_handle != 0; }
58 
63  NT_Entry GetHandle() const;
64 
70 
75  bool Exists() const;
76 
81  std::string GetName() const;
82 
87  NetworkTableType GetType() const;
88 
93  unsigned int GetFlags() const;
94 
99  uint64_t GetLastChange() const;
100 
105  EntryInfo GetInfo() const;
106 
112  std::shared_ptr<Value> GetValue() const;
113 
121  bool GetBoolean(bool defaultValue) const;
122 
130  double GetDouble(double defaultValue) const;
131 
139  std::string GetString(StringRef defaultValue) const;
140 
148  std::string GetRaw(StringRef defaultValue) const;
149 
163  std::vector<int> GetBooleanArray(ArrayRef<int> defaultValue) const;
164 
174  std::vector<double> GetDoubleArray(ArrayRef<double> defaultValue) const;
175 
185  std::vector<std::string> GetStringArray(
186  ArrayRef<std::string> defaultValue) const;
187 
193  bool SetDefaultValue(std::shared_ptr<Value> value);
194 
200  bool SetDefaultBoolean(bool defaultValue);
201 
207  bool SetDefaultDouble(double defaultValue);
208 
214  bool SetDefaultString(const Twine& defaultValue);
215 
221  bool SetDefaultRaw(StringRef defaultValue);
222 
228  bool SetDefaultBooleanArray(ArrayRef<int> defaultValue);
229 
235  bool SetDefaultDoubleArray(ArrayRef<double> defaultValue);
236 
242  bool SetDefaultStringArray(ArrayRef<std::string> defaultValue);
243 
249  bool SetValue(std::shared_ptr<Value> value);
250 
256  bool SetBoolean(bool value);
257 
263  bool SetDouble(double value);
264 
270  bool SetString(const Twine& value);
271 
277  bool SetRaw(StringRef value);
278 
284  bool SetBooleanArray(ArrayRef<int> value);
285 
291  bool SetDoubleArray(ArrayRef<double> value);
292 
299 
305  void ForceSetValue(std::shared_ptr<Value> value);
306 
312  void ForceSetBoolean(bool value);
313 
319  void ForceSetDouble(double value);
320 
326  void ForceSetString(const Twine& value);
327 
333  void ForceSetRaw(StringRef value);
334 
341 
348 
355 
360  void SetFlags(unsigned int flags);
361 
366  void ClearFlags(unsigned int flags);
367 
371  void SetPersistent();
372 
376  void ClearPersistent();
377 
382  bool IsPersistent() const;
383 
387  void Delete();
388 
395  void CreateRpc(std::function<void(const RpcAnswer& answer)> callback);
396 
403  void CreatePolledRpc();
404 
413  RpcCall CallRpc(StringRef params);
414 
422  NT_EntryListener AddListener(
423  std::function<void(const EntryNotification& event)> callback,
424  unsigned int flags) const;
425 
430  void RemoveListener(NT_EntryListener entry_listener);
431 
436  bool operator==(const NetworkTableEntry& oth) const {
437  return m_handle == oth.m_handle;
438  }
439 
441  bool operator!=(const NetworkTableEntry& oth) const {
442  return !(*this == oth);
443  }
444 
445  protected:
446  /* Native handle */
447  NT_Entry m_handle;
448 };
449 
450 } // namespace nt
451 
452 #include "networktables/NetworkTableEntry.inl"
453 
454 #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&#39;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
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:436
void ForceSetBooleanArray(ArrayRef< int > value)
Sets the entry&#39;s value.
Definition: NetworkTableEntry.inl:180
NetworkTables Remote Procedure Call.
Definition: RpcCall.h:21
uint64_t GetLastChange() const
Gets the last time the entry&#39;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&#39;s value as a string array.
Definition: NetworkTableEntry.inl:86
void ForceSetString(const Twine &value)
Sets the entry&#39;s value.
Definition: NetworkTableEntry.inl:172
std::string GetName() const
Gets the name of the entry (the key).
Definition: NetworkTableEntry.inl:24
NetworkTableInstance GetInstance() const
Gets the instance for the entry.
Definition: NetworkTableEntry.cpp:14
NetworkTables Remote Procedure Call (Server Side)
Definition: ntcore_cpp.h:124
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&#39;s value.
Definition: NetworkTableEntry.inl:160
void Delete()
Deletes the entry.
Definition: NetworkTableEntry.inl:209
bool SetDefaultStringArray(ArrayRef< std::string > defaultValue)
Sets the entry&#39;s value if it does not exist.
Definition: NetworkTableEntry.inl:123
bool SetDefaultDouble(double defaultValue)
Sets the entry&#39;s value if it does not exist.
Definition: NetworkTableEntry.inl:101
NetworkTables Entry Notification.
Definition: ntcore_cpp.h:169
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
RpcCall CallRpc(StringRef params)
Call a RPC function.
Definition: NetworkTableEntry.inl:216
std::string GetRaw(StringRef defaultValue) const
Gets the entry&#39;s value as a raw.
Definition: NetworkTableEntry.inl:66
void ForceSetRaw(StringRef value)
Sets the entry&#39;s value.
Definition: NetworkTableEntry.inl:176
void ForceSetBoolean(bool value)
Sets the entry&#39;s value.
Definition: NetworkTableEntry.inl:164
void ClearPersistent()
Stop making value persistent through program restarts.
Definition: NetworkTableEntry.inl:203
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:32
NetworkTables Instance.
Definition: NetworkTableInstance.h:62
void ForceSetStringArray(ArrayRef< std::string > value)
Sets the entry&#39;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&#39;s value.
Definition: NetworkTableEntry.inl:140
bool SetBoolean(bool value)
Sets the entry&#39;s value.
Definition: NetworkTableEntry.inl:132
bool SetRaw(StringRef value)
Sets the entry&#39;s value.
Definition: NetworkTableEntry.inl:144
std::string GetString(StringRef defaultValue) const
Gets the entry&#39;s value as a string.
Definition: NetworkTableEntry.inl:60
bool operator!=(const NetworkTableEntry &oth) const
Inequality operator.
Definition: NetworkTableEntry.h:441
bool SetDefaultBooleanArray(ArrayRef< int > defaultValue)
Sets the entry&#39;s value if it does not exist.
Definition: NetworkTableEntry.inl:113
Definition: IEntryNotifier.h:16
NetworkTables Entry Information.
Definition: ntcore_cpp.h:34
std::vector< int > GetBooleanArray(ArrayRef< int > defaultValue) const
Gets the entry&#39;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&#39;s value.
Definition: NetworkTableEntry.inl:128
void CreatePolledRpc()
Create a polled RPC entry point.
std::shared_ptr< Value > GetValue() const
Gets the entry&#39;s value.
Definition: NetworkTableEntry.inl:44
void ForceSetDouble(double value)
Sets the entry&#39;s value.
Definition: NetworkTableEntry.inl:168
double GetDouble(double defaultValue) const
Gets the entry&#39;s value as a double.
Definition: NetworkTableEntry.inl:54
bool SetStringArray(ArrayRef< std::string > value)
Sets the entry&#39;s value.
Definition: NetworkTableEntry.inl:156
Flags
Flag values (as returned by getFlags()).
Definition: NetworkTableEntry.h:40
bool SetDefaultString(const Twine &defaultValue)
Sets the entry&#39;s value if it does not exist.
Definition: NetworkTableEntry.inl:105
bool SetDefaultDoubleArray(ArrayRef< double > defaultValue)
Sets the entry&#39;s value if it does not exist.
Definition: NetworkTableEntry.inl:118
bool SetDefaultValue(std::shared_ptr< Value > value)
Sets the entry&#39;s value if it does not exist.
Definition: NetworkTableEntry.inl:93
bool SetDefaultBoolean(bool defaultValue)
Sets the entry&#39;s value if it does not exist.
Definition: NetworkTableEntry.inl:97
bool GetBoolean(bool defaultValue) const
Gets the entry&#39;s value as a boolean.
Definition: NetworkTableEntry.inl:48
NT_Entry GetHandle() const
Gets the native handle for the entry.
Definition: NetworkTableEntry.inl:18
bool SetDouble(double value)
Sets the entry&#39;s value.
Definition: NetworkTableEntry.inl:136
bool SetDefaultRaw(StringRef defaultValue)
Sets the entry&#39;s value if it does not exist.
Definition: NetworkTableEntry.inl:109
NetworkTables Entry.
Definition: NetworkTableEntry.h:35
bool IsPersistent() const
Returns whether the value is persistent through program restarts.
Definition: NetworkTableEntry.inl:205
bool SetBooleanArray(ArrayRef< int > value)
Sets the entry&#39;s value.
Definition: NetworkTableEntry.inl:148
std::vector< double > GetDoubleArray(ArrayRef< double > defaultValue) const
Gets the entry&#39;s value as a double array.
Definition: NetworkTableEntry.inl:79
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:42
void SetFlags(unsigned int flags)
Sets flags.
Definition: NetworkTableEntry.inl:193
bool SetDoubleArray(ArrayRef< double > value)
Sets the entry&#39;s value.
Definition: NetworkTableEntry.inl:152