Go to the documentation of this file.
5 #ifndef _UNIVERSAL_METADATA_HPP_
6 #define _UNIVERSAL_METADATA_HPP_ "$Id: UniversalMetaData.hpp 482 2020-07-28 10:08:15Z geoff $"
86 #define RELATIVE_FIELD_OFFSET(className,n) (reinterpret_cast<unsigned char *>(&(((className *)(8192))-> n)) - reinterpret_cast<unsigned char *>(8192))
97 #define DESCRIBE_NAMED_FIELD_OF_CLASS(shortName,n,t,className) { 1, SharedMemoryVariable:: t, (uint16_t) RELATIVE_FIELD_OFFSET(className,n), sizeof(((className *)(0))-> n), {""}, { shortName } }
108 #define DESCRIBE_OPTIONAL_NAMED_FIELD_OF_CLASS(group,shortName,n,t,className) { group, SharedMemoryVariable:: t, (uint16_t) RELATIVE_FIELD_OFFSET(className,n), sizeof(((className *)(0))-> n), {""}, { shortName } }
111 #define __ZERO_FILL_BIT 128
124 #define DESCRIBE_OPTIONAL_OR_ZERO_FILLED_NAMED_FIELD_OF_CLASS(group,shortName,n,t,className) { __ZERO_FILL_BIT | (group), SharedMemoryVariable:: t, (uint16_t) RELATIVE_FIELD_OFFSET(className,n), sizeof(((className *)(0))-> n), {""}, { shortName } }
133 #define DESCRIBE_FIELD_OF_CLASS(n,t,className) DESCRIBE_NAMED_FIELD_OF_CLASS(#n, n, t, className)
143 #define DESCRIBE_OPTIONAL_FIELD_OF_CLASS(group,n,t,className) DESCRIBE_NAMED_FIELD_OF_CLASS(group, #n, n, t, className)
154 #define DESCRIBE_OPTIONAL_OR_ZERO_FILLED_FIELD_OF_CLASS(group,n,t,className) DESCRIBE_NAMED_FIELD_OF_CLASS(__ZERO_FILL_BIT | (group), #n, n, t, className)
180 const char *magicNumber,
181 const char *fileName,
182 const uint32_t totalRecords,
const void **tableBase,
183 const uint32_t outputRecordLength);
249 const char *fileName,
250 const RECORD_CLASS **resultTable,
251 unsigned char **retSegmentBase,
252 size_t *retSegmentLen,
size_t *retDataOffset)
254 unsigned char *segmentBase;
255 size_t segmentLen = 0;
258 *retSegmentBase = segmentBase;
259 *retSegmentLen = segmentLen;
260 if (segmentBase ==
nullptr) {
263 *resultTable =
nullptr;
277 *resultTable =
nullptr;
293 const unsigned char *startOfData =
294 reinterpret_cast<const unsigned char *
>(hdr) + dataOffset;
296 if (metaRecordLength != 0) {
297 const size_t minSize = dataOffset + (totalRecords * metaRecordLength);
298 if (segmentLen < minSize) {
300 " but at least " << minSize <<
301 " bytes would be required for file to hold " << totalRecords <<
303 *resultTable =
nullptr;
308 *resultTable =
reinterpret_cast<const RECORD_CLASS *
>(startOfData);
309 *retDataOffset = dataOffset;
328 const RECORD_CLASS **table,
329 const uint32_t totalRecords,
const uint32_t recordLength) {
330 const void **tableBase =
reinterpret_cast<const void **
>(table);
335 fileName, totalRecords, tableBase, recordLength);
373 const unsigned char *sourceRecord,
unsigned char *destinationRecord,
381 const unsigned char *sourceRecord,
unsigned char *destinationRecord,
418 template <
typename TO_FORMAT,
typename FROM_FORMAT=GENERIC_META_RECORD> TO_FORMAT *
loadAndConvertMetaData(
const char *fileName, uint32_t *recTotal,
420 void *userData=
nullptr)
427 const FROM_FORMAT *resultTable;
428 unsigned char *segmentBase;
429 size_t segmentLen, dataOffset;
433 &resultTable, &segmentBase, &segmentLen, &dataOffset);
434 if (fileHdr ==
nullptr) {
435 if (recTotal !=
nullptr) {
438 if (segmentBase !=
nullptr) {
440 munmap(segmentBase, segmentLen);
442 UnmapViewOfFile(segmentBase);
448 const unsigned char *fieldRec = segmentBase + fileHdr->
headerLength;
450 const uint_fast16_t sourceFieldTotal = fileHdr->
totalFields;
456 FieldMap *fieldMapping =
new FieldMap[sourceFieldTotal + destFieldTotal];
459 uint8_t *handledDestField =
new uint8_t[destFieldTotal];
460 memset(handledDestField, 0, destFieldTotal);
462 for(uint_fast16_t i=0;i<sourceFieldTotal;i+=1) {
464 fieldMapping[i].sourceField = fieldDesc;
465 fieldMapping[i].destField =
nullptr;
467 for(uint_fast16_t j=0;j < destFieldTotal;j+=1) {
477 handledDestField[j] =
true;
481 fieldRec += fieldLen;
484 uint_fast16_t totalFields = sourceFieldTotal;
485 for(uint_fast16_t i=0;i<MetaDataLoaderForFormat<TO_FORMAT>::totalFields;i+=1) {
486 if (handledDestField[i] ==
false) {
488 fieldMapping[totalFields].sourceField =
nullptr;
494 delete[] handledDestField;
499 if (recTotal !=
nullptr) {
500 *recTotal = recordTotal;
502 TO_FORMAT *newTable =
new TO_FORMAT[recordTotal];
503 const unsigned char *sourceRecord = segmentBase + dataOffset;
504 for(uint_fast32_t i=0;i<recordTotal;i+=1) {
506 uint_fast32_t recLen;
515 for(uint_fast16_t j=0;j<sourceFieldTotal;j+=1) {
516 const FieldMap &entry = fieldMapping[j];
517 uint_fast8_t groupIdSpec = entry.sourceField->fieldGroupId;
518 uint_fast8_t groupId = (groupIdSpec & 63) - 1;
519 uint64_t maskBit =
static_cast<uint64_t
>(1) << groupId;
521 (*transferFunction)(entry.sourceField, entry.destField,
523 reinterpret_cast<unsigned char *
>(&(newTable[i])), userData);
524 }
else if (entry.destField !=
nullptr) {
525 const uint_fast8_t zeroFillIfNotPresent = entry.destField->fieldGroupId & __ZERO_FILL_BIT;
526 if (zeroFillIfNotPresent != 0) {
527 (*transferFunction)(entry.sourceField, entry.destField,
529 reinterpret_cast<unsigned char *
>(&(newTable[i])), userData);
534 for(uint_fast16_t j=sourceFieldTotal;j<totalFields;j+=1) {
535 const FieldMap &entry = fieldMapping[j];
537 (*transferFunction)(entry.destField, entry.destField,
539 reinterpret_cast<unsigned char *
>(&(newTable[i])), userData);
542 (*transferFunction)(
nullptr,
nullptr, sourceRecord,
543 reinterpret_cast<unsigned char *
>(&(newTable[i])), userData);
544 sourceRecord += recLen;
546 delete[] fieldMapping;
548 munmap(segmentBase, segmentLen);
550 UnmapViewOfFile(segmentBase);
555 #undef __ZERO_FILL_BIT
Ïúíþ ð Ø ˜ ˜ __text __TEXT € __apple_names __DWARF __apple_objc __DWARF __apple_namespac__DWARF H X __apple_types __DWARF l
Definition: tmp3.o.cpp:1
@ SMV_TYPE_INT64
Definition: shared_variable.hpp:49
@ SMV_TYPE_DOUBLE
Definition: shared_variable.hpp:52
const uint32_t powersOf10[10]
Table of powers-of-10 constants as 32-bit unsigned integers.
Definition: text2int_tbl.h:37
@ SMV_TYPE_STRING
Definition: shared_variable.hpp:56
#define MAP_FILE_READONLY
Definition: mapped_file.h:66
uint32_t n4to_uint32(const void *byteData) NONNULL_PARAMETERS(1) OME_ALWAYS_INLINE OME_ALWAYS_OPTIMIZE("-O3")
Convert a network byte order 4-byte integer into a native unsigned 32-bit value.
Definition: text2int.h:321
int_fast8_t precision
Definition: text2int.h:529
Return value structure for representing fixed-point values with variable precision.
Definition: text2int.h:527
char * fixedpoint_to_ascii(char *resultBfr, uint_fast8_t bfrLen, int64_t value, uint_fast8_t precision, uint_fast8_t *retStrLen, int_fast8_t outputPrecision)
Format a fixed-point value with indicated decimal places.
Definition: text2int.cpp:2734
@ SMV_TYPE_FLOAT
Definition: shared_variable.hpp:51
const char srcID[]
Definition: catSym.c:17
#define OME_EXPECT_TRUE(expr)
Annotation macro for conditional expression expected to be true.
Definition: compiler_hints.h:541
#define NULL
Definition: tmp.o.cpp:327
LogMaskType_t COMPONENT_LOG_MASK() app("app_logMask", &DEFAULT_sharedMemoryVariableManager, COMPONENT_LEVEL(app, defaultMask))
@ SMV_TYPE_FIXED
Definition: shared_variable.hpp:53
char * float_to_ascii(char *resultBfr, uint_fast8_t bfrLen, double value, uint_fast8_t *retStrLen, int_fast8_t outputPrecision, bool roundValue)
Format a double-precision value with indicated decimal places.
Definition: text2int.cpp:2808
int createMappedFile(unsigned char **segment, const char *fileName, size_t *segmentLenPtr, uint_fast32_t doInit)
Create or open a mapped file with the specified file name.
Definition: mapped_file.cpp:207
@ SMV_TYPE_INT32
Definition: shared_variable.hpp:47
char * int_to_ascii(uint32_t resultBfr[], uint_fast8_t bfrLen, int64_t value, uint_fast8_t *retStrLen)
Identical to uint_to_ascii(), except that negative values are accepted.
Definition: text2int.cpp:2699
const char srcID[] OME_USED
Definition: tick_time.cpp:24
int64_t value
Definition: text2int.h:528
@ SMV_TYPE_UNSIGNED
Definition: shared_variable.hpp:45
#define OME_EXPECT_FALSE(expr)
Annotation macro for conditional expression expected to be false.
Definition: compiler_hints.h:540
#define LOG_COMPONENT_CERR(component, lvl)
Convenience macro that uses LOG_COMPONENT_INTO to conditionally log a message to standard error.
Definition: logging_api.hpp:3030
@ SMV_TYPE_UINT32
Definition: shared_variable.hpp:48
#define LOG_ENDLINE
Closing clause for text line output using << operators.
Definition: logging_api.hpp:2956
#define OS_HANDLE_TYPE
Definition: io_processor.hpp:48
char * uint_to_ascii(uint32_t resultBfr[], uint_fast8_t bfrLen, uint64_t value, uint_fast8_t *retStrLen)
Quickly convert a binary integer into ASCII decimal text.
Definition: text2int.cpp:2628
@ SMV_TYPE_UINT64
Definition: shared_variable.hpp:50
VariableFixedPointValue fast_ascii_to_fixedpoint(const char *str, uint_fast8_t len, int_fast8_t desiredPrecision)
Convert ASCII decimal text string to fixed point representation.
Definition: text2int.cpp:2888
#define htonl(x)
Definition: tmp.o.cpp:3098
@ SMV_TYPE_TINY_STRING
Definition: shared_variable.hpp:54
int fd
Definition: ethers.c:41
#define LOG_CERR(lvl)
Convenience macro that uses LOG_INTO() to conditionally log a message to standard error.
Definition: logging_api.hpp:3014