* 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.
pull/808/head
Przemek Wirkus 2015-01-06 08:32:16 +00:00
parent 32cea97577
commit 7d54c82331
6 changed files with 15 additions and 12 deletions

View File

@ -77,7 +77,7 @@ public:
/** Access to particular bit in random-iterator fashion
*/
DigitalIn & operator[] (unsigned int index);
DigitalIn & operator[] (int index);
#endif
protected:

View File

@ -90,6 +90,10 @@ public:
BusInOut& operator= (int v);
BusInOut& operator= (BusInOut& rhs);
/** Access to particular bit in random-iterator fashion
*/
DigitalInOut& operator[] (int index);
/** A shorthand for read()
*/
operator int();
@ -108,7 +112,6 @@ protected:
private:
BusInOut(const BusInOut&);
BusInOut & operator = (const BusInOut&);
DigitalInOut& operator[] (unsigned int index);
};
} // namespace mbed

View File

@ -76,7 +76,7 @@ public:
/** Access to particular bit in random-iterator fashion
*/
DigitalOut& operator[] (unsigned int index);
DigitalOut& operator[] (int index);
/** A shorthand for read()
*/

View File

@ -72,9 +72,9 @@ BusIn::operator int() {
return read();
}
DigitalIn& BusIn::operator[] (unsigned int index) {
//MBED_ASSERT(index >= MBED_BUS_SIZE);
//MBED_ASSERT(_pin[index]);
DigitalIn& BusIn::operator[] (int index) {
MBED_ASSERT(index < 0 || index >= MBED_BUS_SIZE);
MBED_ASSERT(_pin[index]);
if (index >= 16 || _pin[index] == NULL) {
return din_dummy;
}

View File

@ -102,9 +102,9 @@ BusInOut& BusInOut::operator= (BusInOut& rhs) {
return *this;
}
DigitalInOut& BusInOut::operator[] (unsigned int index) {
//MBED_ASSERT(index >= MBED_BUS_SIZE);
//MBED_ASSERT(_pin[index]);
DigitalInOut& BusInOut::operator[] (int index) {
MBED_ASSERT(index < 0 || index >= MBED_BUS_SIZE);
MBED_ASSERT(_pin[index]);
if (index >= 16 || _pin[index] == NULL) {
return dinout_dummy;
}

View File

@ -78,9 +78,9 @@ BusOut& BusOut::operator= (BusOut& rhs) {
return *this;
}
DigitalOut& BusOut::operator[] (unsigned int index) {
//MBED_ASSERT(index >= MBED_BUS_SIZE);
//MBED_ASSERT(_pin[index]);
DigitalOut& BusOut::operator[] (int index) {
MBED_ASSERT(index < 0 || index >= MBED_BUS_SIZE);
MBED_ASSERT(_pin[index]);
if (index >= 16 || _pin[index] == NULL) {
return dout_dummy;
}