Skip to content

Commit

Permalink
Merge pull request #1738 from drdanz/const_sinkhole
Browse files Browse the repository at this point in the history
Improve const correctness
  • Loading branch information
drdanz authored Jun 8, 2018
2 parents a6a49f0 + 11fb427 commit e709b46
Show file tree
Hide file tree
Showing 409 changed files with 1,803 additions and 1,692 deletions.
2 changes: 1 addition & 1 deletion bindings/yarp.i
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
#ifdef SWIGJAVA
%rename(wait_c) *::wait();
%rename(clone_c) *::clone() const;
%rename(toString_c) *::toString();
%rename(toString_c) *::toString() const;
#endif

#ifdef SWIGCHICKEN
Expand Down
7 changes: 7 additions & 0 deletions doc/release/v3_0_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ Important Changes
Note that `RateThread` used the period in msec(int), `PeriodicThread`
requires the period in sec(double), so remember to consider a x1000 factor
when migrate the code.
* Several methods in public interfaces have a slightly different signature (see
#1738 for details).
* It is now possible to write a `const Portable` on a `Port`.
* `const Bytes` and `const ManagedBytes` can no longer return non-const pointers
to the underlying data.

#### `YARP_dev`

Expand Down Expand Up @@ -182,6 +187,8 @@ Important Changes
`IPositionDirect::setPositions(const int, const int*, const double*)`(#1351).
* The file `yarp/dev/ControlBoardInterfacesImpl.inl` was renamed
`yarp/dev/ControlBoardInterfacesImpl-inl.h`
* Several methods in public interfaces have a slightly different signature (see
#1738 for details).

#### `YARP_sig`

Expand Down
24 changes: 12 additions & 12 deletions example/carrier/carrier_human.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class HumanStream : public yarp::os::TwoWayStream, public yarp::os::InputStream,
/////////////////////////////////////////////////
// InputStream

virtual ssize_t read(const yarp::os::Bytes& b) {
virtual ssize_t read(yarp::os::Bytes& b) {
if (interrupting) { return -1; }
while (inputCache.size() < b.length()) {
yInfo() <<"*** CHECK OTHER TERMINAL FOR SOMETHING TO TYPE:";
Expand Down Expand Up @@ -144,48 +144,48 @@ class HumanCarrier : public yarp::os::Carrier {
/////////////////////////////////////////////////
// First, the easy bits...

virtual yarp::os::Carrier *create() {
virtual yarp::os::Carrier *create() const {
return new HumanCarrier();
}

virtual std::string getName() {
virtual std::string getName() const {
return "human";
}

virtual bool isConnectionless() {
virtual bool isConnectionless() const {
return true;
}

virtual bool canAccept() {
virtual bool canAccept() const {
return true;
}

virtual bool canOffer() {
virtual bool canOffer() const {
return true;
}

virtual bool isTextMode() {
virtual bool isTextMode() const {
// let's be text mode, for human-friendliness
return true;
}

virtual bool canEscape() {
virtual bool canEscape() const {
return true;
}

virtual bool requireAck() {
virtual bool requireAck() const {
return true;
}

virtual bool supportReply() {
virtual bool supportReply() const {
return true;
}

virtual bool isLocal() {
virtual bool isLocal() const {
return false;
}

virtual std::string toString() {
virtual std::string toString() const {
return "humans are handy";
}

Expand Down
17 changes: 11 additions & 6 deletions example/carrier/carrier_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,28 @@
* 8-bytes of a regular text mode connection.
*
*/
class TestCarrier : public yarp::os::impl::TextCarrier {

class TestCarrier : public yarp::os::impl::TextCarrier
{

public:
virtual std::string getName() {
virtual std::string getName() const override
{
return "test";
}

virtual std::string getSpecifierName() {
virtual std::string getSpecifierName() const override
{
return "TESTTEST";
}

virtual Carrier *create() {
virtual Carrier *create() const override
{
return new TestCarrier();
}
};

int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
yarp::os::Network yarp;
yarp::os::Carriers::addCarrierPrototype(new TestCarrier);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace yarp {
class yarp::test::PointQualityVocab : public yarp::os::idl::WireVocab {
public:
virtual int fromString(const std::string& input);
virtual std::string toString(int input);
virtual std::string toString(int input) const;
};


Expand Down
2 changes: 1 addition & 1 deletion example/os/playback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Saver : public Portable {
return reader.expectBlock(mem.get(),mem.length());
}

virtual bool write(ConnectionWriter& writer) {
virtual bool write(ConnectionWriter& writer) const {
if (mem.length()==0) {
fprintf(stderr,"Nothing to write.\n");
return false;
Expand Down
10 changes: 7 additions & 3 deletions src/carriers/bayer_carrier/BayerCarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ yarp::os::ConnectionReader& BayerCarrier::modifyIncomingData(yarp::os::Connectio
have_result = false;
if (need_reset) {
int m = DC1394_BAYER_METHOD_BILINEAR;
Searchable& config = reader.getConnectionModifiers();
const Searchable& config = reader.getConnectionModifiers();
half = false;
if (config.check("size")) {
if (config.find("size").asString() == "half") {
Expand Down Expand Up @@ -293,6 +293,10 @@ bool BayerCarrier::debayerFull(yarp::sig::ImageOf<PixelMono>& src,
return true;
}

bool BayerCarrier::processBuffered() const {
return const_cast<BayerCarrier*>(this)->processBuffered();
}

bool BayerCarrier::processBuffered() {
if (!have_result) {
//printf("Copy-based conversion.\n");
Expand All @@ -310,7 +314,7 @@ bool BayerCarrier::processBuffered() {
return true;
}

bool BayerCarrier::processDirect(const yarp::os::Bytes& bytes) {
bool BayerCarrier::processDirect(yarp::os::Bytes& bytes) {
if (have_result) {
memcpy(bytes.get(),out.getRawImage(),bytes.length());
return true;
Expand All @@ -328,7 +332,7 @@ bool BayerCarrier::processDirect(const yarp::os::Bytes& bytes) {
}


yarp::conf::ssize_t BayerCarrier::read(const yarp::os::Bytes& b) {
yarp::conf::ssize_t BayerCarrier::read(yarp::os::Bytes& b) {
// copy across small stuff - the image header
if (consumed<sizeof(header)) {
size_t len = b.length();
Expand Down
42 changes: 25 additions & 17 deletions src/carriers/bayer_carrier/BayerCarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ class yarp::os::BayerCarrier : public yarp::os::ModifyingCarrier,
if (local) delete local;
}

virtual Carrier *create() override {
virtual Carrier *create() const override {
return new BayerCarrier();
}

virtual std::string getName() override {
virtual std::string getName() const override {
return "bayer";
}

virtual std::string toString() override {
virtual std::string toString() const override {
return "bayer_carrier";
}

Expand All @@ -105,7 +105,7 @@ class yarp::os::BayerCarrier : public yarp::os::ModifyingCarrier,
////////////////////////////////////////////////////////////////////////
// ConnectionReader methods

virtual bool expectBlock(const char *data, size_t len) override {
virtual bool expectBlock(char *data, size_t len) override {
return local->expectBlock(data,len);
}

Expand Down Expand Up @@ -141,19 +141,19 @@ class yarp::os::BayerCarrier : public yarp::os::ModifyingCarrier,
return local->expectFloat64();
}

virtual bool isTextMode() override {
virtual bool isTextMode() const override {
return false;
}

virtual bool isBareMode() override {
virtual bool isBareMode() const override {
return false;
}

virtual bool convertTextMode() override {
return true;
}

virtual size_t getSize() override {
virtual size_t getSize() const override {
if (image_data_len) {
processBuffered();
}
Expand All @@ -168,35 +168,35 @@ class yarp::os::BayerCarrier : public yarp::os::ModifyingCarrier,
return parent->readEnvelope();
}

virtual Portable *getReference() override {
virtual Portable *getReference() const override {
return parent->getReference();
}

virtual Contact getRemoteContact() override {
virtual Contact getRemoteContact() const override {
return parent->getRemoteContact();
}

virtual Contact getLocalContact() override {
virtual Contact getLocalContact() const override {
return parent->getLocalContact();
}

virtual bool isValid() override {
virtual bool isValid() const override {
return true;
}

virtual bool isActive() override {
virtual bool isActive() const override {
return parent->isActive();
}

virtual bool isError() override {
virtual bool isError() const override {
return parent->isError()||!happy;
}

virtual void requestDrop() override {
parent->requestDrop();
}

virtual yarp::os::Searchable& getConnectionModifiers() override {
virtual const yarp::os::Searchable& getConnectionModifiers() const override {
return parent->getConnectionModifiers();
}

Expand All @@ -208,12 +208,12 @@ class yarp::os::BayerCarrier : public yarp::os::ModifyingCarrier,
// InputStream methods

using yarp::os::InputStream::read;
virtual yarp::conf::ssize_t read(const yarp::os::Bytes& b) override;
virtual yarp::conf::ssize_t read(yarp::os::Bytes& b) override;

virtual void close() override {
}

virtual bool isOk() override {
virtual bool isOk() const override {
return happy;
}

Expand All @@ -230,9 +230,17 @@ class yarp::os::BayerCarrier : public yarp::os::ModifyingCarrier,
virtual bool debayerHalf(yarp::sig::ImageOf<yarp::sig::PixelMono>& src,
yarp::sig::ImageOf<yarp::sig::PixelRgb>& dest);

/*
* The const version of the processBuffered() method performs a const_cast,
* and calls the non-const version. This allows to call it in const methods.
* Conceptually this is not completely wrong because it does not modify
* the external state of the class, but just some internal representation.
*/
virtual bool processBuffered() const;

virtual bool processBuffered();

virtual bool processDirect(const yarp::os::Bytes& bytes);
virtual bool processDirect(yarp::os::Bytes& bytes);

};

Expand Down
Loading

0 comments on commit e709b46

Please sign in to comment.