HIPO  4.3.0
High Performance Output data format for experimental physics
bank.cpp
Go to the documentation of this file.
1 //******************************************************************************
2 //* ██╗ ██╗██╗██████╗ ██████╗ ██╗ ██╗ ██████╗ *
3 //* ██║ ██║██║██╔══██╗██╔═══██╗ ██║ ██║ ██╔═████╗ *
4 //* ███████║██║██████╔╝██║ ██║ ███████║ ██║██╔██║ *
5 //* ██╔══██║██║██╔═══╝ ██║ ██║ ╚════██║ ████╔╝██║ *
6 //* ██║ ██║██║██║ ╚██████╔╝ ██║██╗╚██████╔╝ *
7 //* ╚═╝ ╚═╝╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═════╝ *
8 //************************ Jefferson National Lab (2017) ***********************
9 /*
10  * Copyright (c) 2017. Jefferson Lab (JLab). All rights reserved. Permission
11  * to use, copy, modify, and distribute this software and its documentation
12  * for educational, research, and not-for-profit purposes, without fee and
13  * without a signed licensing agreement.
14  *
15  * IN NO EVENT SHALL JLAB BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL
16  * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
17  * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JLAB HAS
18  * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19  *
20  * JLAB SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE. THE HIPO DATA FORMAT SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF
23  * ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". JLAB HAS NO OBLIGATION TO
24  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25  *
26  * This software was developed under the United States Government license.
27  * For more information contact author at gavalian@jlab.org
28  * Department of Experimental Nuclear Physics, Jefferson Lab.
29  */
30 /*******************************************************************************
31  * File: bank.cc
32  * Author: gavalian
33  *
34  * Created on April 12, 2017, 10:14 AM
35  */
36 
41 #include "bank.h"
42 #include "parser.h"
43 
44 #include <algorithm>
45 #include <numeric>
46 
47 namespace hipo {
48 
49  //==============================================================
50  // Definition of class structure, this will class will be extended
51  // to represent different objects that will be appended to the event
52  //==============================================================
53 
54  structure::structure(int __group, int __item, std::string &str){
55  int length = str.length();
56  initStructureBySize(__group,__item, 6, length);
57  putStringAt(0,str);
58  }
59 
60  bool structure::allocate(int size){
61  if(structureBuffer.size()<size){
62  structureBuffer.resize(size+32);
63  }
64  return true;
65  }
66 
67  void structure::initStructureBySize(int __group, int __item, int __type, int __size){
68  allocate(__size+8);
69  structureAddress = &structureBuffer[0];
70  *reinterpret_cast<uint16_t *>(structureAddress) = (uint16_t) __group;
71  *reinterpret_cast<uint8_t *>(&structureAddress[2]) = (uint8_t) __item;
72  *reinterpret_cast<uint8_t *>(&structureAddress[3]) = (uint8_t) __type;
73  *reinterpret_cast<uint32_t *>(&structureAddress[4]) = __size;
74  }
75 
76  void structure::setSize(int size){
77  int sizeWord = *reinterpret_cast<uint32_t *>(structureAddress+4);
78  int header = sizeWord&STRUCT_FORMAT_MASK;
79  *reinterpret_cast<uint32_t *>(structureAddress+4) = header|(size&STRUCT_SIZE_MASK);
80  }
81 
82  void structure::setDataSize(int size){
83  int sizeWord = *reinterpret_cast<uint32_t *>(structureAddress+4);
84  int header = sizeWord&STRUCT_FORMAT_MASK;
85  int headerSize = (sizeWord>>STRUCT_FORMAT_SHIFT)&STRUCT_FORMAT_BYTE;
86  int totalSize = headerSize + size;
87  //printf(" header size = %d, size = %d, total size = %d\n", (sizeWord>>24)&0x000000ff,size, totalSize);
88  *reinterpret_cast<uint32_t *>(structureAddress+4) = header|(totalSize&STRUCT_SIZE_MASK);
89  }
90 
91  void structure::setHeaderSize(int size){
92  int sizeWord = *reinterpret_cast<uint32_t *>(structureAddress+4);
93  int dataSize = sizeWord&STRUCT_SIZE_MASK;
94  *reinterpret_cast<uint32_t *>(structureAddress+4) = ((size<<STRUCT_FORMAT_SHIFT)&STRUCT_FORMAT_MASK)|dataSize ;
95  }
96 
97  // return the type of the structure
98  int structure::getType() const {
99  auto type = (int) (*reinterpret_cast<uint8_t *>(structureAddress+3));
100  return type;
101  }
102  // returns the group number of the object
103  int structure::getGroup() const {
104  auto group = (int) (*reinterpret_cast<uint16_t *>(structureAddress));
105  return group;
106  }
107  // returns the item number of the structure
108  int structure::getItem() const {
109  auto item = (int) (*reinterpret_cast<uint8_t *>(structureAddress+2));
110  return item;
111  }
112  void structure::initNoCopy(const char *buffer, int size){
113  structureAddress = const_cast<char*>(buffer);
114  }
115 
116  void structure::init(const char *buffer, int size){
117  allocate(size);
118  memcpy(&structureBuffer[0],buffer,size);
119  structureAddress = &structureBuffer[0];
120  }
121 
122  void structure::show() const {
123  printf("structure : [%5d,%5d] type = %4d, header = %5d, length = %6d, data size = %5d, offset = %5d, capacity = %5lu\n",
124  getGroup(),getItem(),getType(),getHeaderSize(), getSize(), getDataSize(), dataOffset, structureBuffer.size());
125  }
126 
127  std::string structure::getStringAt(int index){
128  int length = getSize();
129  auto *string_ch = (char *) malloc(length+1);
130  std::memcpy(string_ch, &structureBuffer[8],length);
131  string_ch[length] = '\0';
132  std::string result = string_ch;
133  free(string_ch);
134  return result;
135  }
136 
137  void structure::putStringAt(int index, std::string &str){
138  int strLen = str.length();
139  std::memcpy(&structureBuffer[8],&str[0],strLen);
140  }
141 
142  const char *structure::getAddress(){
143  return structureAddress;
144  }
145 
146 //====================================================================
147 //-=- END of structure class - starting composite class -=-
148 //====================================================================
149 
151  //int length = getHeaderSize();
152  //setHeaderSize(length);
153  //setSize(length);
154  setDataLength(0);
155 }
156 
157 composite::composite(int group, int item, const char *format, int capacity){
158  parse(group,item,format,capacity);
159  //create(group,item,10,capacity);
160 }
161 
162 void composite::parse(std::string format){
163  parse(134,1,format,256);
164 }
165 
166 void composite::setRows(int rows) {
167  if(((formatLength()+8)+getRowSize()*(rows+1))<capacity()){
168  printf("composite::setRows:: error, the requested row %d exceeds the bank capacity of %d\n",
169  rows,capacity());
170  } else {
171  setDataLength(rows*rowOffset);
172  }
173 }
174 
175 void composite::parse(int group, int item, std::string format, int maxrows){
176  types.clear(); offsets.clear();
177  int length = format.length();
178  int offset = 0;
179  for(int i = 0; i < length; i++){
180  char c = format[i];
181  //printf("%5d : %c\n",i,c);
182 
183  switch(c){
184  case 'b': types.push_back(1); offsets.push_back(offset); offset += getTypeSize(1); break;
185  case 's': types.push_back(2); offsets.push_back(offset); offset += getTypeSize(2); break;
186  case 'i': types.push_back(3); offsets.push_back(offset); offset += getTypeSize(3); break;
187  case 'f': types.push_back(4); offsets.push_back(offset); offset += getTypeSize(4); break;
188  case 'd': types.push_back(5); offsets.push_back(offset); offset += getTypeSize(5); break;
189  case 'l': types.push_back(8); offsets.push_back(offset); offset += getTypeSize(8); break;
190  default: break;
191  }
192  }
193  rowOffset = offset;
194  create(group,item,10,rowOffset*maxrows + 8 + length);
195  setFormatLength(length);
196  memcpy(const_cast<char *>(&pointer()[8]),&format[0],length);
197  //initStructureBySize(group,item,10,rowOffset*maxrows + 8 + length);
198  //setHeaderSize(length);
199  //setSize(length);
200  //dataOffset = 8 + length;
201  //memcpy(&getStructureBuffer()[8],&format[0],length);
202 }
203 
204 int composite::getTypeSize(int type){
205  switch(type){
206  case 1: return 1;
207  case 2: return 2;
208  case 3: return 4;
209  case 4: return 4;
210  case 5: return 8;
211  case 8: return 8;
212  default: return 0;
213  }
214 }
215 
216 int composite::getInt ( int element, int row) const noexcept{
217  int type = types[element];
218  int rows = getRows();
219  if(row>=rows) {
220  printf(" error : requested row %d out of %d\n", row, rows);
221  return -1;
222  }
223  int offset = getRowSize()*row + offsets[element];
224  switch(type){
225  case 1: return getByteAt(offset);
226  case 2: return getShortAt(offset);
227  case 3: return getIntAt(offset);
228  default: printf(" error : type = %d\n",type); break;
229  }
230  return -1;
231 }
232 
233 int64_t composite::getLong ( int element ,int row) const noexcept{
234  int rows = getRows();
235  if(row>=rows) {
236  printf(" error : requested row %d out of %d\n", row, rows);
237  return -1;
238  }
239  int offset = getRowSize()*row + offsets[element];
240  return getLongAt(offset);
241 }
242 
243 float composite::getFloat ( int element, int row) const noexcept {
244  int rows = getRows();
245  if(row>=rows) {
246  printf(" error : requested row %d out of %d\n", row, rows);
247  return 0.0;
248  }
249  int offset = getRowSize()*row + offsets[element];
250  return getFloatAt(offset);
251 }
252 
253 void composite::putInt ( int element, int row, int value){
254  int type = types[element];
255  int rows = getRows();
256  if(row>=rows) setRows(row+1);
257  int offset = getRowSize()*row + offsets[element];
258  //printf("[putInt] offset = %d\n",offset);
259  switch(type){
260  case 1: putByteAt(offset, (uint8_t) value); break;
261  case 2: putShortAt(offset, (uint16_t) value); break;
262  case 3: putIntAt(offset, value); /*printf(" after put = %d\n",getIntAt(offset));*/ break;
263  default: printf("[putInt] error : type = %d\n",type); break;
264  }
265 }
266 
267 void composite::putLong ( int element, int row, int64_t value){
268  int rows = getRows();
269  if(row>=rows) setRows(row+1);
270  int offset = getRowSize()*row + offsets[element];
271  putLongAt(offset, value);
272 }
273 
274 
275 void composite::putFloat ( int element, int row, float value){
276  int type = types[element];
277  int rows = getRows();
278  if(row>=rows) setRows(row+1);
279  int offset = getRowSize()*row + offsets[element];
280  if(type==4) putFloatAt(offset, value);
281  else printf("[putFloat] error : type = %d\n",type);
282 }
283 
285  //printf("-----> composite::notify method is called:\n");
286  types.clear(); offsets.clear();
287  char *destination = const_cast<char*> (&pointer()[4]);
288  int sword = *reinterpret_cast<int*>(destination);
289  //printf("sword = %X ---- %d\n",sword,sword);
290  int fsize = (sword>>24)&(0x000000FF);
291  int offset = 0;
292  for(int i = 0; i < fsize; i++){
293  char c = pointer()[8+i];
294  //printf("charachter at %d = %c\n",i,c);
295  switch(c){
296  case 'b': types.push_back(1); offsets.push_back(offset); offset += getTypeSize(1); break;
297  case 's': types.push_back(2); offsets.push_back(offset); offset += getTypeSize(2); break;
298  case 'i': types.push_back(3); offsets.push_back(offset); offset += getTypeSize(3); break;
299  case 'f': types.push_back(4); offsets.push_back(offset); offset += getTypeSize(4); break;
300  case 'd': types.push_back(5); offsets.push_back(offset); offset += getTypeSize(5); break;
301  case 'l': types.push_back(8); offsets.push_back(offset); offset += getTypeSize(8); break;
302  default: break;
303  }
304  }
305  rowOffset = offset;
306  //dataOffset = 8 + fsize;
307 }
308 
310  printf("\n------------- \n");
311  printf("[composite] identifiers : [%5d, %5d]\n",group(),item());
312  int headerSize = formatLength();
313  printf("[composite] format : [");
314  for(int i = 0; i < headerSize; i++) printf("%c",pointer()[8+i]);
315  printf("], row size = %5d , nrows = %5d\n",rowOffset, getRows());
316  printf("[composite] entry : ");
317  for(size_t k = 0; k < offsets.size(); k++) printf("%5zu ",k); printf("\n");
318  printf("[composite] types : ");
319  for(size_t k = 0; k < offsets.size(); k++) printf("%5d ",types[k]);
320  printf("\n");printf("[composite] offsets : ");
321  for(size_t k = 0; k < offsets.size(); k++) printf("%5d ",offsets[k]);
322  printf("\n------------\n");
323 
324  int nEntries = getEntries();
325  int nRows = getRows();
326  for(int e = 0; e < nEntries; e++){
327  printf("%5d : ", e);
328  for(int r = 0 ; r < nRows; r++){
329  int type = getEntryType(e);
330  if(type==1||type==2||type==3) printf("%8d ",getInt(e,r));
331  if(type==4) printf("%8.5f ",getFloat(e,r));
332  if(type==8) printf("%lld ",getLong(e,r));
333  }
334  printf("\n");
335  }
336 }
337 
338 
340 // hipo::bank::rowlist
342 
343 void bank::rowlist::reset(int numRows) {
344  m_list.clear();
345  m_init = false;
346  if(numRows >= 0)
347  m_list = createFullList(numRows);
348  else {
349  if(ownerBankIsUnknown("reset"))
350  return;
351  m_list = createFullList(m_owner_bank->getRows());
352  }
353  m_init = true;
354 }
355 
357  if(!m_init)
358  std::cerr << "WARNING: attempted to get an uninitialized bank row list" << std::endl;
359  return m_list;
360 }
361 
362 void bank::rowlist::setList(list_t const& list) {
363  m_list = list;
364  m_init = true;
365 }
366 
367 void bank::rowlist::filter(std::function<bool(bank&, int)> func) {
368  if(ownerBankIsUnknown("filter"))
369  return;
370  auto indx = m_list;
371  m_list.clear();
372  for(auto const& r : indx)
373  if(func(*m_owner_bank, r) == true)
374  m_list.push_back(r);
375 }
376 
377 void bank::rowlist::filter(const char *expression) {
378  if(ownerBankIsUnknown("filter"))
379  return;
380  Parser p(expression);
381  filter(p);
382 }
383 
385  if(ownerBankIsUnknown("filter"))
386  return;
387  int nitems = m_owner_bank->getSchema().getEntries();
388  schema &schema = m_owner_bank->getSchema();
389  auto indx = m_list;
390  m_list.clear();
391  for(auto const& r : indx){
392  for(int i = 0; i < nitems; i++)
393  p[schema.getEntryName(i)] = m_owner_bank->get(i,r);
394  if(p.Evaluate() > 0.5)
395  m_list.push_back(r);
396  }
397 }
398 
400  if(num < 0) {
401  std::cerr << "ERROR: attempted to call rowlist::getFullRowList with a negative size" << std::endl;
402  return {};
403  }
404  list_t result(num);
405  std::iota(result.begin(), result.end(), 0);
406  return result;
407 }
408 
409 bool bank::rowlist::ownerBankIsUnknown(std::string_view caller) {
410  if(m_owner_bank == nullptr) {
411  std::cerr <<
412  "ERROR: attempted to call hipo::bank::rowlist " <<
413  (caller=="" ? "method" : caller) <<
414  ", but no bank is associated to this rowlist" <<
415  std::endl;
416  return true;
417  }
418  return false;
419 }
420 
421 bank::rowlist::list_t bank::rowlist::s_number_list_init(list_t::size_type num) {
422  list_t result;
423  for(list_t::size_type i = 0; i < num; i++)
424  result.push_back(i);
425  return result;
426 }
427 
428 bank::rowlist::list_t bank::rowlist::s_number_list = bank::rowlist::s_number_list_init();
429 
430 
432 // hipo::bank
434 
435 bank::bank()= default;
436 
437 bank::~bank()= default;
438 
439 void bank::setRows(int rows){
440  bankRows = rows;
441  int size = bankSchema.getSizeForRows(bankRows);
442  initStructureBySize(bankSchema.getGroup(),bankSchema.getItem(), 11, size);
443  bankRowList.reset(bankRows);
444  //allocate(size+12);
445 }
446 
447 void bank::reset(){
448  setSize(0);
449  bankRows = 0;
450  bankRowList.reset(bankRows);
451 }
452 
454  int size = bankSchema.getRowLength();
455  bankRows = getSize()/size;
456  bankRowList.reset(bankRows);
457  //printf("---> bank notify called structure size = %8d (size = %5d) rows = %d\n",
458  // getSize(),size, bankRows);
459 }
460 
461 
462 void bank::putInt(const char *name, int index, int32_t value){
463  int item = bankSchema.getEntryOrder(name);
464  int offset = bankSchema.getOffset(item, index, bankRows);
465  putIntAt(offset,value);
466 }
467 void bank::putShort(const char *name, int index, int16_t value){
468  int item = bankSchema.getEntryOrder(name);
469  int offset = bankSchema.getOffset(item, index, bankRows);
470  putShortAt(offset,value);
471 }
472 void bank::putByte(const char *name, int index, int8_t value){
473  int item = bankSchema.getEntryOrder(name);
474  int offset = bankSchema.getOffset(item, index, bankRows);
475  putByteAt(offset,value);
476 }
477 void bank::putFloat(const char *name, int index, float value){
478  int item = bankSchema.getEntryOrder(name);
479  int offset = bankSchema.getOffset(item, index, bankRows);
480  putFloatAt(offset,value);
481 }
482 void bank::putDouble(const char *name, int index, double value){
483  int item = bankSchema.getEntryOrder(name);
484  int offset = bankSchema.getOffset(item, index, bankRows);
485  putDoubleAt(offset,value);
486 }
487 
488 void bank::putLong(const char *name, int index, int64_t value){
489  int item = bankSchema.getEntryOrder(name);
490  int offset = bankSchema.getOffset(item, index, bankRows);
491  putLongAt(offset,value);
492 }
493 
495  return bankRowList.getList();
496 }
497 
499  return bankRowList.createFullList(getRows());
500 }
501 
503  bankRowList.setOwnerBank(this);
504  return bankRowList;
505 }
506 
507 bank::rowlist::list_t const bank::getRowListLinked(int const row, int const column) const {
508  rowlist::list_t linked_rows;
509  for(auto const& r : getRowList()) {
510  if(getInt(column,r)==row)
511  linked_rows.push_back(r);
512  }
513  return linked_rows;
514 }
515 
516 void bank::show() const {
517  show(false);
518 }
519 
520 void bank::show(bool const showAllRows) const {
521 
522  bool loopAllRows = showAllRows || ! bankRowList.isInitialized() || getRowList().size() == getRows();
523  if(loopAllRows)
524  printf("BANK :: NAME %24s , ROWS %6d\n", bankSchema.getName().c_str(), getRows());
525  else
526  printf("BANK :: NAME %24s , ROWS %6zu (FILTERED FROM %d TOTAL)\n", bankSchema.getName().c_str(), getRowList().size(),getRows());
527 
528  for(int i = 0; i < bankSchema.getEntries(); i++){
529  printf("%18s : ", bankSchema.getEntryName(i).c_str());
530  if(loopAllRows)
531  for(int k = 0; k < getRows(); k++)
532  printValue(i, k);
533  else
534  for(auto const& k : getRowList())
535  printValue(i, k);
536  printf("\n");
537  }
538 }
539 
540 void bank::printValue(int schemaEntry, int row) const {
541  switch(bankSchema.getEntryType(schemaEntry)) {
542  case kByte:
543  case kShort:
544  case kInt:
545  printf("%8d ", getInt(schemaEntry, row));
546  break;
547  case kFloat:
548  printf("%8.5f ", getFloat(schemaEntry, row));
549  break;
550  case kDouble:
551  printf("%8.5f ", getDouble(schemaEntry, row));
552  break;
553  case kLong:
554  printf("%14ld ", getLong(schemaEntry, row));
555  break;
556  }
557 }
558 
559 banklist::size_type getBanklistIndex(banklist& banks, std::string const& bankName) noexcept(false) {
560  auto predicate = [&bankName](auto& bank) { return bank.getSchema().getName() == bankName; };
561  if(auto it{std::find_if(banks.begin(), banks.end(), predicate)}; it != banks.end())
562  return std::distance(banks.begin(), it);
563  throw std::runtime_error("bank named '" + bankName + "' not found in banklist");
564 }
565 
566 }
Core HIPO data structures: structure, composite, and bank classes for tabular data access.
Mathematical expression parser and evaluator.
Definition: parser.h:43
const double Evaluate()
Evaluate the stored expression using current symbol values.
Definition: parser.cpp:653
rowlist encapsulates a list of rows for this bank, providing a way to iterate over them
Definition: bank.h:357
list_t const & getList() const
Definition: bank.cpp:356
void setOwnerBank(bank *const ownerBank)
Definition: bank.h:391
void reset(int numRows=-1)
Definition: bank.cpp:343
void filter(std::function< bool(bank &, int)> func)
Definition: bank.cpp:367
void setList(list_t const &list)
Definition: bank.cpp:362
bool isInitialized() const
Definition: bank.h:368
std::vector< int > list_t
Definition: bank.h:360
static list_t createFullList(int num)
Definition: bank.cpp:399
void filter(char const *expression)
Definition: bank.cpp:377
Represents a HIPO bank, a tabular data structure with rows and typed columns.
Definition: bank.h:352
void setRows(int rows)
Definition: bank.cpp:439
void putByte(const char *name, int index, int8_t value)
Definition: bank.cpp:472
void reset()
Reset the bank to an empty state (zero rows).
Definition: bank.cpp:447
rowlist::list_t const & getRowList() const
Definition: bank.cpp:494
void putFloat(const char *name, int index, float value)
Definition: bank.cpp:477
rowlist & getMutableRowList()
Definition: bank.cpp:502
int getInt(int item, int index) const noexcept
Definition: bank.h:714
void putShort(const char *name, int index, int16_t value)
Definition: bank.cpp:467
bank()
Default constructor.
void notify() override
Called when the bank is updated; recalculates the row count from the schema.
Definition: bank.cpp:453
void putLong(const char *name, int index, int64_t value)
Definition: bank.cpp:488
long getLong(int item, int index) const noexcept
Definition: bank.h:706
void printValue(int schemaEntry, int row) const
Definition: bank.cpp:540
int getRows() const noexcept
Definition: bank.h:446
void putDouble(const char *name, int index, double value)
Definition: bank.cpp:482
void show() const override
show this bank's contents; only the rows in its current rowlist instance are shown
Definition: bank.cpp:516
float getFloat(int item, int index) const noexcept
Definition: bank.h:686
schema & getSchema()
Definition: bank.h:443
~bank() override
rowlist::list_t const getFullRowList() const
Definition: bank.cpp:498
void putInt(const char *name, int index, int32_t value)
Definition: bank.cpp:462
double getDouble(int item, int index) const noexcept
Definition: bank.h:694
rowlist::list_t const getRowListLinked(int const row, int const column) const
Definition: bank.cpp:507
int getRows() const noexcept
Definition: bank.h:295
int getInt(int element, int row) const noexcept
Definition: bank.cpp:216
virtual void notify()
Called when the composite is updated (e.g., after reading an event).
Definition: bank.cpp:284
int getEntries() const noexcept
Definition: bank.h:298
void print()
Print the composite contents to standard output.
Definition: bank.cpp:309
void putLong(int element, int row, int64_t value)
Definition: bank.cpp:267
float getFloat(int element, int row) const noexcept
Definition: bank.cpp:243
void putInt(int element, int row, int value)
Definition: bank.cpp:253
int getEntryType(int index) const noexcept
Definition: bank.h:301
void parse(std::string format)
Definition: bank.cpp:162
void reset()
Reset the composite to an empty state.
Definition: bank.cpp:150
int getRowSize() const noexcept
Definition: bank.h:307
int64_t getLong(int element, int row) const noexcept
Definition: bank.cpp:233
void putFloat(int element, int row, float value)
Definition: bank.cpp:275
composite()
Default constructor.
Definition: bank.h:260
void setRows(int rows)
Definition: bank.cpp:166
int formatLength() const noexcept
Definition: node.h:151
int group()
Definition: node.h:212
int item()
Definition: node.h:214
void putFloatAt(int index, float value)
Write a 32-bit float at the given byte offset within the data region.
Definition: node.h:293
int capacity() const noexcept
Definition: node.h:145
void putShortAt(int index, int16_t value)
Write a 16-bit integer at the given byte offset within the data region.
Definition: node.h:277
void create(int group, int item, int type, int size)
Create a node with the given header fields and allocate storage.
Definition: node.cpp:51
void putByteAt(int index, int8_t value)
Write an 8-bit integer at the given byte offset within the data region.
Definition: node.h:285
const char * pointer()
Definition: node.h:219
int type()
Definition: node.h:216
void putIntAt(int index, int value)
Write a 32-bit integer at the given byte offset within the data region.
Definition: node.h:269
void putLongAt(int index, int64_t value)
Write a 64-bit integer at the given byte offset within the data region.
Definition: node.h:309
void setDataLength(int length)
Set the data payload length, preserving the format length.
Definition: node.h:171
void setFormatLength(int length)
Set the format descriptor length.
Definition: node.h:160
Schema definition for a HIPO bank.
Definition: dictionary.h:73
std::string getName() const
Get the schema name.
Definition: dictionary.h:125
int getEntryOrder(const char *name) const
Get the column index for a given column name.
Definition: dictionary.h:239
std::string getEntryName(int item) const noexcept
Get the name of a column by index.
Definition: dictionary.h:214
int getSizeForRows(int rows)
Compute the total buffer size needed for a given number of rows.
Definition: dictionary.cpp:80
int getOffset(int item, int order, int rows) const
Compute the byte offset for a column value by column index.
Definition: dictionary.h:171
int getRowLength() const noexcept
Get the size of a single row in bytes.
Definition: dictionary.h:141
int getItem()
Get the item identifier.
Definition: dictionary.h:131
int getEntries() const noexcept
Get the number of columns in the schema.
Definition: dictionary.h:217
int getGroup()
Get the group identifier.
Definition: dictionary.h:128
int getEntryType(int item) const noexcept
Get the type identifier of a column by index.
Definition: dictionary.h:193
void initStructureBySize(int __group, int __item, int __type, int __size)
Initialize the structure buffer with the given group, item, type, and data size.
Definition: bank.cpp:67
void putShortAt(int index, int16_t value)
Definition: bank.h:198
int getItem() const
Definition: bank.cpp:108
int getSize() const noexcept
Definition: bank.h:106
void putIntAt(int index, int value)
Definition: bank.h:191
int getDataSize() const noexcept
Definition: bank.h:119
void putByteAt(int index, int8_t value)
Definition: bank.h:205
bool allocate(int size)
Definition: bank.cpp:60
int getGroup() const
Definition: bank.cpp:103
void putStringAt(int index, std::string &str)
Definition: bank.cpp:137
structure()
Default constructor. Sets the structure address to nullptr.
Definition: bank.h:87
void setSize(int size)
Definition: bank.cpp:76
virtual void show() const
Display the structure contents to standard output.
Definition: bank.cpp:122
int dataOffset
Definition: bank.h:80
void putLongAt(int index, int64_t value)
Definition: bank.h:226
int getType() const
Definition: bank.cpp:98
void initNoCopy(const char *buffer, int size)
Definition: bank.cpp:112
void setDataSize(int size)
Definition: bank.cpp:82
void putDoubleAt(int index, double value)
Definition: bank.h:219
void putFloatAt(int index, float value)
Definition: bank.h:212
int getHeaderSize() const noexcept
Definition: bank.h:113
void init(const char *buffer, int size)
Definition: bank.cpp:116
std::string getStringAt(int index)
Definition: bank.cpp:127
void setHeaderSize(int size)
Definition: bank.cpp:91
const char * getAddress()
Definition: bank.cpp:142
Definition: bank.cpp:47
@ kLong
64-bit signed integer.
Definition: dictionary.h:57
@ kInt
32-bit signed integer.
Definition: dictionary.h:54
@ kFloat
32-bit IEEE 754 floating point.
Definition: dictionary.h:55
@ kShort
16-bit signed integer.
Definition: dictionary.h:53
@ kByte
8-bit signed integer.
Definition: dictionary.h:52
@ kDouble
64-bit IEEE 754 floating point.
Definition: dictionary.h:56
constexpr uint32_t STRUCT_FORMAT_BYTE
Definition: constants.h:129
constexpr int STRUCT_FORMAT_SHIFT
Definition: constants.h:128
std::vector< bank > banklist
Definition: bank.h:948
banklist::size_type getBanklistIndex(banklist &banks, std::string const &bankName) noexcept(false)
Find the index of a bank by name in a banklist.
Definition: bank.cpp:559
constexpr uint32_t STRUCT_FORMAT_MASK
Definition: constants.h:127
constexpr uint32_t STRUCT_SIZE_MASK
Definition: constants.h:126
Mathematical expression parser for arithmetic and conditional evaluation.