Skip to content

Commit 7d54c82

Browse files
committed
* Changed Bus operator[]() parameter from unsigned int to int to match mbed code
guidelines. * Uncommented assertions in operators and added check for operator[] index < 0. * Moved one operator from private to public, this was a typo thing.
1 parent 32cea97 commit 7d54c82

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

libraries/mbed/api/BusIn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class BusIn {
7777

7878
/** Access to particular bit in random-iterator fashion
7979
*/
80-
DigitalIn & operator[] (unsigned int index);
80+
DigitalIn & operator[] (int index);
8181
#endif
8282

8383
protected:

libraries/mbed/api/BusInOut.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ class BusInOut {
9090
BusInOut& operator= (int v);
9191
BusInOut& operator= (BusInOut& rhs);
9292

93+
/** Access to particular bit in random-iterator fashion
94+
*/
95+
DigitalInOut& operator[] (int index);
96+
9397
/** A shorthand for read()
9498
*/
9599
operator int();
@@ -108,7 +112,6 @@ class BusInOut {
108112
private:
109113
BusInOut(const BusInOut&);
110114
BusInOut & operator = (const BusInOut&);
111-
DigitalInOut& operator[] (unsigned int index);
112115
};
113116

114117
} // namespace mbed

libraries/mbed/api/BusOut.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class BusOut {
7676

7777
/** Access to particular bit in random-iterator fashion
7878
*/
79-
DigitalOut& operator[] (unsigned int index);
79+
DigitalOut& operator[] (int index);
8080

8181
/** A shorthand for read()
8282
*/

libraries/mbed/common/BusIn.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ BusIn::operator int() {
7272
return read();
7373
}
7474

75-
DigitalIn& BusIn::operator[] (unsigned int index) {
76-
//MBED_ASSERT(index >= MBED_BUS_SIZE);
77-
//MBED_ASSERT(_pin[index]);
75+
DigitalIn& BusIn::operator[] (int index) {
76+
MBED_ASSERT(index < 0 || index >= MBED_BUS_SIZE);
77+
MBED_ASSERT(_pin[index]);
7878
if (index >= 16 || _pin[index] == NULL) {
7979
return din_dummy;
8080
}

libraries/mbed/common/BusInOut.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ BusInOut& BusInOut::operator= (BusInOut& rhs) {
102102
return *this;
103103
}
104104

105-
DigitalInOut& BusInOut::operator[] (unsigned int index) {
106-
//MBED_ASSERT(index >= MBED_BUS_SIZE);
107-
//MBED_ASSERT(_pin[index]);
105+
DigitalInOut& BusInOut::operator[] (int index) {
106+
MBED_ASSERT(index < 0 || index >= MBED_BUS_SIZE);
107+
MBED_ASSERT(_pin[index]);
108108
if (index >= 16 || _pin[index] == NULL) {
109109
return dinout_dummy;
110110
}

libraries/mbed/common/BusOut.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ BusOut& BusOut::operator= (BusOut& rhs) {
7878
return *this;
7979
}
8080

81-
DigitalOut& BusOut::operator[] (unsigned int index) {
82-
//MBED_ASSERT(index >= MBED_BUS_SIZE);
83-
//MBED_ASSERT(_pin[index]);
81+
DigitalOut& BusOut::operator[] (int index) {
82+
MBED_ASSERT(index < 0 || index >= MBED_BUS_SIZE);
83+
MBED_ASSERT(_pin[index]);
8484
if (index >= 16 || _pin[index] == NULL) {
8585
return dout_dummy;
8686
}

0 commit comments

Comments
 (0)