Skip to content

Conversation

@leokoppel
Copy link
Contributor

@leokoppel leokoppel commented May 31, 2017

Further to #41. Code duplication was noted in PR #82.

Reduce code duplication between the similar MeasurementContainer and LandmarkMeasurementContainer (and any other future variations).

This is done through static polymorphism, using CRTP (the technique used extensively by Eigen). References:

Pre-Merge Checklist:

  • Code is documented in doxygen format
  • Code has automated tests
  • Zero compiler warnings
  • Formatted with clang-format

Testing done: existing unit tests. There is no behaviour change, so unit tests are untouched.

@leokoppel leokoppel self-assigned this May 31, 2017
@leokoppel leokoppel requested review from chutsu and navganti May 31, 2017 05:22
@leokoppel leokoppel force-pushed the refactor_measurement_containers branch from 5bf290b to 7ab206a Compare June 3, 2017 21:34
@navganti navganti requested a review from Jebediah June 7, 2017 21:19
Copy link
Member

@navganti navganti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be honest, I'm struggling a bit with the TMP. Even more so now that it's recursive...

I'm going to take another look at it a bit later. Haven't noticed anything major yet; just have a few questions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still need this? I see you're using T for the rest of this struct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. T does not persist outside of this definition. MeasurementType is defined so it can be used by MeasurementContainerBase, from outside of this definition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right...because Base is templated with either the landmark or regular measurement containers.

I was actually wondering about where MeasurementType was defined in the base class; that makes a bit more sense now. Thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice CRTP

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have two sets of protected: specified objects. Should they be consolidated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm maybe. I sorted them by types and data members but I actually have a typedef down here.. good catch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the typedef at the bottom (and the protected at the top)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to specify a local variable here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the next line doesn't go over 80 characters ; )

But also, it makes it clear I just use the result of one call composite(); that it doesn't change or have side effects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, sounds good. Was just curious since you were just directly modifying this->composite all throughout the rest of those similar methods.

leokoppel added 9 commits June 7, 2017 21:57
The goal is to reduce code duplication between the similar MeasurementContainer and LandmarkMeasurementContainer
(and any other future variations).

To do this, use CRTP and refine the "internal::measurement_container" struct as a traits class.

Only modify MeasurementContainer in this commit; LandmarkMeasurementContainer is next.

Resources:

- http://eli.thegreenplace.net/2011/05/17/the-curiously-recurring-template-pattern-in-c
- https://stackoverflow.com/questions/4173254/what-is-the-curiously-recurring-template-pattern-crtp
- https://stackoverflow.com/questions/6006614/c-static-polymorphism-crtp-and-using-typedefs-from-derived-classes
The problem was the test getAllFromSensor for getAllFromSensor was failing because the results
were not ordered by time.

Because MeasurementContainerBase<T>::getAllFromSensor() uses the traits type "sensor_index",
make LandmarkMeasurementContainer's "sensor_index" include ordering by time. Do this by simply
renaming its "sensor_composite_index".
Clearly differentiate:
* Derived: the type of derived measurement container
* T: the type of measurement
There is no reason for this change except it fixes a resolution problem in my IDE.

There is no real reason to avoid the change either.
@leokoppel leokoppel force-pushed the refactor_measurement_containers branch 2 times, most recently from 39afe88 to 3794745 Compare June 8, 2017 04:45
The class definition is organized, top to bottom:

- typedefs
- methods
- data members

The first typedef is private, and is first because it is used for convenience of defining the other types.

Remove an unneeded typedef used only in the subsequent two lines.
Change "protected" traits typedef to private, and redefine it in derived classes to avoid possibly confusing "Base::traits".
@leokoppel leokoppel force-pushed the refactor_measurement_containers branch from 3794745 to 036f03d Compare June 8, 2017 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants