Skip to content

Commit fc0c12d

Browse files
committed
Encapsulate everything in namespace arduino
This will help integrating with other C++ frameworks declaring the same classes (String/Serial/...)
1 parent 398e70f commit fc0c12d

20 files changed

+83
-25
lines changed

Diff for: api/Client.h

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "Stream.h"
2323
#include "IPAddress.h"
2424

25+
namespace arduino {
26+
2527
class Client : public Stream {
2628

2729
public:
@@ -41,3 +43,4 @@ class Client : public Stream {
4143
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
4244
};
4345

46+
}

Diff for: api/HardwareI2C.h

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <inttypes.h>
2222
#include "Stream.h"
2323

24+
namespace arduino {
25+
2426
class HardwareI2C : public Stream
2527
{
2628
public:
@@ -41,3 +43,5 @@ class HardwareI2C : public Stream
4143
virtual void onRequest(void(*)(void)) = 0;
4244
};
4345

46+
}
47+

Diff for: api/HardwareSerial.h

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <inttypes.h>
2222
#include "Stream.h"
2323

24+
namespace arduino {
25+
2426
// XXX: Those constants should be defined as const int / enums?
2527
// XXX: shall we use namespaces too?
2628
#define SERIAL_PARITY_EVEN (0x1ul)
@@ -100,3 +102,4 @@ class HardwareSerial : public Stream
100102
// XXX: Are we keeping the serialEvent API?
101103
extern void serialEventRun(void) __attribute__((weak));
102104

105+
}

Diff for: api/IPAddress.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "IPAddress.h"
2121
#include "Print.h"
2222

23+
using namespace arduino;
24+
2325
IPAddress::IPAddress()
2426
{
2527
_address.dword = 0;

Diff for: api/IPAddress.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "Printable.h"
2424
#include "String.h"
2525

26+
namespace arduino {
27+
2628
// A class to make it easier to handle and pass around IP addresses
2729

2830
class IPAddress : public Printable {
@@ -74,4 +76,4 @@ class IPAddress : public Printable {
7476
};
7577

7678
extern const IPAddress INADDR_NONE;
77-
79+
}

Diff for: api/Interrupts.h

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <stdint.h>
88
#include "Common.h"
99

10+
namespace arduino {
11+
1012
template <typename T>
1113
using voidTemplateFuncPtrParam = void (*)(T param);
1214

@@ -37,5 +39,6 @@ template<typename T> void attachInterrupt(pin_size_t interruptNum, voidTemplateF
3739
attachInterruptParam(interruptNum, (voidFuncPtrParam)userFunc, mode, (void*)param);
3840
}
3941

42+
}
4043
#endif
4144
#endif

Diff for: api/PluggableUSB.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "USBAPI.h"
2121
#include "PluggableUSB.h"
2222

23+
using namespace arduino;
24+
2325
int PluggableUSB_::getInterface(uint8_t* interfaceCount)
2426
{
2527
int sent = 0;

Diff for: api/PluggableUSB.h

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <stdint.h>
2525
#include <stddef.h>
2626

27+
namespace arduino {
28+
2729
// core need to define
2830
void* epBuffer(unsigned int n); // -> returns a poointer to the Nth element of the EP buffer structure
2931

@@ -72,4 +74,6 @@ class PluggableUSB_ {
7274
// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use
7375
PluggableUSB_& PluggableUSB();
7476

77+
}
78+
7579
#endif

Diff for: api/Print.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include "Print.h"
2525

26+
using namespace arduino;
27+
2628
// Public Methods //////////////////////////////////////////////////////////////
2729

2830
/* default implementation: may be overridden */

Diff for: api/Print.h

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#define OCT 8
3030
#define BIN 2
3131

32+
namespace arduino {
33+
3234
class Print
3335
{
3436
private:
@@ -90,3 +92,4 @@ class Print
9092
virtual void flush() { /* Empty implementation for backward compatibility */ }
9193
};
9294

95+
}

Diff for: api/Printable.h

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include <stdlib.h>
2222

23+
namespace arduino {
24+
2325
class Print;
2426

2527
/** The Printable class provides a way for new classes to allow themselves to be printed.
@@ -34,3 +36,4 @@ class Printable
3436
virtual size_t printTo(Print& p) const = 0;
3537
};
3638

39+
}

Diff for: api/RingBuffer.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include <stdint.h>
2525

26+
namespace arduino {
27+
2628
// Define constants and variables for buffering incoming serial data. We're
2729
// using a ring buffer (I think), in which head is the index of the location
2830
// to which to write the next incoming character and tail is the index of the
@@ -137,6 +139,7 @@ bool RingBufferN<N>::isFull()
137139
return (nextIndex(_iHead) == _iTail);
138140
}
139141

140-
#endif /* _RING_BUFFER_ */
142+
}
141143

144+
#endif /* _RING_BUFFER_ */
142145
#endif /* __cplusplus */

Diff for: api/Server.h

+3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121

2222
#include "Print.h"
2323

24+
namespace arduino {
25+
2426
class Server : public Print {
2527
public:
2628
virtual void begin() = 0;
2729
};
2830

31+
}

Diff for: api/Stream.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait
2929

30+
using namespace arduino;
31+
3032
// private method to read stream with timeout
3133
int Stream::timedRead()
3234
{

Diff for: api/Stream.h

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
readBytesBetween( pre_string, terminator, buffer, length)
3535
*/
3636

37+
namespace arduino {
38+
3739
// This enumeration provides the lookahead options for parseInt(), parseFloat()
3840
// The rules set out here are used until either the first valid character is found
3941
// or a time out occurs due to lack of input.
@@ -125,3 +127,5 @@ class Stream : public Print
125127
};
126128

127129
#undef NO_IGNORE_CHAR
130+
131+
}

Diff for: api/String.cpp

+13-11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
/* Constructors */
2828
/*********************************************/
2929

30+
using namespace arduino;
31+
3032
String::String(const char *cstr)
3133
{
3234
init();
@@ -352,77 +354,77 @@ unsigned char String::concat(const __FlashStringHelper * str)
352354
/* Concatenate */
353355
/*********************************************/
354356

355-
StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs)
357+
StringSumHelper & arduino::operator + (const StringSumHelper &lhs, const String &rhs)
356358
{
357359
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
358360
if (!a.concat(rhs.buffer, rhs.len)) a.invalidate();
359361
return a;
360362
}
361363

362-
StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr)
364+
StringSumHelper & arduino::operator + (const StringSumHelper &lhs, const char *cstr)
363365
{
364366
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
365367
if (!cstr || !a.concat(cstr, strlen(cstr))) a.invalidate();
366368
return a;
367369
}
368370

369-
StringSumHelper & operator + (const StringSumHelper &lhs, char c)
371+
StringSumHelper & arduino::operator + (const StringSumHelper &lhs, char c)
370372
{
371373
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
372374
if (!a.concat(c)) a.invalidate();
373375
return a;
374376
}
375377

376-
StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num)
378+
StringSumHelper & arduino::operator + (const StringSumHelper &lhs, unsigned char num)
377379
{
378380
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
379381
if (!a.concat(num)) a.invalidate();
380382
return a;
381383
}
382384

383-
StringSumHelper & operator + (const StringSumHelper &lhs, int num)
385+
StringSumHelper & arduino::operator + (const StringSumHelper &lhs, int num)
384386
{
385387
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
386388
if (!a.concat(num)) a.invalidate();
387389
return a;
388390
}
389391

390-
StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num)
392+
StringSumHelper & arduino::operator + (const StringSumHelper &lhs, unsigned int num)
391393
{
392394
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
393395
if (!a.concat(num)) a.invalidate();
394396
return a;
395397
}
396398

397-
StringSumHelper & operator + (const StringSumHelper &lhs, long num)
399+
StringSumHelper & arduino::operator + (const StringSumHelper &lhs, long num)
398400
{
399401
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
400402
if (!a.concat(num)) a.invalidate();
401403
return a;
402404
}
403405

404-
StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num)
406+
StringSumHelper & arduino::operator + (const StringSumHelper &lhs, unsigned long num)
405407
{
406408
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
407409
if (!a.concat(num)) a.invalidate();
408410
return a;
409411
}
410412

411-
StringSumHelper & operator + (const StringSumHelper &lhs, float num)
413+
StringSumHelper & arduino::operator + (const StringSumHelper &lhs, float num)
412414
{
413415
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
414416
if (!a.concat(num)) a.invalidate();
415417
return a;
416418
}
417419

418-
StringSumHelper & operator + (const StringSumHelper &lhs, double num)
420+
StringSumHelper & arduino::operator + (const StringSumHelper &lhs, double num)
419421
{
420422
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
421423
if (!a.concat(num)) a.invalidate();
422424
return a;
423425
}
424426

425-
StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs)
427+
StringSumHelper & arduino::operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs)
426428
{
427429
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
428430
if (!a.concat(rhs)) a.invalidate();

Diff for: api/String.h

+17-12
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2020
*/
2121

22-
#pragma once
23-
2422
#ifdef __cplusplus
2523

24+
#ifndef __ARDUINO_STRINGS__
25+
#define __ARDUINO_STRINGS__
26+
2627
#include <stdlib.h>
2728
#include <string.h>
2829
#include <ctype.h>
@@ -32,6 +33,7 @@
3233
#include "deprecated-avr-comp/avr/pgmspace.h"
3334
#endif
3435

36+
namespace arduino {
3537
// When compiling programs with this class, the following gcc parameters
3638
// dramatically increase performance and memory (RAM) efficiency, typically
3739
// with little or no increase in code size.
@@ -48,6 +50,7 @@ class StringSumHelper;
4850
// The string class
4951
class String
5052
{
53+
friend class StringSumHelper;
5154
// use a function pointer to allow for "if (s)" without the
5255
// complications of an operator bool(). for more information, see:
5356
// http://www.artima.com/cppsource/safebool.html
@@ -231,16 +234,18 @@ class String
231234
class StringSumHelper : public String
232235
{
233236
public:
234-
StringSumHelper(const String &s) : String(s) {}
235-
StringSumHelper(const char *p) : String(p) {}
236-
StringSumHelper(char c) : String(c) {}
237-
StringSumHelper(unsigned char num) : String(num) {}
238-
StringSumHelper(int num) : String(num) {}
239-
StringSumHelper(unsigned int num) : String(num) {}
240-
StringSumHelper(long num) : String(num) {}
241-
StringSumHelper(unsigned long num) : String(num) {}
242-
StringSumHelper(float num) : String(num) {}
243-
StringSumHelper(double num) : String(num) {}
237+
StringSumHelper(const String &s) : String(s) {}
238+
StringSumHelper(const char *p) : String(p) {}
239+
StringSumHelper(char c) : String(c) {}
240+
StringSumHelper(unsigned char num) : String(num) {}
241+
StringSumHelper(int num) : String(num) {}
242+
StringSumHelper(unsigned int num) : String(num) {}
243+
StringSumHelper(long num) : String(num) {}
244+
StringSumHelper(unsigned long num) : String(num) {}
245+
StringSumHelper(float num) : String(num) {}
246+
StringSumHelper(double num) : String(num) {}
244247
};
245248

249+
}
246250
#endif // __cplusplus
251+
#endif // __ARDUINO_STRINGS__

Diff for: api/USBAPI.h

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <stdint.h>
2424

25+
namespace arduino {
2526
//================================================================================
2627
//================================================================================
2728
// Low level API
@@ -57,4 +58,5 @@ int USB_Recv(uint8_t ep, void* data, int len); // non-blocking
5758
int USB_Recv(uint8_t ep); // non-blocking
5859
void USB_Flush(uint8_t ep);
5960

61+
}
6062
#endif

Diff for: api/Udp.h

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include "Stream.h"
3838
#include "IPAddress.h"
3939

40+
namespace arduino {
41+
4042
class UDP : public Stream {
4143

4244
public:
@@ -84,3 +86,4 @@ class UDP : public Stream {
8486
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
8587
};
8688

89+
}

0 commit comments

Comments
 (0)