Skip to content

Commit

Permalink
uCDB constructor, const class members moved to class decl
Browse files Browse the repository at this point in the history
  • Loading branch information
JulStrat committed Jan 26, 2022
1 parent d08bda3 commit 2cc0177
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Compatible storage libraries:
- official [Arduino SD](https://github.com/arduino-libraries/SD)
- [Greiman SdFat](https://github.com/greiman/SdFat)
- [SdFat - Adafruit fork](https://github.com/adafruit/SdFat)
- [Adafruit SPIFlash](https://github.com/adafruit/Adafruit_SPIFlash)
- [Adafruit SPIFlash](https://github.com/adafruit/Adafruit_SPIFlash), real usage :airplane:[SoftRF](https://github.com/lyusupov/SoftRF/blob/master/software/firmware/source/SoftRF/src/platform/nRF52.cpp).

Simple tracing for CDB format/integrity and run time file operation errors.
```C++
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=uCDB
version=0.5.3
version=0.5.4
author=Ioulianos Kakoulidis
maintainer=Ioulianos Kakoulidis <[email protected]>
sentence=API for querying Constant DataBase file store.
Expand Down
49 changes: 22 additions & 27 deletions src/uCDB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

#define UCDB_VERSION_MAJOR 0
#define UCDB_VERSION_MINOR 5
#define UCDB_VERSION_PATCH 3
#define UCDB_VERSION_PATCH 4

#ifdef TRACE_CDB
#ifndef TracePrinter
Expand Down Expand Up @@ -85,7 +85,15 @@ template <class TFileSystem, class TFile>
class uCDB
{
public:
uCDB(TFileSystem& fs);

/**
uCDB constructor
*/
uCDB(TFileSystem& fs) :
fs_(fs),
slotsToScan_(0),
nextSlotPos_(0),
state_(CDB_CLOSED) {}

/**
Open CDB file
Expand Down Expand Up @@ -119,12 +127,22 @@ class uCDB
/**
Total records number in CDB
*/
unsigned long recordsNumber() const;
unsigned long recordsNumber() const {
switch (state_) {
case CDB_CLOSED:
case CDB_ERROR:
return 0;
default:
return (slotsNum_ >> 1);
}
}

/**
The number of `value' bytes available for reading
*/
unsigned long valueAvailable() const;
unsigned long valueAvailable() const {
return (state_ == KEY_FOUND ? valueBytesAvail_ : 0);
}

/**
Close CDB
Expand Down Expand Up @@ -185,12 +203,6 @@ static unsigned long unpack(const byte *buff);
template <class TFile>
static bool readDescriptor(TFile& file, byte *buff, unsigned long pos);

template <class TFileSystem, class TFile>
uCDB<TFileSystem, TFile>::uCDB(TFileSystem& fs) : fs_(fs) {
zero();
state_ = CDB_CLOSED;
}

template <class TFileSystem, class TFile>
cdbResult uCDB<TFileSystem, TFile>::open(const char *fileName, unsigned long (*userHashFunc)(const void *key, unsigned long keyLen)) {
unsigned long htPos;
Expand Down Expand Up @@ -405,23 +417,6 @@ int uCDB<TFileSystem, TFile>::readValue(void *buff, unsigned int byteNum) {
return -1;
}

template <class TFileSystem, class TFile>
unsigned long uCDB<TFileSystem, TFile>::recordsNumber() const {
// Check CDB state
switch (state_) {
case CDB_CLOSED:
case CDB_ERROR:
return 0;
default:
return (slotsNum_ >> 1);
}
}

template <class TFileSystem, class TFile>
unsigned long uCDB<TFileSystem, TFile>::valueAvailable() const {
return ((state_ == KEY_FOUND) ? valueBytesAvail_ : 0);
}

template <class TFileSystem, class TFile>
cdbResult uCDB<TFileSystem, TFile>::close() {
zero();
Expand Down

0 comments on commit 2cc0177

Please sign in to comment.