Skip to content

Commit 2cc0177

Browse files
committed
uCDB constructor, const class members moved to class decl
1 parent d08bda3 commit 2cc0177

File tree

3 files changed

+24
-29
lines changed

3 files changed

+24
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Compatible storage libraries:
1919
- official [Arduino SD](https://github.com/arduino-libraries/SD)
2020
- [Greiman SdFat](https://github.com/greiman/SdFat)
2121
- [SdFat - Adafruit fork](https://github.com/adafruit/SdFat)
22-
- [Adafruit SPIFlash](https://github.com/adafruit/Adafruit_SPIFlash)
22+
- [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).
2323

2424
Simple tracing for CDB format/integrity and run time file operation errors.
2525
```C++

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=uCDB
2-
version=0.5.3
2+
version=0.5.4
33
author=Ioulianos Kakoulidis
44
maintainer=Ioulianos Kakoulidis <ioulianos.kakoulidis@hotmail.com>
55
sentence=API for querying Constant DataBase file store.

src/uCDB.hpp

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
#define UCDB_VERSION_MAJOR 0
5252
#define UCDB_VERSION_MINOR 5
53-
#define UCDB_VERSION_PATCH 3
53+
#define UCDB_VERSION_PATCH 4
5454

5555
#ifdef TRACE_CDB
5656
#ifndef TracePrinter
@@ -85,7 +85,15 @@ template <class TFileSystem, class TFile>
8585
class uCDB
8686
{
8787
public:
88-
uCDB(TFileSystem& fs);
88+
89+
/**
90+
uCDB constructor
91+
*/
92+
uCDB(TFileSystem& fs) :
93+
fs_(fs),
94+
slotsToScan_(0),
95+
nextSlotPos_(0),
96+
state_(CDB_CLOSED) {}
8997

9098
/**
9199
Open CDB file
@@ -119,12 +127,22 @@ class uCDB
119127
/**
120128
Total records number in CDB
121129
*/
122-
unsigned long recordsNumber() const;
130+
unsigned long recordsNumber() const {
131+
switch (state_) {
132+
case CDB_CLOSED:
133+
case CDB_ERROR:
134+
return 0;
135+
default:
136+
return (slotsNum_ >> 1);
137+
}
138+
}
123139

124140
/**
125141
The number of `value' bytes available for reading
126142
*/
127-
unsigned long valueAvailable() const;
143+
unsigned long valueAvailable() const {
144+
return (state_ == KEY_FOUND ? valueBytesAvail_ : 0);
145+
}
128146

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

188-
template <class TFileSystem, class TFile>
189-
uCDB<TFileSystem, TFile>::uCDB(TFileSystem& fs) : fs_(fs) {
190-
zero();
191-
state_ = CDB_CLOSED;
192-
}
193-
194206
template <class TFileSystem, class TFile>
195207
cdbResult uCDB<TFileSystem, TFile>::open(const char *fileName, unsigned long (*userHashFunc)(const void *key, unsigned long keyLen)) {
196208
unsigned long htPos;
@@ -405,23 +417,6 @@ int uCDB<TFileSystem, TFile>::readValue(void *buff, unsigned int byteNum) {
405417
return -1;
406418
}
407419

408-
template <class TFileSystem, class TFile>
409-
unsigned long uCDB<TFileSystem, TFile>::recordsNumber() const {
410-
// Check CDB state
411-
switch (state_) {
412-
case CDB_CLOSED:
413-
case CDB_ERROR:
414-
return 0;
415-
default:
416-
return (slotsNum_ >> 1);
417-
}
418-
}
419-
420-
template <class TFileSystem, class TFile>
421-
unsigned long uCDB<TFileSystem, TFile>::valueAvailable() const {
422-
return ((state_ == KEY_FOUND) ? valueBytesAvail_ : 0);
423-
}
424-
425420
template <class TFileSystem, class TFile>
426421
cdbResult uCDB<TFileSystem, TFile>::close() {
427422
zero();

0 commit comments

Comments
 (0)