mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-29 10:24:12 +01:00
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.
This commit is contained in:
parent
36c2216dd6
commit
954f59d9ce
@ -42,6 +42,7 @@ connected KEYWORD2
|
|||||||
|
|
||||||
# FileIO Class
|
# FileIO Class
|
||||||
File KEYWORD2
|
File KEYWORD2
|
||||||
|
BridgeFile KEYWORD2
|
||||||
seek KEYWORD2
|
seek KEYWORD2
|
||||||
position KEYWORD2
|
position KEYWORD2
|
||||||
size KEYWORD2
|
size KEYWORD2
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=Bridge
|
name=Bridge
|
||||||
version=1.0.7
|
version=1.1.0
|
||||||
author=Arduino
|
author=Arduino
|
||||||
maintainer=Arduino <info@arduino.cc>
|
maintainer=Arduino <info@arduino.cc>
|
||||||
sentence=Enables the communication between the Linux processor and the AVR. For Arduino Yún and TRE only.
|
sentence=Enables the communication between the Linux processor and the AVR. For Arduino Yún and TRE only.
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#include <FileIO.h>
|
#include <FileIO.h>
|
||||||
|
|
||||||
|
namespace BridgeLib {
|
||||||
|
|
||||||
File::File(BridgeClass &b) : mode(255), bridge(b) {
|
File::File(BridgeClass &b) : mode(255), bridge(b) {
|
||||||
// Empty
|
// Empty
|
||||||
@ -279,3 +279,5 @@ boolean FileSystemClass::rmdir(const char *filepath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FileSystemClass FileSystem;
|
FileSystemClass FileSystem;
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
#define FILE_WRITE 1
|
#define FILE_WRITE 1
|
||||||
#define FILE_APPEND 2
|
#define FILE_APPEND 2
|
||||||
|
|
||||||
|
namespace BridgeLib {
|
||||||
|
|
||||||
class File : public Stream {
|
class File : public Stream {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -100,4 +102,19 @@ class FileSystemClass {
|
|||||||
|
|
||||||
extern FileSystemClass FileSystem;
|
extern FileSystemClass FileSystem;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// We enclose File and FileSystem classes in namespace BridgeLib to avoid
|
||||||
|
// conflicts with legacy SD library.
|
||||||
|
|
||||||
|
// This ensure compatibility with older sketches that uses only Bridge lib
|
||||||
|
// (the user can still use File instead of BridgeFile)
|
||||||
|
using namespace BridgeLib;
|
||||||
|
|
||||||
|
// This allows sketches to use BridgeLib::File together with SD library
|
||||||
|
// (you must use BridgeFile instead of File when needed to disambiguate)
|
||||||
|
typedef BridgeLib::File BridgeFile;
|
||||||
|
typedef BridgeLib::FileSystemClass BridgeFileSystemClass;
|
||||||
|
#define BridgeFileSystem BridgeLib::FileSystem
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
SD KEYWORD1 SD
|
SD KEYWORD1 SD
|
||||||
File KEYWORD1 SD
|
File KEYWORD1 SD
|
||||||
|
SDFile KEYWORD1 SD
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# Methods and Functions (KEYWORD2)
|
# Methods and Functions (KEYWORD2)
|
||||||
|
@ -52,6 +52,8 @@
|
|||||||
|
|
||||||
#include "SD.h"
|
#include "SD.h"
|
||||||
|
|
||||||
|
namespace SDLib {
|
||||||
|
|
||||||
// Used by `getNextPathComponent`
|
// Used by `getNextPathComponent`
|
||||||
#define MAX_COMPONENT_LEN 12 // What is max length?
|
#define MAX_COMPONENT_LEN 12 // What is max length?
|
||||||
#define PATH_COMPONENT_BUFFER_LEN MAX_COMPONENT_LEN+1
|
#define PATH_COMPONENT_BUFFER_LEN MAX_COMPONENT_LEN+1
|
||||||
@ -614,3 +616,5 @@ void File::rewindDirectory(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDClass SD;
|
SDClass SD;
|
||||||
|
|
||||||
|
};
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
#define FILE_READ O_READ
|
#define FILE_READ O_READ
|
||||||
#define FILE_WRITE (O_READ | O_WRITE | O_CREAT)
|
#define FILE_WRITE (O_READ | O_WRITE | O_CREAT)
|
||||||
|
|
||||||
|
namespace SDLib {
|
||||||
|
|
||||||
class File : public Stream {
|
class File : public Stream {
|
||||||
private:
|
private:
|
||||||
char _name[13]; // our name
|
char _name[13]; // our name
|
||||||
@ -104,4 +106,18 @@ private:
|
|||||||
|
|
||||||
extern SDClass SD;
|
extern SDClass SD;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// We enclose File and SD classes in namespace SDLib to avoid conflicts
|
||||||
|
// with others legacy libraries that redefines File class.
|
||||||
|
|
||||||
|
// This ensure compatibility with sketches that uses only SD library
|
||||||
|
using namespace SDLib;
|
||||||
|
|
||||||
|
// This allows sketches to use SDLib::File with other libraries (in the
|
||||||
|
// sketch you must use SDFile instead of File to disambiguate)
|
||||||
|
typedef SDLib::File SDFile;
|
||||||
|
typedef SDLib::SDClass SDFileSystemClass;
|
||||||
|
#define SDFileSystem SDLib::SD
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user