Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DataReader::read() const #455

Open
t0ny-peng opened this issue Sep 28, 2023 · 1 comment
Open

Make DataReader::read() const #455

t0ny-peng opened this issue Sep 28, 2023 · 1 comment

Comments

@t0ny-peng
Copy link
Contributor

I have a const class function that checks if a DataReader member has any data ready to be received. The problem is, DataReader::read() itself is not const.

https://github.com/eclipse-cyclonedds/cyclonedds-cxx/blob/master/src/ddscxx/include/dds/sub/detail/DataReader.hpp#L74

I understand that take will modify the internal state of the buffer, but since read returns a view and won't affect the counter, would it make sense to mark it as const?

Thanks

@eboasson
Copy link
Contributor

eboasson commented Oct 5, 2023

Hi @t0ny-peng, unfortunately read too modifies the state of the history cache: it changes the "sample state" and "view state" for the samples/instances in the result. I think that's enough to not be able to mark it const.

It did remind me that I've wanted a peek operation for a long time, one that has no side-effects on the reader or its history cache whatsoever. I've added it in the C API (see cyclonedds#1842); adding it to the C++ API should be trivial (just another set of functions like for read/take) but not something I can do right now, but maybe someone else (or you yourself) can do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants