55 int length = str.length();
61 if(structureBuffer.size()<size){
62 structureBuffer.resize(size+32);
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;
77 int sizeWord = *
reinterpret_cast<uint32_t *
>(structureAddress+4);
79 *
reinterpret_cast<uint32_t *
>(structureAddress+4) = header|(size&
STRUCT_SIZE_MASK);
83 int sizeWord = *
reinterpret_cast<uint32_t *
>(structureAddress+4);
86 int totalSize = headerSize + size;
88 *
reinterpret_cast<uint32_t *
>(structureAddress+4) = header|(totalSize&
STRUCT_SIZE_MASK);
92 int sizeWord = *
reinterpret_cast<uint32_t *
>(structureAddress+4);
99 auto type = (int) (*
reinterpret_cast<uint8_t *
>(structureAddress+3));
104 auto group = (int) (*
reinterpret_cast<uint16_t *
>(structureAddress));
109 auto item = (int) (*
reinterpret_cast<uint8_t *
>(structureAddress+2));
113 structureAddress =
const_cast<char*
>(buffer);
118 memcpy(&structureBuffer[0],buffer,size);
119 structureAddress = &structureBuffer[0];
123 printf(
"structure : [%5d,%5d] type = %4d, header = %5d, length = %6d, data size = %5d, offset = %5d, capacity = %5lu\n",
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;
138 int strLen = str.length();
139 std::memcpy(&structureBuffer[8],&str[0],strLen);
143 return structureAddress;
163 parse(134,1,format,256);
168 printf(
"composite::setRows:: error, the requested row %d exceeds the bank capacity of %d\n",
176 types.clear(); offsets.clear();
177 int length = format.length();
179 for(
int i = 0; i < length; i++){
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;
196 memcpy(
const_cast<char *
>(&
pointer()[8]),&format[0],length);
204 int composite::getTypeSize(
int type){
217 int type = types[element];
218 int rows = getRows();
220 printf(
" error : requested row %d out of %d\n", row, rows);
223 int offset = getRowSize()*row + offsets[element];
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;
234 int rows = getRows();
236 printf(
" error : requested row %d out of %d\n", row, rows);
239 int offset = getRowSize()*row + offsets[element];
240 return getLongAt(offset);
244 int rows = getRows();
246 printf(
" error : requested row %d out of %d\n", row, rows);
249 int offset = getRowSize()*row + offsets[element];
250 return getFloatAt(offset);
254 int type = types[element];
257 int offset =
getRowSize()*row + offsets[element];
260 case 1:
putByteAt(offset, (uint8_t) value);
break;
261 case 2:
putShortAt(offset, (uint16_t) value);
break;
262 case 3:
putIntAt(offset, value);
break;
263 default: printf(
"[putInt] error : type = %d\n",
type);
break;
270 int offset =
getRowSize()*row + offsets[element];
276 int type = types[element];
279 int offset =
getRowSize()*row + offsets[element];
281 else printf(
"[putFloat] error : type = %d\n",
type);
286 types.clear(); offsets.clear();
287 char *destination =
const_cast<char*
> (&
pointer()[4]);
288 int sword = *
reinterpret_cast<int*
>(destination);
290 int fsize = (sword>>24)&(0x000000FF);
292 for(
int i = 0; i < fsize; i++){
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;
310 printf(
"\n------------- \n");
311 printf(
"[composite] identifiers : [%5d, %5d]\n",
group(),
item());
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");
326 for(
int e = 0; e < nEntries; e++){
328 for(
int r = 0 ; r < nRows; r++){
349 if(ownerBankIsUnknown(
"reset"))
358 std::cerr <<
"WARNING: attempted to get an uninitialized bank row list" << std::endl;
368 if(ownerBankIsUnknown(
"filter"))
372 for(
auto const& r : indx)
373 if(func(*m_owner_bank, r) ==
true)
378 if(ownerBankIsUnknown(
"filter"))
385 if(ownerBankIsUnknown(
"filter"))
387 int nitems = m_owner_bank->getSchema().getEntries();
391 for(
auto const& r : indx){
392 for(
int i = 0; i < nitems; i++)
401 std::cerr <<
"ERROR: attempted to call rowlist::getFullRowList with a negative size" << std::endl;
405 std::iota(result.begin(), result.end(), 0);
409 bool bank::rowlist::ownerBankIsUnknown(std::string_view caller) {
410 if(m_owner_bank ==
nullptr) {
412 "ERROR: attempted to call hipo::bank::rowlist " <<
413 (caller==
"" ?
"method" : caller) <<
414 ", but no bank is associated to this rowlist" <<
423 for(list_t::size_type i = 0; i < num; i++)
443 bankRowList.
reset(bankRows);
450 bankRowList.
reset(bankRows);
456 bankRowList.
reset(bankRows);
464 int offset = bankSchema.
getOffset(item, index, bankRows);
469 int offset = bankSchema.
getOffset(item, index, bankRows);
474 int offset = bankSchema.
getOffset(item, index, bankRows);
479 int offset = bankSchema.
getOffset(item, index, bankRows);
484 int offset = bankSchema.
getOffset(item, index, bankRows);
490 int offset = bankSchema.
getOffset(item, index, bankRows);
511 linked_rows.push_back(r);
524 printf(
"BANK :: NAME %24s , ROWS %6d\n", bankSchema.
getName().c_str(),
getRows());
526 printf(
"BANK :: NAME %24s , ROWS %6zu (FILTERED FROM %d TOTAL)\n", bankSchema.
getName().c_str(),
getRowList().size(),
getRows());
528 for(
int i = 0; i < bankSchema.
getEntries(); i++){
531 for(
int k = 0; k <
getRows(); k++)
545 printf(
"%8d ",
getInt(schemaEntry, row));
548 printf(
"%8.5f ",
getFloat(schemaEntry, row));
551 printf(
"%8.5f ",
getDouble(schemaEntry, row));
554 printf(
"%14ld ",
getLong(schemaEntry, row));
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");
Core HIPO data structures: structure, composite, and bank classes for tabular data access.
Mathematical expression parser and evaluator.
const double Evaluate()
Evaluate the stored expression using current symbol values.
rowlist encapsulates a list of rows for this bank, providing a way to iterate over them
list_t const & getList() const
void setOwnerBank(bank *const ownerBank)
void reset(int numRows=-1)
void filter(std::function< bool(bank &, int)> func)
void setList(list_t const &list)
bool isInitialized() const
std::vector< int > list_t
static list_t createFullList(int num)
void filter(char const *expression)
Represents a HIPO bank, a tabular data structure with rows and typed columns.
void putByte(const char *name, int index, int8_t value)
void reset()
Reset the bank to an empty state (zero rows).
rowlist::list_t const & getRowList() const
void putFloat(const char *name, int index, float value)
rowlist & getMutableRowList()
int getInt(int item, int index) const noexcept
void putShort(const char *name, int index, int16_t value)
bank()
Default constructor.
void notify() override
Called when the bank is updated; recalculates the row count from the schema.
void putLong(const char *name, int index, int64_t value)
long getLong(int item, int index) const noexcept
void printValue(int schemaEntry, int row) const
int getRows() const noexcept
void putDouble(const char *name, int index, double value)
void show() const override
show this bank's contents; only the rows in its current rowlist instance are shown
float getFloat(int item, int index) const noexcept
rowlist::list_t const getFullRowList() const
void putInt(const char *name, int index, int32_t value)
double getDouble(int item, int index) const noexcept
rowlist::list_t const getRowListLinked(int const row, int const column) const
int getRows() const noexcept
int getInt(int element, int row) const noexcept
virtual void notify()
Called when the composite is updated (e.g., after reading an event).
int getEntries() const noexcept
void print()
Print the composite contents to standard output.
void putLong(int element, int row, int64_t value)
float getFloat(int element, int row) const noexcept
void putInt(int element, int row, int value)
int getEntryType(int index) const noexcept
void parse(std::string format)
void reset()
Reset the composite to an empty state.
int getRowSize() const noexcept
int64_t getLong(int element, int row) const noexcept
void putFloat(int element, int row, float value)
composite()
Default constructor.
int formatLength() const noexcept
void putFloatAt(int index, float value)
Write a 32-bit float at the given byte offset within the data region.
int capacity() const noexcept
void putShortAt(int index, int16_t value)
Write a 16-bit integer at the given byte offset within the data region.
void create(int group, int item, int type, int size)
Create a node with the given header fields and allocate storage.
void putByteAt(int index, int8_t value)
Write an 8-bit integer at the given byte offset within the data region.
void putIntAt(int index, int value)
Write a 32-bit integer at the given byte offset within the data region.
void putLongAt(int index, int64_t value)
Write a 64-bit integer at the given byte offset within the data region.
void setDataLength(int length)
Set the data payload length, preserving the format length.
void setFormatLength(int length)
Set the format descriptor length.
Schema definition for a HIPO bank.
std::string getName() const
Get the schema name.
int getEntryOrder(const char *name) const
Get the column index for a given column name.
std::string getEntryName(int item) const noexcept
Get the name of a column by index.
int getSizeForRows(int rows)
Compute the total buffer size needed for a given number of rows.
int getOffset(int item, int order, int rows) const
Compute the byte offset for a column value by column index.
int getRowLength() const noexcept
Get the size of a single row in bytes.
int getItem()
Get the item identifier.
int getEntries() const noexcept
Get the number of columns in the schema.
int getGroup()
Get the group identifier.
int getEntryType(int item) const noexcept
Get the type identifier of a column by index.
void initStructureBySize(int __group, int __item, int __type, int __size)
Initialize the structure buffer with the given group, item, type, and data size.
void putShortAt(int index, int16_t value)
int getSize() const noexcept
void putIntAt(int index, int value)
int getDataSize() const noexcept
void putByteAt(int index, int8_t value)
void putStringAt(int index, std::string &str)
structure()
Default constructor. Sets the structure address to nullptr.
virtual void show() const
Display the structure contents to standard output.
void putLongAt(int index, int64_t value)
void initNoCopy(const char *buffer, int size)
void setDataSize(int size)
void putDoubleAt(int index, double value)
void putFloatAt(int index, float value)
int getHeaderSize() const noexcept
void init(const char *buffer, int size)
std::string getStringAt(int index)
void setHeaderSize(int size)
const char * getAddress()
@ kLong
64-bit signed integer.
@ kInt
32-bit signed integer.
@ kFloat
32-bit IEEE 754 floating point.
@ kShort
16-bit signed integer.
@ kByte
8-bit signed integer.
@ kDouble
64-bit IEEE 754 floating point.
constexpr uint32_t STRUCT_FORMAT_BYTE
constexpr int STRUCT_FORMAT_SHIFT
std::vector< bank > banklist
banklist::size_type getBanklistIndex(banklist &banks, std::string const &bankName) noexcept(false)
Find the index of a bank by name in a banklist.
constexpr uint32_t STRUCT_FORMAT_MASK
constexpr uint32_t STRUCT_SIZE_MASK
Mathematical expression parser for arithmetic and conditional evaluation.