WPILibC++  unspecified
NetworkTableEntry.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2017. 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 NT_ENTRY_H_
9 #define NT_ENTRY_H_
10 
11 #include <memory>
12 #include <string>
13 
14 #include "llvm/StringRef.h"
15 
16 #include "networktables/NetworkTableType.h"
17 #include "networktables/NetworkTableValue.h"
18 #include "networktables/RpcCall.h"
19 #include "ntcore_c.h"
20 #include "ntcore_cpp.h"
21 
22 namespace nt {
23 
24 using llvm::ArrayRef;
25 using llvm::StringRef;
26 
27 class NetworkTableInstance;
28 
30 class NetworkTableEntry final {
31  public:
35  enum Flags { kPersistent = NT_PERSISTENT };
36 
41 
46  explicit NetworkTableEntry(NT_Entry handle);
47 
52  explicit operator bool() const { return m_handle != 0; }
53 
58  NT_Entry GetHandle() const;
59 
65 
70  bool Exists() const;
71 
76  std::string GetName() const;
77 
82  NetworkTableType GetType() const;
83 
88  unsigned int GetFlags() const;
89 
94  unsigned long long GetLastChange() const;
95 
100  EntryInfo GetInfo() const;
101 
107  std::shared_ptr<Value> GetValue() const;
108 
116  bool GetBoolean(bool defaultValue) const;
117 
125  double GetDouble(double defaultValue) const;
126 
134  std::string GetString(StringRef defaultValue) const;
135 
143  std::string GetRaw(StringRef defaultValue) const;
144 
158  std::vector<int> GetBooleanArray(ArrayRef<int> defaultValue) const;
159 
169  std::vector<double> GetDoubleArray(ArrayRef<double> defaultValue) const;
170 
180  std::vector<std::string> GetStringArray(
181  ArrayRef<std::string> defaultValue) const;
182 
188  bool SetDefaultValue(std::shared_ptr<Value> value);
189 
195  bool SetDefaultBoolean(bool defaultValue);
196 
202  bool SetDefaultDouble(double defaultValue);
203 
209  bool SetDefaultString(StringRef defaultValue);
210 
216  bool SetDefaultRaw(StringRef defaultValue);
217 
223  bool SetDefaultBooleanArray(ArrayRef<int> defaultValue);
224 
230  bool SetDefaultDoubleArray(ArrayRef<double> defaultValue);
231 
237  bool SetDefaultStringArray(ArrayRef<std::string> defaultValue);
238 
244  bool SetValue(std::shared_ptr<Value> value);
245 
251  bool SetBoolean(bool value);
252 
258  bool SetDouble(double value);
259 
265  bool SetString(StringRef value);
266 
272  bool SetRaw(StringRef value);
273 
279  bool SetBooleanArray(ArrayRef<int> value);
280 
286  bool SetDoubleArray(ArrayRef<double> value);
287 
294 
300  void ForceSetValue(std::shared_ptr<Value> value);
301 
307  void ForceSetBoolean(bool value);
308 
314  void ForceSetDouble(double value);
315 
321  void ForceSetString(StringRef value);
322 
328  void ForceSetRaw(StringRef value);
329 
336 
343 
350 
355  void SetFlags(unsigned int flags);
356 
361  void ClearFlags(unsigned int flags);
362 
366  void SetPersistent();
367 
371  void ClearPersistent();
372 
377  bool IsPersistent() const;
378 
382  void Delete();
383 
390  void CreateRpc(std::function<void(const RpcAnswer& answer)> callback);
391 
398  void CreatePolledRpc();
399 
408  RpcCall CallRpc(StringRef params);
409 
417  NT_EntryListener AddListener(
418  std::function<void(const EntryNotification& event)> callback,
419  unsigned int flags) const;
420 
425  void RemoveListener(NT_EntryListener entry_listener);
426 
431  bool operator==(const NetworkTableEntry& oth) const {
432  return m_handle == oth.m_handle;
433  }
434 
436  bool operator!=(const NetworkTableEntry& oth) const {
437  return !(*this == oth);
438  }
439 
440  protected:
441  /* Native handle */
442  NT_Entry m_handle;
443 };
444 
445 } // namespace nt
446 
447 #include "networktables/NetworkTableEntry.inl"
448 
449 #endif // NT_ENTRY_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:431
void ForceSetBooleanArray(ArrayRef< int > value)
Sets the entry&#39;s value.
Definition: NetworkTableEntry.inl:180
NetworkTables Remote Procedure Call.
Definition: RpcCall.h:21
unsigned long long 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
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:120
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:165
void ForceSetString(StringRef value)
Sets the entry&#39;s value.
Definition: NetworkTableEntry.inl:172
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:59
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 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:436
bool SetDefaultBooleanArray(ArrayRef< int > defaultValue)
Sets the entry&#39;s value if it does not exist.
Definition: NetworkTableEntry.inl:113
Definition: IEntryNotifier.h:15
NetworkTables Entry Information.
Definition: ntcore_cpp.h:30
std::vector< int > GetBooleanArray(ArrayRef< int > defaultValue) const
Gets the entry&#39;s value as a boolean array.
Definition: NetworkTableEntry.inl:72
bool SetDefaultString(StringRef defaultValue)
Sets the entry&#39;s value if it does not exist.
Definition: NetworkTableEntry.inl:105
bool SetString(StringRef value)
Sets the entry&#39;s value.
Definition: NetworkTableEntry.inl:140
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:35
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:30
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