Skip to content

Commit 14c7da3

Browse files
committed
Bridge: Fixed File "duplicate definitions" when using SD and Bridge libraries together
The two File classes have been enclosed into different namespaces. To guarantee compatibility with old sketches that uses only one of the two libraries an additional line: using namespace xxxxx; has been added so the users can still use "File" where there is no ambiguity. BridgeLib::File and SDLib::File classes have been also aliased to BridgeFile and SDFile respectively, users are encouraged to use that instead of File.
1 parent e2c7761 commit 14c7da3

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
SD KEYWORD1 SD
1010
File KEYWORD1 SD
11+
SDFile KEYWORD1 SD
1112

1213
#######################################
1314
# Methods and Functions (KEYWORD2)

src/SD.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252

5353
#include "SD.h"
5454

55+
namespace SDLib {
56+
5557
// Used by `getNextPathComponent`
5658
#define MAX_COMPONENT_LEN 12 // What is max length?
5759
#define PATH_COMPONENT_BUFFER_LEN MAX_COMPONENT_LEN+1
@@ -614,3 +616,5 @@ void File::rewindDirectory(void) {
614616
}
615617

616618
SDClass SD;
619+
620+
};

src/SD.h

+16
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#define FILE_READ O_READ
2424
#define FILE_WRITE (O_READ | O_WRITE | O_CREAT)
2525

26+
namespace SDLib {
27+
2628
class File : public Stream {
2729
private:
2830
char _name[13]; // our name
@@ -104,4 +106,18 @@ class SDClass {
104106

105107
extern SDClass SD;
106108

109+
};
110+
111+
// We enclose File and SD classes in namespace SDLib to avoid conflicts
112+
// with others legacy libraries that redefines File class.
113+
114+
// This ensure compatibility with sketches that uses only SD library
115+
using namespace SDLib;
116+
117+
// This allows sketches to use SDLib::File with other libraries (in the
118+
// sketch you must use SDFile instead of File to disambiguate)
119+
typedef SDLib::File SDFile;
120+
typedef SDLib::SDClass SDFileSystemClass;
121+
#define SDFileSystem SDLib::SD
122+
107123
#endif

0 commit comments

Comments
 (0)