NDEVR
API Documentation
Table.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Database
28File: Table
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/TableColumn.h>
35#include <NDEVR/Dictionary.h>
36#include <NDEVR/Pointer.h>
37namespace NDEVR
38{
39 template<class t_type>
40 class Set;
41
47
59 class NDEVR_DATABASE_API Table
60 {
61 public:
65 Table();
66
71 explicit Table(const StringView& name);
72
76 ~Table();
77
82 bool validate() const;
83
88 uint04 size() const;
89
95 void fixIndexLinking(TableColumn* channel);
96
103 template<class t_column_type>
104 std::pair<uint04, TableColumn*> createColumn(const StringView& name)
105 {
106 auto iter = m_name_channels.find(name);
107 if (iter != m_name_channels.end())
108 return iter.value();
109 t_column_type* channel = new t_column_type(name);
110 m_generated_channels.add(channel);
111 return { addChannel(channel), channel };
112 }
113
121 template<class t_column_type, class t_default_type>
122 std::pair<uint04, TableColumn*> createColumn(const StringView& name, const t_default_type& default_value)
123 {
124 auto iter = m_name_channels.find(name);
125 if (iter != m_name_channels.end())
126 return iter.value();
127 t_column_type* channel = new t_column_type(name);
128 channel->setDefault(default_value);
129 m_generated_channels.add(channel);
130 return { addChannel(channel), channel };
131 }
132
140 std::pair<uint04, TableColumn*> createColumn(const StringView& name, const TypeInfo& type_info);
141 public:
147 void addIndexChannel(TableColumn* channel);
148
153 void link(const Dictionary<UUID, Table*>& tables);
154
160 uint04 addChannel(TableColumn* channel);
161
166 uint04 rowSize() const;
167
172 uint04 columnSize() const;
173
177 void clear();
178
183 void setSize(uint04 size);
184
188 void addRow();
189
194 void resetRow(uint04 row);
195
201 void copyRow(uint04 source, uint04 destination);
202
209 void copyRows(uint04 source, uint04 destination, uint04 size);
210
215 void appendRows(uint04 size);
216
221 void insertRow(uint04 index);
222
228 void swapRows(uint04 a, uint04 b);
229
235 void swapColumns(uint04 a, uint04 b);
236
242 void swapColumns(TableColumn* a, TableColumn* b);
243
249 void insertRows(uint04 index, uint04 size);
250
255 void removeColumn(uint04 channel);
256
261 void removeColumn(TableColumn* channel);
262
267 void removeColumn(const StringView& channel);
268
273 void removeRow(uint04 index);
274
280 void removeRows(uint04 index, uint04 size);
281
286 void removeRows(const Buffer<uint04>& sorted_remove_indices);
287
293 void removeRows(uint04 offset, const Buffer<bool>& remove_mask);
294
300 bool hasColumn(const StringView& column_name) const;
301
307 void renameColumn(uint04 column_index, const StringView& new_name);
308
314 void renameColumn(TableColumn* column, const StringView& new_name);
315
321 bool hasColumn(uint04 index) const;
322
328 uint04 indexOf(const StringView& column_name) const;
329
335 uint04 indexOf(TableColumn* column) const;
336
342 inline TableColumn& get(uint04 channel_index)
343 {
344 lib_assert(channel_index < m_data_channels.size() && m_data_channels[channel_index] != nullptr, "Tried to access non-existent table");
345 return *m_data_channels[channel_index];
346 }
347
353 inline const TableColumn& get(uint04 channel_index) const
354 {
355 lib_assert(channel_index < m_data_channels.size() && m_data_channels[channel_index] != nullptr, "Tried to access non-existent table");
356 return *m_data_channels[channel_index];
357 }
358
364 inline TableColumn& get(const StringView& channel)
365 {
366 return *m_name_channels.get(channel).second;
367 }
368
374 inline const TableColumn& get(const StringView& channel) const
375 {
376 return *m_name_channels.get(channel).second;
377 }
378
384 inline const TableColumn& operator[](uint04 channel_index) const
385 {
386 return get(channel_index);
387 }
388
394 inline TableColumn& operator[](uint04 channel_index)
395 {
396 return get(channel_index);
397 }
398
404 template<class t_enum_type>
405 inline const TableColumn& operator[](t_enum_type channel_index) const
406 {
407 return get(eint04<t_enum_type>(channel_index));
408 }
409
416 template<class t_enum_type>
417 inline typename std::enable_if<ObjectInfo<t_enum_type>::Enum, TableColumn&>::type operator[](t_enum_type channel_index)
418 {
419 return get(eint04<t_enum_type>(channel_index));
420 }
421
432 template<class t_enum_type>
433 inline typename std::enable_if<ObjectInfo<t_enum_type>::Enum, const TableColumn&>::type operator[](const StringView& channel) const
434 {
435 return get(channel);
436 }
437
443 inline TableColumn& operator[](const StringView& channel)
444 {
445 return get(channel);
446 }
447
453 bool hasMatchingColumns(const Table& table) const;
454
459 auto begin()
460 {
461 return m_name_channels.begin();
462 }
463
468 auto end()
469 {
470 return m_name_channels.end();
471 }
472
478 bool operator==(const Table& table) const
479 {
480 return table.m_uuid == m_uuid;
481 }
482
487 UUID uuid() const
488 {
489 return m_uuid;
490 }
491
497 void fetchDataColumns(Buffer<TableColumn*>& columns, const Set<StringAllocatingView>& exclusion_list);
498
503 const String& name() const;
504
509 void mapToFile(BinaryFileTableInfo& file) const;
510
515 static void SkipTable(BinaryFileTableInfo& file);
516
521 void mapFromFile(BinaryFileTableInfo& file);
522
528 void finishMapFromFile(BinaryFileTableInfo& file);
529
534 Buffer<StringView> getColumnNames() const;
535
539 void updateAll();
540
545 void update(const TableChange& change);
546
551 uint08 approximateMemorySize() const;
552
560 void setAll(uint04 to_row, uint04 from_row, uint04 size, const Table& from_table);
561 private:
568 template<uint01 t_dims>
569 std::pair<uint04, TableColumn*> createScalarChannel(const StringView& name, const TypeInfo& type_info);
570
578 void writeColumnHeaders(BinaryFileTableInfo& file, const Buffer<uint08>& locations, uint08 start, uint08 end) const;
579
587 std::pair<uint04, TableColumn*> createBufferChannel(const StringView& name, const TypeInfo& type_info, bool is_floating = false);
588 protected:
589 UUID m_uuid;
590 Dictionary<StringView, std::pair<uint04, TableColumn*>> m_name_channels;
591 Buffer<TableColumn*> m_data_channels;
592 Buffer<TableColumn*> m_generated_channels;
593 Buffer<TableColumn*> m_index_channels;
594 uint04 m_size;
595 String m_name;
596 };
597}
Container that stores unique elements in no particular order, and which allow for fast retrieval or i...
Definition Set.h:59
The primary namespace for the NDEVR SDK.
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
@ name
The display name of the object.
Extended file table information for reading and writing NDV binary files.