RelAccX improvements

This commit is contained in:
Thulinma 2018-03-13 22:39:54 +01:00
parent 7ea42685a6
commit 12d18bd7c5
2 changed files with 7 additions and 40 deletions

View file

@ -411,13 +411,10 @@ namespace Util{
/// Gets the size in bytes of a single record in the structure. /// Gets the size in bytes of a single record in the structure.
uint32_t RelAccX::getRSize() const{return RAXHDR_RECORDSIZE;} uint32_t RelAccX::getRSize() const{return RAXHDR_RECORDSIZE;}
/// Gets the position in the records where the entries start
uint32_t RelAccX::getStartPos() const{return RAXHDR_STARTPOS;}
/// Gets the number of deleted records /// Gets the number of deleted records
uint64_t RelAccX::getDeleted() const{return RAXHDR_DELETED;} uint64_t RelAccX::getDeleted() const{return RAXHDR_DELETED;}
//Gets the number of the last valid index /// Gets the number of the last valid index
uint64_t RelAccX::getEndPos() const{return RAXHDR_ENDPOS;} uint64_t RelAccX::getEndPos() const{return RAXHDR_ENDPOS;}
///Gets the number of fields per recrd ///Gets the number of fields per recrd
@ -662,15 +659,11 @@ namespace Util{
/// Sets the record counter to the given value. /// Sets the record counter to the given value.
void RelAccX::setRCount(uint32_t count){RAXHDR_RECORDCNT = count;} void RelAccX::setRCount(uint32_t count){RAXHDR_RECORDCNT = count;}
/// Sets the position in the records where the entries start
void RelAccX::setStartPos(uint32_t n){RAXHDR_STARTPOS = n;}
/// Sets the number of deleted records /// Sets the number of deleted records
void RelAccX::setDeleted(uint64_t n){RAXHDR_DELETED = n;} void RelAccX::setDeleted(uint64_t n){RAXHDR_DELETED = n;}
/// Sets the number of records present /// Sets the number of the last valid index
/// Defaults to the record count if set to zero. void RelAccX::setEndPos(uint64_t n){RAXHDR_ENDPOS = n;}
void RelAccX::setPresent(uint32_t n){RAXHDR_PRESENT = n;}
/// Sets the ready flag. /// Sets the ready flag.
/// After calling this function, addField() may no longer be called. /// After calling this function, addField() may no longer be called.
@ -757,38 +750,14 @@ namespace Util{
/// Updates the deleted record counter, the start position and the present record counter, /// Updates the deleted record counter, the start position and the present record counter,
/// shifting the ring buffer start position forward without moving the ring buffer end position. /// shifting the ring buffer start position forward without moving the ring buffer end position.
/// If the records present counter would be pushed into the negative by this function, sets it to
/// zero, defaulting it to the record count for all relevant purposes.
void RelAccX::deleteRecords(uint32_t amount){ void RelAccX::deleteRecords(uint32_t amount){
uint32_t &startPos = RAXHDR_STARTPOS; RAXHDR_DELETED += amount; // update deleted record counter
uint64_t &deletedRecs = RAXHDR_DELETED;
uint32_t &recsPresent = RAXHDR_PRESENT;
startPos += amount; // update start position
deletedRecs += amount; // update deleted record counter
if (recsPresent >= amount){
recsPresent -= amount; // decrease records present
}else{
WARN_MSG("Depleting recordCount!");
recsPresent = 0;
}
} }
/// Updates the present record counter, shifting the ring buffer end position forward without /// Updates the present record counter, shifting the ring buffer end position forward without
/// moving the ring buffer start position. /// moving the ring buffer start position.
/// If the records present counter would be pushed past the record counter by this function, sets
/// it to zero, defaulting it to the record count for all relevant purposes.
void RelAccX::addRecords(uint32_t amount){ void RelAccX::addRecords(uint32_t amount){
uint32_t & recsPresent = RAXHDR_PRESENT; RAXHDR_ENDPOS += amount;
uint32_t & recordsCount = RAXHDR_RECORDCNT;
uint64_t & recordEndPos = RAXHDR_ENDPOS;
if (recsPresent+amount > recordsCount){
BACKTRACE
WARN_MSG("Exceeding recordCount (%d [%d + %d] > %d)", recsPresent + amount, recsPresent, amount, recordsCount);
recsPresent = 0;
}else{
recsPresent += amount;
}
recordEndPos += amount;
} }
FieldAccX RelAccX::getFieldAccX(const std::string & fName){ FieldAccX RelAccX::getFieldAccX(const std::string & fName){

View file

@ -70,6 +70,7 @@ namespace Util{
#define RAX_64STRING 0x32 #define RAX_64STRING 0x32
#define RAX_128STRING 0x33 #define RAX_128STRING 0x33
#define RAX_256STRING 0x34 #define RAX_256STRING 0x34
#define RAX_512STRING 0x35
#define RAX_RAW 0x40 #define RAX_RAW 0x40
#define RAX_256RAW 0x44 #define RAX_256RAW 0x44
#define RAX_512RAW 0x45 #define RAX_512RAW 0x45
@ -115,10 +116,8 @@ namespace Util{
uint32_t getRCount() const; uint32_t getRCount() const;
uint32_t getRSize() const; uint32_t getRSize() const;
uint16_t getOffset() const; uint16_t getOffset() const;
uint32_t getStartPos() const;
uint64_t getDeleted() const; uint64_t getDeleted() const;
uint64_t getEndPos() const; uint64_t getEndPos() const;
size_t getPresent() const;
uint32_t getFieldCount() const; uint32_t getFieldCount() const;
bool isReady() const; bool isReady() const;
bool isExit() const; bool isExit() const;
@ -138,9 +137,8 @@ namespace Util{
//Read-write functions: //Read-write functions:
void addField(const std::string & name, uint8_t fType, uint32_t fLen=0); void addField(const std::string & name, uint8_t fType, uint32_t fLen=0);
void setRCount(uint32_t count); void setRCount(uint32_t count);
void setStartPos(uint32_t n);
void setDeleted(uint64_t n); void setDeleted(uint64_t n);
void setPresent(uint32_t n); void setEndPos(uint64_t n);
void setReady(); void setReady();
void setExit(); void setExit();
void setReload(); void setReload();