WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
ITable.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2015. 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 ITABLE_H_
9 #define ITABLE_H_
10 
11 #include <memory>
12 
13 #include "llvm/StringRef.h"
14 #include "nt_Value.h"
15 
16 // [[deprecated(msg)]] is a C++14 feature not supported by MSVC or GCC < 4.9.
17 // We provide an equivalent warning implementation for those compilers here.
18 #ifndef NT_DEPRECATED
19  #if defined(_MSC_VER)
20  #define NT_DEPRECATED(msg) __declspec(deprecated(msg))
21  #elif defined(__GNUC__)
22  #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 8)
23  #if __cplusplus > 201103L
24  #define NT_DEPRECATED(msg) [[deprecated(msg)]]
25  #else
26  #define NT_DEPRECATED(msg) [[gnu::deprecated(msg)]]
27  #endif
28  #else
29  #define NT_DEPRECATED(msg) __attribute__((deprecated(msg)))
30  #endif
31  #elif __cplusplus > 201103L
32  #define NT_DEPRECATED(msg) [[deprecated(msg)]]
33  #else
34  #define NT_DEPRECATED(msg) /*nothing*/
35  #endif
36 #endif
37 
38 class ITableListener;
39 
43 class ITable {
44  public:
51  virtual bool ContainsKey(llvm::StringRef key) const = 0;
52 
61  virtual bool ContainsSubTable(llvm::StringRef key) const = 0;
62 
69  virtual std::shared_ptr<ITable> GetSubTable(llvm::StringRef key) const = 0;
70 
75  virtual std::vector<std::string> GetKeys(int types = 0) const = 0;
76 
80  virtual std::vector<std::string> GetSubTables() const = 0;
81 
87  virtual void SetPersistent(llvm::StringRef key) = 0;
88 
95  virtual void ClearPersistent(llvm::StringRef key) = 0;
96 
103  virtual bool IsPersistent(llvm::StringRef key) const = 0;
104 
112  virtual void SetFlags(llvm::StringRef key, unsigned int flags) = 0;
113 
121  virtual void ClearFlags(llvm::StringRef key, unsigned int flags) = 0;
122 
129  virtual unsigned int GetFlags(llvm::StringRef key) const = 0;
130 
136  virtual void Delete(llvm::StringRef key) = 0;
137 
145  virtual std::shared_ptr<nt::Value> GetValue(llvm::StringRef key) const = 0;
146 
154  virtual bool PutValue(llvm::StringRef key,
155  std::shared_ptr<nt::Value> value) = 0;
156 
164  virtual bool PutNumber(llvm::StringRef key, double value) = 0;
165 
176  NT_DEPRECATED("Raises an exception if key not found; "
177  "use GetNumber(StringRef key, double defaultValue) instead")
178  virtual double GetNumber(llvm::StringRef key) const = 0;
179 
188  virtual double GetNumber(llvm::StringRef key, double defaultValue) const = 0;
189 
197  virtual bool PutString(llvm::StringRef key, llvm::StringRef value) = 0;
198 
209  NT_DEPRECATED("Raises an exception if key not found; "
210  "use GetString(StringRef key, StringRef defaultValue) instead")
211  virtual std::string GetString(llvm::StringRef key) const = 0;
212 
225  virtual std::string GetString(llvm::StringRef key,
226  llvm::StringRef defaultValue) const = 0;
227 
235  virtual bool PutBoolean(llvm::StringRef key, bool value) = 0;
236 
247  NT_DEPRECATED("Raises an exception if key not found; "
248  "use GetBoolean(StringRef key, bool defaultValue) instead")
249  virtual bool GetBoolean(llvm::StringRef key) const = 0;
250 
260  virtual bool GetBoolean(llvm::StringRef key, bool defaultValue) const = 0;
261 
272  virtual bool PutBooleanArray(llvm::StringRef key,
273  llvm::ArrayRef<int> value) = 0;
274 
290  virtual std::vector<int> GetBooleanArray(
291  llvm::StringRef key, llvm::ArrayRef<int> defaultValue) const = 0;
292 
299  virtual bool PutNumberArray(llvm::StringRef key,
300  llvm::ArrayRef<double> value) = 0;
301 
313  virtual std::vector<double> GetNumberArray(
314  llvm::StringRef key, llvm::ArrayRef<double> defaultValue) const = 0;
315 
322  virtual bool PutStringArray(llvm::StringRef key,
323  llvm::ArrayRef<std::string> value) = 0;
324 
336  virtual std::vector<std::string> GetStringArray(
337  llvm::StringRef key, llvm::ArrayRef<std::string> defaultValue) const = 0;
338 
345  virtual bool PutRaw(llvm::StringRef key, llvm::StringRef value) = 0;
346 
358  virtual std::string GetRaw(llvm::StringRef key,
359  llvm::StringRef defaultValue) const = 0;
360 
366  virtual void AddTableListener(ITableListener* listener) = 0;
367 
375  virtual void AddTableListener(ITableListener* listener,
376  bool immediateNotify) = 0;
377 
386  virtual void AddTableListenerEx(ITableListener* listener,
387  unsigned int flags) = 0;
388 
397  virtual void AddTableListener(llvm::StringRef key, ITableListener* listener,
398  bool immediateNotify) = 0;
399 
409  virtual void AddTableListenerEx(llvm::StringRef key, ITableListener* listener,
410  unsigned int flags) = 0;
411 
416  virtual void AddSubTableListener(ITableListener* listener) = 0;
417 
424  virtual void AddSubTableListener(ITableListener* listener,
425  bool localNotify) = 0;
426 
432  virtual void RemoveTableListener(ITableListener* listener) = 0;
433 };
434 
435 #endif // ITABLE_H_
virtual bool PutNumber(llvm::StringRef key, double value)=0
Put a number in the table.
virtual bool PutNumberArray(llvm::StringRef key, llvm::ArrayRef< double > value)=0
Put a number array in the table.
A table whose values can be read and written to.
Definition: ITable.h:43
virtual void ClearPersistent(llvm::StringRef key)=0
Stop making a key's value persistent through program restarts.
virtual void AddTableListener(ITableListener *listener)=0
Add a listener for changes to the table.
virtual std::string GetRaw(llvm::StringRef key, llvm::StringRef defaultValue) const =0
Returns the raw value (byte array) the key maps to.
virtual bool PutBooleanArray(llvm::StringRef key, llvm::ArrayRef< int > value)=0
Put a boolean array in the table.
virtual std::shared_ptr< ITable > GetSubTable(llvm::StringRef key) const =0
Gets the subtable in this table for the given name.
virtual void Delete(llvm::StringRef key)=0
Deletes the specified key in this table.
virtual void AddSubTableListener(ITableListener *listener)=0
This will immediately notify the listener of all current sub tables.
virtual unsigned int GetFlags(llvm::StringRef key) const =0
Returns the flags for the specified key.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:54
virtual bool ContainsKey(llvm::StringRef key) const =0
Determines whether the given key is in this table.
virtual bool PutStringArray(llvm::StringRef key, llvm::ArrayRef< std::string > value)=0
Put a string array in the table.
virtual std::vector< std::string > GetSubTables() const =0
virtual bool IsPersistent(llvm::StringRef key) const =0
Returns whether the value is persistent through program restarts.
virtual bool PutString(llvm::StringRef key, llvm::StringRef value)=0
Put a string in the table.
virtual std::vector< std::string > GetKeys(int types=0) const =0
virtual bool PutBoolean(llvm::StringRef key, bool value)=0
Put a boolean in the table.
virtual void RemoveTableListener(ITableListener *listener)=0
Remove a listener from receiving table events.
virtual std::shared_ptr< nt::Value > GetValue(llvm::StringRef key) const =0
Gets the value associated with a key as an object.
A listener that listens to changes in values in a ITable.
Definition: ITableListener.h:18
virtual void SetFlags(llvm::StringRef key, unsigned int flags)=0
Sets flags on the specified key in this table.
virtual std::vector< std::string > GetStringArray(llvm::StringRef key, llvm::ArrayRef< std::string > defaultValue) const =0
Returns the string array the key maps to.
virtual std::vector< double > GetNumberArray(llvm::StringRef key, llvm::ArrayRef< double > defaultValue) const =0
Returns the number array the key maps to.
virtual void ClearFlags(llvm::StringRef key, unsigned int flags)=0
Clears flags on the specified key in this table.
virtual bool ContainsSubTable(llvm::StringRef key) const =0
Determines whether there exists a non-empty subtable for this key in this table.
virtual bool PutValue(llvm::StringRef key, std::shared_ptr< nt::Value > value)=0
Put a value in the table.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:39
virtual std::vector< int > GetBooleanArray(llvm::StringRef key, llvm::ArrayRef< int > defaultValue) const =0
Returns the boolean array the key maps to.
virtual void AddTableListenerEx(ITableListener *listener, unsigned int flags)=0
Add a listener for changes to the table.
virtual bool PutRaw(llvm::StringRef key, llvm::StringRef value)=0
Put a raw value (byte array) in the table.
virtual void SetPersistent(llvm::StringRef key)=0
Makes a key's value persistent through program restarts.