jerrym | f157933 | 2013-02-07 01:56:28 +0000 | [diff] [blame] | 1 | /*
|
| 2 | * ITable.h
|
| 3 | *
|
| 4 | * Created on: Sep 19, 2012
|
| 5 | * Author: Mitchell Wills
|
| 6 | */
|
| 7 |
|
| 8 | #ifndef ITABLE_H_
|
| 9 | #define ITABLE_H_
|
| 10 |
|
| 11 |
|
| 12 | class ITable;
|
| 13 | union EntryValue{
|
| 14 | void* ptr;
|
| 15 | bool b;
|
| 16 | double f;
|
| 17 | };
|
| 18 | typedef union EntryValue EntryValue;
|
| 19 |
|
| 20 |
|
| 21 | #include <string>
|
| 22 | #include "networktables2/type/ComplexData.h"
|
| 23 | #include "ITableListener.h"
|
| 24 |
|
| 25 |
|
| 26 | class ITable {
|
| 27 | public:
|
| 28 |
|
| 29 | /**
|
| 30 | * Determines whether the given key is in this table.
|
| 31 | *
|
| 32 | * @param key the key to search for
|
| 33 | * @return true if the table as a value assigned to the given key
|
| 34 | */
|
| 35 | virtual bool ContainsKey(std::string key) = 0;
|
| 36 |
|
| 37 | /**
|
| 38 | * Determines whether there exists a non-empty subtable for this key
|
| 39 | * in this table.
|
| 40 | *
|
| 41 | * @param key the key to search for
|
| 42 | * @return true if there is a subtable with the key which contains at least one key/subtable of its own
|
| 43 | */
|
| 44 | virtual bool ContainsSubTable(std::string key) = 0;
|
| 45 |
|
| 46 | /**
|
| 47 | * Gets the subtable in this table for the given name.
|
| 48 | *
|
| 49 | * @param key the name of the table relative to this one
|
| 50 | * @return a sub table relative to this one
|
| 51 | */
|
| 52 | virtual ITable* GetSubTable(std::string key) = 0;
|
| 53 |
|
| 54 |
|
| 55 | /**
|
| 56 | * Gets the value associated with a key as an object
|
| 57 | *
|
| 58 | * @param key the key of the value to look up
|
| 59 | * @return the value associated with the given key
|
| 60 | * @throws TableKeyNotDefinedException if there is no value associated with the given key
|
| 61 | */
|
| 62 | virtual EntryValue GetValue(std::string key) = 0;
|
| 63 | /**
|
| 64 | * Put a value in the table
|
| 65 | *
|
| 66 | * @param key the key to be assigned to
|
| 67 | * @param value the value that will be assigned
|
| 68 | * @throws IllegalArgumentException when the value is not supported by the table
|
| 69 | */
|
| 70 | virtual void PutValue(std::string key, ComplexData& value) = 0;
|
| 71 |
|
| 72 | virtual void RetrieveValue(std::string key, ComplexData& externalValue) = 0;
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 | /**
|
| 77 | * Put a number in the table
|
| 78 | *
|
| 79 | * @param key the key to be assigned to
|
| 80 | * @param value the value that will be assigned
|
| 81 | */
|
| 82 | virtual void PutNumber(std::string key, double value) = 0;
|
| 83 | /**
|
| 84 | * Gets the number associated with the given name.
|
| 85 | *
|
| 86 | * @param key the key to look up
|
| 87 | * @return the value associated with the given key
|
| 88 | * @throws TableKeyNotDefinedException if there is no value associated with the given key
|
| 89 | */
|
| 90 | virtual double GetNumber(std::string key) = 0;
|
| 91 | /**
|
| 92 | * Gets the number associated with the given name.
|
| 93 | *
|
| 94 | * @param key the key to look up
|
| 95 | * @param defaultValue the value to be returned if no value is found
|
| 96 | * @return the value associated with the given key or the given default value if there is no value associated with the key
|
| 97 | */
|
| 98 | virtual double GetNumber(std::string key, double defaultValue) = 0;
|
| 99 |
|
| 100 | /**
|
| 101 | * Put a std::string& in the table
|
| 102 | *
|
| 103 | * @param key the key to be assigned to
|
| 104 | * @param value the value that will be assigned
|
| 105 | */
|
| 106 | virtual void PutString(std::string key, std::string value) = 0;
|
| 107 |
|
| 108 | /**
|
| 109 | * Gets the string associated with the given name.
|
| 110 | *
|
| 111 | * @param key the key to look up
|
| 112 | * @return the value associated with the given key
|
| 113 | * @throws TableKeyNotDefinedException if there is no value associated with the given key
|
| 114 | */
|
| 115 | virtual std::string GetString(std::string key) = 0;
|
| 116 |
|
| 117 | /**
|
| 118 | * Gets the string associated with the given name.
|
| 119 | *
|
| 120 | * @param key the key to look up
|
| 121 | * @param defaultValue the value to be returned if no value is found
|
| 122 | * @return the value associated with the given key or the given default value if there is no value associated with the key
|
| 123 | */
|
| 124 | virtual std::string GetString(std::string key, std::string defaultValue) = 0;
|
| 125 |
|
| 126 | /**
|
| 127 | * Put a boolean in the table
|
| 128 | *
|
| 129 | * @param key the key to be assigned to
|
| 130 | * @param value the value that will be assigned
|
| 131 | */
|
| 132 | virtual void PutBoolean(std::string key, bool value) = 0;
|
| 133 |
|
| 134 | /**
|
| 135 | * Gets the boolean associated with the given name.
|
| 136 | *
|
| 137 | * @param key the key to look up
|
| 138 | * @return the value associated with the given key
|
| 139 | * @throws TableKeyNotDefinedException if there is no value associated with the given key
|
| 140 | */
|
| 141 | virtual bool GetBoolean(std::string key) = 0;
|
| 142 |
|
| 143 | /**
|
| 144 | * Gets the boolean associated with the given name.
|
| 145 | *
|
| 146 | * @param key the key to look up
|
| 147 | * @param defaultValue the value to be returned if no value is found
|
| 148 | * @return the value associated with the given key or the given default value if there is no value associated with the key
|
| 149 | */
|
| 150 | virtual bool GetBoolean(std::string key, bool defaultValue) = 0;
|
| 151 |
|
| 152 | /**
|
| 153 | * Add a listener for changes to the table
|
| 154 | *
|
| 155 | * @param listener the listener to add
|
| 156 | */
|
| 157 | virtual void AddTableListener(ITableListener* listener) = 0;
|
| 158 |
|
| 159 | /**
|
| 160 | * Add a listener for changes to the table
|
| 161 | *
|
| 162 | * @param listener the listener to add
|
| 163 | * @param immediateNotify if true then this listener will be notified of all current entries (marked as new)
|
| 164 | */
|
| 165 | virtual void AddTableListener(ITableListener* listener, bool immediateNotify) = 0;
|
| 166 |
|
| 167 | /**
|
| 168 | * Add a listener for changes to a specific key the table
|
| 169 | *
|
| 170 | * @param key the key to listen for
|
| 171 | * @param listener the listener to add
|
| 172 | * @param immediateNotify if true then this listener will be notified of all current entries (marked as new)
|
| 173 | */
|
| 174 | virtual void AddTableListener(std::string key, ITableListener* listener, bool immediateNotify) = 0;
|
| 175 |
|
| 176 | /**
|
| 177 | * This will immediately notify the listener of all current sub tables
|
| 178 | *
|
| 179 | * @param listener
|
| 180 | */
|
| 181 | virtual void AddSubTableListener(ITableListener* listener) = 0;
|
| 182 |
|
| 183 | /**
|
| 184 | * Remove a listener from receiving table events
|
| 185 | *
|
| 186 | * @param listener the listener to be removed
|
| 187 | */
|
| 188 | virtual void RemoveTableListener(ITableListener* listener) = 0;
|
| 189 |
|
| 190 |
|
| 191 | };
|
| 192 |
|
| 193 |
|
| 194 | #endif /* ITABLE_H_ */
|