Rudiments
tableinlines.h
1// Copyright (c) 1999-2018 David Muse
2// See the COPYING file for more information
3
4#include <rudiments/stdio.h>
5#include <rudiments/private/nodeinlines.h>
6
7template <class valuetype>
8inline
11 cols(0),
12 rows(0) {
13}
14
15template <class valuetype>
16inline
21
22template <class valuetype>
23inline
28
29template <class valuetype>
30inline
32 if (this!=&a) {
33 clear();
35 clone(&a);
36 }
37 return *this;
38}
39
40template <class valuetype>
41inline
43 if (this!=&a) {
44 clear();
46 clone(&a);
47 }
48 return *this;
49}
50
51template <class valuetype>
52inline
54 cols=0;
55 rows=0;
56 setCopyColumnNames(t->getCopyColumnNames());
57 setManageValues(t->getManageValues());
58 setManageArrayValues(t->getManageArrayValues());
59 for (uint64_t col=0; col<t->getColumnCount(); col++) {
60 setColumnName(col,t->getColumnName(col));
61 }
62 bool managevalues=this->getManageValues();
63 bool managearrayvalues=this->getManageArrayValues();
64 for (uint64_t row=0;
65 !(t->getAllRowsAvailable() && row==t->getRowCount());
66 row++) {
67 for (uint64_t col=0; col<t->getColumnCount(); col++) {
69 node_duplicate_value(
70 &(t->getReference(row,col)),
71 managevalues,managearrayvalues));
72 }
73 }
74}
75
76template <class valuetype>
77inline
80
81template <class valuetype>
82inline
83void table<valuetype>::setColumnName(uint64_t col, const char *name) {
84 if (this->copycolumnnames) {
85 if (cols && col<cols-1) {
86 delete[] columnnames[col];
87 }
88 columnnames[col]=charstring::duplicate(name);
89 } else {
90 columnnames[col]=(char *)name;
91 }
92 if (col>=cols) {
93 cols=col+1;
94 }
95}
96
97template <class valuetype>
98inline
99const char *table<valuetype>::getColumnName(uint64_t col) {
100 return (col<cols)?columnnames[col]:NULL;
101}
102
103template <class valuetype>
104inline
107 columnnames.setManageArrayValues(copy);
108}
109
110template <class valuetype>
111inline
113 return columnnames.getManageArrayValues();
114}
115
116template <class valuetype>
117inline
119 return cols;
120}
121
122template <class valuetype>
123inline
125 values.setManageValues(manage);
126}
127
128template <class valuetype>
129inline
131 return values.getManageValues();
132}
133
134template <class valuetype>
135inline
137 values.setManageArrayValues(manage);
138}
139
140template <class valuetype>
141inline
143 return values.getManageArrayValues();
144}
145
146template <class valuetype>
147inline
148void table<valuetype>::setValue(uint64_t row, uint64_t col, valuetype value) {
149 values[row][col]=value;
150 if (row>=rows) {
151 rows=row+1;
152 }
153 if (col>=cols) {
154 cols=col+1;
155 }
156}
157
158template <class valuetype>
159inline
161 return (row<rows && col<cols)?values[row][col]:((valuetype)0);
162}
163
164template <class valuetype>
165inline
167 return values[row][col];
168}
169
170template <class valuetype>
171inline
173 // FIXME: inefficient
174 for (uint64_t i=0; i<cols; i++) {
175 if (!charstring::compare(colname,columnnames[i])) {
176 return getValue(row,i);
177 }
178 }
179 return (valuetype)0;
180}
181
182template <class valuetype>
183inline
185 return rows;
186}
187
188template <class valuetype>
189inline
191 return true;
192}
193
194template <class valuetype>
195inline
197 for (uint64_t i=0; i<rows; i++) {
198 values[i].clear();
199 }
200 values.clear();
201 cols=0;
202 rows=0;
203 return true;
204}
Definition avltree.h:11
avltreenode(valuetype value)
Definition avltreeinlines.h:555
valuetype & getReference()
Definition avltreeinlines.h:584
valuetype getValue()
Definition avltreeinlines.h:578
void setValue(valuetype value)
Definition avltreeinlines.h:572
static char * duplicate(const char *str)
static int32_t compare(const char *str1, const char *str2)
Definition table.h:15
Definition tablecollection.h:35
tablecollection & operator=(tablecollection &c)
Definition tablecollectioninlines.h:21
virtual void setCopyColumnNames(bool copy)
Definition tablecollectioninlines.h:48