Skip to content

Commit

Permalink
Mark generated named vectors final
Browse files Browse the repository at this point in the history
We don't really want users further subclassing these vector types.
Also, I would not be surprised if this was a performance improvement.
  • Loading branch information
jwnimmer-tri committed May 23, 2018
1 parent cc8a89c commit ac03c0c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
14 changes: 7 additions & 7 deletions tools/vector_gen/lcm_vector_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def generate_set_to_named_variables(hh, caller_context, fields):


DO_CLONE = """
%(camel)s<T>* DoClone() const override {
%(camel)s<T>* DoClone() const final {
return new %(camel)s;
}
"""
Expand Down Expand Up @@ -297,7 +297,7 @@ def generate_is_valid(hh, caller_context, fields):

CALC_INEQUALITY_CONSTRAINT_BEGIN = """
// VectorBase override.
void CalcInequalityConstraint(drake::VectorX<T>* value) const override {
void CalcInequalityConstraint(drake::VectorX<T>* value) const final {
value->resize(%(num_constraints)d);
"""
CALC_INEQUALITY_CONSTRAINT_MIN_VALUE = """
Expand Down Expand Up @@ -365,7 +365,7 @@ def generate_calc_inequality_constraint(hh, caller_context, fields):
/// Specializes BasicVector with specific getters and setters.
template <typename T>
class %(camel)s : public drake::systems::BasicVector<T> {
class %(camel)s final : public drake::systems::BasicVector<T> {
public:
/// An abbreviation for our row index constants.
typedef %(indices)s K;
Expand Down Expand Up @@ -411,18 +411,18 @@ class %(camel)s : public drake::systems::BasicVector<T> {
* Translates between LCM message objects and VectorBase objects for the
* %(camel)s type.
*/
class %(camel)sTranslator
class %(camel)sTranslator final
: public drake::systems::lcm::LcmAndVectorBaseTranslator {
public:
%(camel)sTranslator()
: LcmAndVectorBaseTranslator(%(indices)s::kNumCoordinates) {}
std::unique_ptr<drake::systems::BasicVector<double>> AllocateOutputVector()
const override;
const final;
void Deserialize(const void* lcm_message_bytes, int lcm_message_length,
drake::systems::VectorBase<double>* vector_base) const override;
drake::systems::VectorBase<double>* vector_base) const final;
void Serialize(double time,
const drake::systems::VectorBase<double>& vector_base,
std::vector<uint8_t>* lcm_message_bytes) const override;
std::vector<uint8_t>* lcm_message_bytes) const final;
};
"""

Expand Down
6 changes: 3 additions & 3 deletions tools/vector_gen/test/goal/sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct SampleIndices {

/// Specializes BasicVector with specific getters and setters.
template <typename T>
class Sample : public drake::systems::BasicVector<T> {
class Sample final : public drake::systems::BasicVector<T> {
public:
/// An abbreviation for our row index constants.
typedef SampleIndices K;
Expand All @@ -63,7 +63,7 @@ class Sample : public drake::systems::BasicVector<T> {
this->set_absone(symbolic::Variable("absone"));
}

Sample<T>* DoClone() const override { return new Sample; }
Sample<T>* DoClone() const final { return new Sample; }

/// @name Getters and Setters
//@{
Expand Down Expand Up @@ -103,7 +103,7 @@ class Sample : public drake::systems::BasicVector<T> {
}

// VectorBase override.
void CalcInequalityConstraint(drake::VectorX<T>* value) const override {
void CalcInequalityConstraint(drake::VectorX<T>* value) const final {
value->resize(3);
(*value)[0] = x() - T(0.0);
(*value)[1] = absone() - T(-1.0);
Expand Down
11 changes: 5 additions & 6 deletions tools/vector_gen/test/goal/sample_translator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ namespace test {
* Translates between LCM message objects and VectorBase objects for the
* Sample type.
*/
class SampleTranslator
class SampleTranslator final
: public drake::systems::lcm::LcmAndVectorBaseTranslator {
public:
SampleTranslator()
: LcmAndVectorBaseTranslator(SampleIndices::kNumCoordinates) {}
std::unique_ptr<drake::systems::BasicVector<double>> AllocateOutputVector()
const override;
void Deserialize(
const void* lcm_message_bytes, int lcm_message_length,
drake::systems::VectorBase<double>* vector_base) const override;
const final;
void Deserialize(const void* lcm_message_bytes, int lcm_message_length,
drake::systems::VectorBase<double>* vector_base) const final;
void Serialize(double time,
const drake::systems::VectorBase<double>& vector_base,
std::vector<uint8_t>* lcm_message_bytes) const override;
std::vector<uint8_t>* lcm_message_bytes) const final;
};

} // namespace test
Expand Down

0 comments on commit ac03c0c

Please sign in to comment.