memory: Hide all copy/assignment ops for class w/heap allocation

Many of the UPM libraries allocate space on the heap but do not
explicitly handle copying and assignment.  This commit uses C++11 delete
to forbit both the copy and assignment operator for these classes.

The C++ examples which used assignment operators to initialize class
instances were also updated since it did not appear necessary in those
cases to use the assignment operator.

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck 2017-07-14 11:16:27 -07:00
parent f59f3131bb
commit 5e7a8b41a3
75 changed files with 264 additions and 19 deletions

View File

@ -54,8 +54,7 @@ int main(int argc, char **argv)
cout << "Using device: " << defaultDev << endl;
// Instantiate a RN2903 sensor on defaultDev at 57600 baud.
upm::RN2903 sensor = upm::RN2903(defaultDev,
RN2903_DEFAULT_BAUDRATE);
upm::RN2903 sensor (defaultDev, RN2903_DEFAULT_BAUDRATE);
// To use an internal UART understood by MRAA, use the following
// to inititialize rather than the above, which by default uses a

View File

@ -54,8 +54,7 @@ int main(int argc, char **argv)
cout << "Using device: " << defaultDev << endl;
// Instantiate a RN2903 sensor on defaultDev at 57600 baud.
upm::RN2903 sensor = upm::RN2903(defaultDev,
RN2903_DEFAULT_BAUDRATE);
upm::RN2903 sensor(defaultDev, RN2903_DEFAULT_BAUDRATE);
// To use an internal UART understood by MRAA, use the following
// to inititialize rather than the above, which by default uses a

View File

@ -42,8 +42,7 @@ int main(int argc, char **argv)
cout << "Using device: " << defaultDev << endl;
// Instantiate a RN2903 sensor on defaultDev at 57600 baud.
upm::RN2903 sensor = upm::RN2903(defaultDev,
RN2903_DEFAULT_BAUDRATE);
upm::RN2903 sensor(defaultDev, RN2903_DEFAULT_BAUDRATE);
// To use an internal UART understood by MRAA, use the following
// to inititialize rather than the above, which by default uses a

View File

@ -208,6 +208,10 @@ namespace upm {
void stepperSteps(STEPMOTORS_T motor, unsigned int steps);
private:
/* Disable implicit copy and assignment operators */
AdafruitMS1438(const AdafruitMS1438&) = delete;
AdafruitMS1438 &operator=(const AdafruitMS1438&) = delete;
// SWIG will generate a warning for these 'nested structs'; however,
// it can be ignored as these structs are never exposed.

View File

@ -156,6 +156,10 @@ class APA102
void pushState();
private:
/* Disable implicit copy and assignment operators */
APA102(const APA102&) = delete;
APA102 &operator=(const APA102&) = delete;
mraa::Spi* m_spi;
mraa::Gpio* m_csnPinCtx;

View File

@ -128,7 +128,8 @@ namespace upm {
uint16_t readData();
private:
/* Disable implicit copy and assignment operators */
BH1750(const BH1750&) = delete;
BH1750 &operator=(const BH1750&) = delete;
};
}

View File

@ -88,6 +88,10 @@ namespace upm {
bool motionDetected() { return value(); };
private:
/* Disable implicit copy and assignment operators */
BISS0001(const BISS0001&) = delete;
BISS0001 &operator=(const BISS0001&) = delete;
biss0001_context m_biss0001;
};
}

View File

@ -813,6 +813,10 @@ namespace upm {
float m_accelScale;
private:
/* Disable implicit copy and assignment operators */
BMA220(const BMA220&) = delete;
BMA220 &operator=(const BMA220&) = delete;
/**
* update the accelerometer values
*/

View File

@ -582,6 +582,10 @@ namespace upm {
bma250e_context m_bma250e;
private:
/* Disable implicit copy and assignment operators */
BMA250E(const BMA250E&) = delete;
BMA250E &operator=(const BMA250E&) = delete;
// Adding a private function definition for java bindings
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
void installISR(BMA250E_INTERRUPT_PINS_T intr, int gpio,

View File

@ -480,6 +480,10 @@ namespace upm {
bmg160_context m_bmg160;
private:
/* Disable implicit copy and assignment operators */
BMG160(const BMG160&) = delete;
BMG160 &operator=(const BMG160&) = delete;
// needs to be private for SWIG Java builds
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
void installISR(BMG160_INTERRUPT_PINS_T intr, int gpio,

View File

@ -242,5 +242,8 @@ namespace upm {
void busWrite(int addr, int reg, std::string data);
private:
/* Disable implicit copy and assignment operators */
BMI160(const BMI160&) = delete;
BMI160 &operator=(const BMI160&) = delete;
};
}

View File

@ -346,6 +346,10 @@ namespace upm {
bmm150_context m_bmm150;
private:
/* Disable implicit copy and assignment operators */
BMM150(const BMM150&) = delete;
BMM150 &operator=(const BMM150&) = delete;
// Adding a private function definition for java bindings
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
void installISR(BMM150_INTERRUPT_PINS_T intr, int gpio,

View File

@ -270,5 +270,8 @@ namespace upm {
void writeReg(uint8_t reg, uint8_t val);
private:
/* Disable implicit copy and assignment operators */
BMP280(const BMP280&) = delete;
BMP280 &operator=(const BMP280&) = delete;
};
}

View File

@ -241,6 +241,8 @@ namespace upm {
void writeReg(uint8_t reg, uint8_t val);
private:
/* Disable implicit copy and assignment operators */
BMPX8X(const BMPX8X&) = delete;
BMPX8X &operator=(const BMPX8X&) = delete;
};
}

View File

@ -193,5 +193,8 @@ namespace upm {
BMM150 *m_mag;
private:
/* Disable implicit copy and assignment operators */
BMC150(const BMC150&) = delete;
BMC150 &operator=(const BMC150&) = delete;
};
}

View File

@ -191,5 +191,8 @@ namespace upm {
BMG160 *m_gyro;
private:
/* Disable implicit copy and assignment operators */
BMI055(const BMI055&) = delete;
BMI055 &operator=(const BMI055&) = delete;
};
}

View File

@ -247,5 +247,8 @@ namespace upm {
BMM150 *m_mag;
private:
/* Disable implicit copy and assignment operators */
BMX055(const BMX055&) = delete;
BMX055 &operator=(const BMX055&) = delete;
};
}

View File

@ -675,6 +675,10 @@ namespace upm {
void writeRegs(uint8_t reg, uint8_t *buffer, int len);
private:
/* Disable implicit copy and assignment operators */
BNO055(const BNO055&) = delete;
BNO055 &operator=(const BNO055&) = delete;
// Adding a private function definition for java bindings
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
void installISR(int gpio, mraa_gpio_edge_t level,

View File

@ -118,5 +118,10 @@ namespace upm {
protected:
std::string m_name;
buzzer_context m_buzzer;
private:
/* Disable implicit copy and assignment operators */
Buzzer(const Buzzer&) = delete;
Buzzer &operator=(const Buzzer&) = delete;
};
}

View File

@ -120,6 +120,9 @@ namespace upm {
cjq4435_context m_cjq4435;
private:
/* Disable implicit copy and assignment operators */
CJQ4435(const CJQ4435&) = delete;
CJQ4435 &operator=(const CJQ4435&) = delete;
};
}

View File

@ -165,6 +165,10 @@ namespace upm {
private:
/* Disable implicit copy and assignment operators */
CWLSXXA(const CWLSXXA&) = delete;
CWLSXXA &operator=(const CWLSXXA&) = delete;
float m_aref;
float m_rResistor;
int m_aResTemp;

View File

@ -184,5 +184,8 @@ namespace upm {
dfrec_context m_dfrec;
private:
/* Disable implicit copy and assignment operators */
DFREC(const DFREC&) = delete;
DFREC &operator=(const DFREC&) = delete;
};
}

View File

@ -158,5 +158,8 @@ namespace upm {
dfrorp_context m_dfrorp;
private:
/* Disable implicit copy and assignment operators */
DFRORP(const DFRORP&) = delete;
DFRORP &operator=(const DFRORP&) = delete;
};
}

View File

@ -212,5 +212,8 @@ namespace upm {
ds18b20_context m_ds18b20;
private:
/* Disable implicit copy and assignment operators */
DS18B20(const DS18B20&) = delete;
DS18B20 &operator=(const DS18B20&) = delete;
};
}

View File

@ -234,5 +234,8 @@ namespace upm {
void write(std::string data);
private:
/* Disable implicit copy and assignment operators */
ECEZO(const ECEZO&) = delete;
ECEZO &operator=(const ECEZO&) = delete;
};
}

View File

@ -133,5 +133,8 @@ class ENC03R {
enc03r_context m_enc03r;
private:
/* Disable implicit copy and assignment operators */
ENC03R(const ENC03R&) = delete;
ENC03R &operator=(const ENC03R&) = delete;
};
}

View File

@ -114,6 +114,10 @@ namespace upm {
void setOffset(float offset);
private:
/* Disable implicit copy and assignment operators */
GUVAS12D(const GUVAS12D&) = delete;
GUVAS12D &operator=(const GUVAS12D&) = delete;
guvas12d_context m_guvas12d;
};
}

View File

@ -147,6 +147,10 @@ namespace upm {
mraa::Aio *m_aioTemp;
private:
/* Disable implicit copy and assignment operators */
HDXXVXTA(const HDXXVXTA&) = delete;
HDXXVXTA &operator=(const HDXXVXTA&) = delete;
float m_aref;
int m_aResTemp;
int m_aResHum;

View File

@ -131,5 +131,8 @@ namespace upm {
hka5_context m_hka5;
private:
/* Disable implicit copy and assignment operators */
HKA5(const HKA5&) = delete;
HKA5 &operator=(const HKA5&) = delete;
};
}

View File

@ -67,6 +67,10 @@ public:
void setBrightness(int dutyPercent);
private:
/* Disable implicit copy and assignment operators */
HLG150H(const HLG150H&) = delete;
HLG150H &operator=(const HLG150H&) = delete;
mraa::Result status;
bool isPoweredShadow;
int pinRelay;

View File

@ -252,5 +252,8 @@ namespace upm
upm_result_t data(uint8_t data);
private:
/* Disable implicit copy and assignment operators */
Jhd1313m1(const Jhd1313m1&) = delete;
Jhd1313m1 &operator=(const Jhd1313m1&) = delete;
};
}

View File

@ -267,5 +267,9 @@ namespace upm
lcdks_context m_lcdks;
private:
/* Disable implicit copy and assignment operators */
LCDKS(const LCDKS&) = delete;
LCDKS &operator=(const LCDKS&) = delete;
};
}

View File

@ -256,5 +256,8 @@ namespace upm
upm_result_t data(uint8_t data);
private:
/* Disable implicit copy and assignment operators */
Lcm1602(const Lcm1602&) = delete;
Lcm1602 &operator=(const Lcm1602&) = delete;
};
}

View File

@ -167,5 +167,8 @@ namespace upm {
light_context m_light;
private:
/* Disable implicit copy and assignment operators */
Light(const Light&) = delete;
Light &operator=(const Light&) = delete;
};
}

View File

@ -80,6 +80,10 @@ namespace upm {
bool blackDetected();
private:
/* Disable implicit copy and assignment operators */
LineFinder(const LineFinder&) = delete;
LineFinder &operator=(const LineFinder&) = delete;
linefinder_context m_linefinder;
};
}

View File

@ -312,6 +312,10 @@ namespace upm {
lis2ds12_context m_lis2ds12;
private:
/* Disable implicit copy and assignment operators */
LIS2DS12(const LIS2DS12&) = delete;
LIS2DS12 &operator=(const LIS2DS12&) = delete;
// Adding a private function definition for java bindings
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
void installISR(LIS2DS12_INTERRUPT_PINS_T intr, int gpio,

View File

@ -101,7 +101,8 @@ namespace upm {
lm35_context m_lm35;
private:
/* Disable implicit copy and assignment operators */
LM35(const LM35&) = delete;
LM35 &operator=(const LM35&) = delete;
};
}

View File

@ -65,6 +65,10 @@ public:
void setBrightness(int dutyPercent);
private:
/* Disable implicit copy and assignment operators */
LP8860(const LP8860&) = delete;
LP8860 &operator=(const LP8860&) = delete;
void i2cWriteByte(int reg, int value);
void i2cWriteBuffer(int reg, uint8_t* buf, int length);
uint8_t i2cReadByte(uint8_t reg);

View File

@ -101,6 +101,10 @@ class LPD8806 {
return m_name;
}
private:
/* Disable implicit copy and assignment operators */
LPD8806(const LPD8806&) = delete;
LPD8806 &operator=(const LPD8806&) = delete;
std::string m_name;
mraa::Spi m_spi;
mraa::Gpio m_csnPinCtx;

View File

@ -369,6 +369,10 @@ namespace upm {
void writeReg(uint8_t reg, uint8_t val);
private:
/* Disable implicit copy and assignment operators */
LSM303AGR(const LSM303AGR&) = delete;
LSM303AGR &operator=(const LSM303AGR&) = delete;
// Adding a private function definition for java bindings
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
void installISR(LSM303AGR_INTERRUPT_PINS_T intr, int gpio,

View File

@ -238,5 +238,8 @@ namespace upm {
void writeReg(uint8_t reg, uint8_t val);
private:
/* Disable implicit copy and assignment operators */
LSM303D(const LSM303D&) = delete;
LSM303D &operator=(const LSM303D&) = delete;
};
}

View File

@ -326,6 +326,10 @@ namespace upm {
lsm6ds3h_context m_lsm6ds3h;
private:
/* Disable implicit copy and assignment operators */
LSM6DS3H(const LSM6DS3H&) = delete;
LSM6DS3H &operator=(const LSM6DS3H&) = delete;
// Adding a private function definition for java bindings
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
void installISR(LSM6DS3H_INTERRUPT_PINS_T intr, int gpio,

View File

@ -343,6 +343,10 @@ namespace upm {
lsm6dsl_context m_lsm6dsl;
private:
/* Disable implicit copy and assignment operators */
LSM6DSL(const LSM6DSL&) = delete;
LSM6DSL &operator=(const LSM6DSL&) = delete;
// Adding a private function definition for java bindings
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
void installISR(LSM6DSL_INTERRUPT_PINS_T intr, int gpio,

View File

@ -134,6 +134,10 @@ class MAX44009 : public ILightSensor {
virtual const char* getModuleName() { return "max44009"; }
private:
/* Disable implicit copy and assignment operators */
MAX44009(const MAX44009&) = delete;
MAX44009 &operator=(const MAX44009&) = delete;
mraa::Result reset();
int m_maxControlAddr;

View File

@ -90,5 +90,8 @@ namespace upm {
mb704x_context m_mb704x;
private:
/* Disable implicit copy and assignment operators */
MB704X(const MB704X&) = delete;
MB704X &operator=(const MB704X&) = delete;
};
}

View File

@ -515,6 +515,10 @@ namespace upm {
void bitModify(uint8_t addr, uint8_t mask, uint8_t value);
private:
/* Disable implicit copy and assignment operators */
MCP2515(const MCP2515&) = delete;
MCP2515 &operator=(const MCP2515&) = delete;
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
void installISR(int pin, void (*isr)(void *), void *arg);
#endif

View File

@ -314,6 +314,10 @@ namespace upm {
uint16_t getDevicedId();
private:
/* Disable implicit copy and assignment operators */
MCP9808(const MCP9808&) = delete;
MCP9808 &operator=(const MCP9808&) = delete;
std::string m_name;
bool m_celsius;
bool m_tcrit;

View File

@ -182,6 +182,11 @@ namespace upm {
protected:
md_context m_md;
private:
/* Disable implicit copy and assignment operators */
MD(const MD&) = delete;
MD &operator=(const MD&) = delete;
};
}

View File

@ -117,6 +117,10 @@ namespace upm {
}
private:
/* Disable implicit copy and assignment operators */
MICSV89(const MICSV89&) = delete;
MICSV89 &operator=(const MICSV89&) = delete;
std::string m_name;
bool m_valid;
uint8_t m_address;

View File

@ -202,6 +202,9 @@ namespace upm {
mma7361_context m_mma7361;
private:
/* Disable implicit copy and assignment operators */
MMA7361(const MMA7361&) = delete;
MMA7361 &operator=(const MMA7361&) = delete;
};
}

View File

@ -247,6 +247,10 @@ namespace upm {
mma7660_context m_mma7660;
private:
/* Disable implicit copy and assignment operators */
MMA7660(const MMA7660&) = delete;
MMA7660 &operator=(const MMA7660&) = delete;
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
void installISR(int pin, void (*isr)(void *), void *arg);
#endif

View File

@ -932,6 +932,10 @@ namespace upm {
float m_gyroScale;
private:
/* Disable implicit copy and assignment operators */
MPU60X0(const MPU60X0&) = delete;
MPU60X0 &operator=(const MPU60X0&) = delete;
mraa::I2c m_i2c;
uint8_t m_addr;

View File

@ -126,6 +126,10 @@ namespace upm {
private:
/* Disable implicit copy and assignment operators */
MPU9150(const MPU9150&) = delete;
MPU9150 &operator=(const MPU9150&) = delete;
int m_i2cBus;
uint8_t m_magAddress;
bool m_enableAk8975;

View File

@ -74,6 +74,10 @@ public:
int getPressurePa();
private:
/* Disable implicit copy and assignment operators */
MS5611(const MS5611&) = delete;
MS5611 &operator=(const MS5611&) = delete;
int promCrc4();
uint32_t readADC(int adcReg);
void delayms(int millisecs);

View File

@ -179,5 +179,8 @@ namespace upm {
void busWrite(int cmd, std::string data);
private:
/* Disable implicit copy and assignment operators */
MS5803(const MS5803&) = delete;
MS5803 &operator=(const MS5803&) = delete;
};
}

View File

@ -125,6 +125,9 @@ namespace upm {
my9221_context m_my9221;
private:
/* Disable implicit copy and assignment operators */
MY9221(const MY9221&) = delete;
MY9221 &operator=(const MY9221&) = delete;
};
}

View File

@ -146,6 +146,9 @@ namespace upm {
nmea_gps_context m_nmea_gps;
private:
/* Disable implicit copy and assignment operators */
NMEAGPS(const NMEAGPS&) = delete;
NMEAGPS &operator=(const NMEAGPS&) = delete;
};
}

View File

@ -124,10 +124,11 @@ namespace upm {
bool buttonZ;
protected:
nunchuck_context m_nunchuck;
nunchuck_context m_nunchuck;
private:
/* Disable implicit copy and assignment operators */
NUNCHUCK(const NUNCHUCK&) = delete;
NUNCHUCK &operator=(const NUNCHUCK&) = delete;
};
}

View File

@ -166,6 +166,11 @@ namespace upm {
protected:
otp538u_context m_otp538u;
private:
/* Disable implicit copy and assignment operators */
OTP538U(const OTP538U&) = delete;
OTP538U &operator=(const OTP538U&) = delete;
};
}

View File

@ -75,6 +75,10 @@ namespace upm {
ppd42ns_dust_data getData();
private:
/* Disable implicit copy and assignment operators */
PPD42NS(const PPD42NS&) = delete;
PPD42NS &operator=(const PPD42NS&) = delete;
ppd42ns_context m_ppd42ns;
};
}

View File

@ -632,5 +632,8 @@ namespace upm {
int write(std::string buffer);
private:
/* Disable implicit copy and assignment operators */
RN2903(const RN2903&) = delete;
RN2903 &operator=(const RN2903&) = delete;
};
}

View File

@ -88,6 +88,10 @@ namespace upm {
int position();
private:
/* Disable implicit copy and assignment operators */
RotaryEncoder(const RotaryEncoder&) = delete;
RotaryEncoder &operator=(const RotaryEncoder&) = delete;
rotaryencoder_context m_rotaryencoder;
};
}

View File

@ -104,6 +104,10 @@ namespace upm {
void uninstallISR();
private:
/* Disable implicit copy and assignment operators */
RPR220(const RPR220&) = delete;
RPR220 &operator=(const RPR220&) = delete;
rpr220_context m_rpr220;
#if defined(SWIGJAVA) || defined(JAVACALLBACK)

View File

@ -180,5 +180,8 @@ namespace upm {
upm_result_t write8Bits(uint8_t byte);
private:
/* Disable implicit copy and assignment operators */
SHT1X(const SHT1X&) = delete;
SHT1X &operator=(const SHT1X&) = delete;
};
}

View File

@ -83,6 +83,10 @@ class SI1132 : public ILightSensor {
virtual const char* getModuleName() { return "si1132"; }
private:
/* Disable implicit copy and assignment operators */
SI1132(const SI1132&) = delete;
SI1132 &operator=(const SI1132&) = delete;
mraa::Result reset();
mraa::Result clearResponseRegister();
mraa::Result runCommand(uint8_t command);

View File

@ -125,6 +125,10 @@ class SI7005 : public ITemperatureSensor, public IHumiditySensor {
void disableFastConversionMode();
private:
/* Disable implicit copy and assignment operators */
SI7005(const SI7005&) = delete;
SI7005 &operator=(const SI7005&) = delete;
int m_controlAddr;
int m_bus;
int m_pin;

View File

@ -145,5 +145,8 @@ namespace upm {
speaker_context m_speaker;
private:
/* Disable implicit copy and assignment operators */
Speaker(const Speaker&) = delete;
Speaker &operator=(const Speaker&) = delete;
};
}

View File

@ -154,6 +154,10 @@ class StepMotor {
int getStep ();
private:
/* Disable implicit copy and assignment operators */
StepMotor(const StepMotor&) = delete;
StepMotor &operator=(const StepMotor&) = delete;
std::string m_name;
mraa::Gpio m_dirPinCtx;

View File

@ -174,6 +174,10 @@ namespace upm {
void enableAllPorts();
private:
/* Disable implicit copy and assignment operators */
TCA9548A(const TCA9548A&) = delete;
TCA9548A &operator=(const TCA9548A&) = delete;
std::string m_name;
mraa::I2c* i2c;

View File

@ -257,5 +257,8 @@ namespace upm {
uartat_context m_uartat;
private:
/* Disable implicit copy and assignment operators */
UARTAT(const UARTAT&) = delete;
UARTAT &operator=(const UARTAT&) = delete;
};
}

View File

@ -106,10 +106,11 @@ namespace upm {
void release();
protected:
uln200xa_context m_uln200xa;
uln200xa_context m_uln200xa;
private:
/* Disable implicit copy and assignment operators */
ULN200XA(const ULN200XA&) = delete;
ULN200XA &operator=(const ULN200XA&) = delete;
};
}

View File

@ -152,7 +152,8 @@ namespace upm {
urm37_context m_urm37;
private:
/* Disable implicit copy and assignment operators */
URM37(const URM37&) = delete;
URM37 &operator=(const URM37&) = delete;
};
}

View File

@ -69,6 +69,10 @@ namespace upm {
bool isWet();
private:
/* Disable implicit copy and assignment operators */
Water(const Water&) = delete;
Water &operator=(const Water&) = delete;
water_context m_water;
};
}

View File

@ -129,5 +129,8 @@ class WFS {
wfs_context m_wfs;
private:
/* Disable implicit copy and assignment operators */
WFS(const WFS&) = delete;
WFS &operator=(const WFS&) = delete;
};
}

View File

@ -76,6 +76,10 @@ namespace upm {
bool flameDetected();
private:
/* Disable implicit copy and assignment operators */
YG1006(const YG1006&) = delete;
YG1006 &operator=(const YG1006&) = delete;
yg1006_context m_yg1006;
};
}