Add final specifier to public classes

Change-Id: Ib7291dc68d5d4141ee821689743481fc84768606
This commit is contained in:
Sameer Agarwal
2022-02-18 15:51:17 -08:00
parent 84e1696f4e
commit 8fe8ebc3a6
11 changed files with 33 additions and 34 deletions
+3 -2
View File
@@ -151,7 +151,8 @@ namespace ceres {
template <typename CostFunctor,
int kNumResiduals, // Number of residuals, or ceres::DYNAMIC.
int... Ns> // Number of parameters in each parameter block.
class AutoDiffCostFunction : public SizedCostFunction<kNumResiduals, Ns...> {
class AutoDiffCostFunction final
: public SizedCostFunction<kNumResiduals, Ns...> {
public:
// Takes ownership of functor by default. Uses the template-provided
// value for the number of residuals ("kNumResiduals").
@@ -215,7 +216,7 @@ class AutoDiffCostFunction : public SizedCostFunction<kNumResiduals, Ns...> {
jacobians);
};
const CostFunctor & functor() const { return *functor_; }
const CostFunctor& functor() const { return *functor_; }
private:
std::unique_ptr<CostFunctor> functor_;
@@ -102,7 +102,7 @@ namespace ceres {
// seen where instead of using a_ directly, a_ is wrapped with T(a_).
template <typename FirstOrderFunctor, int kNumParameters>
class AutoDiffFirstOrderFunction : public FirstOrderFunction {
class AutoDiffFirstOrderFunction final : public FirstOrderFunction {
public:
// Takes ownership of functor.
explicit AutoDiffFirstOrderFunction(FirstOrderFunctor* functor)
@@ -110,7 +110,6 @@ class AutoDiffFirstOrderFunction : public FirstOrderFunction {
static_assert(kNumParameters > 0, "kNumParameters must be positive");
}
bool Evaluate(const double* const parameters,
double* cost,
double* gradient) const override {
@@ -141,7 +140,7 @@ class AutoDiffFirstOrderFunction : public FirstOrderFunction {
int NumParameters() const override { return kNumParameters; }
const FirstOrderFunctor & functor() const { return *functor_; }
const FirstOrderFunctor& functor() const { return *functor_; }
private:
std::unique_ptr<FirstOrderFunctor> functor_;
+2 -3
View File
@@ -145,14 +145,13 @@ namespace ceres {
// Manifold* manifold = new AutoDiffManifold<QuaternionFunctor, 4, 3>;
template <typename Functor, int kAmbientSize, int kTangentSize>
class AutoDiffManifold : public Manifold {
class AutoDiffManifold final : public Manifold {
public:
AutoDiffManifold() : functor_(std::make_unique<Functor>()) {}
// Takes ownership of functor.
explicit AutoDiffManifold(Functor* functor) : functor_(functor) {}
int AmbientSize() const override { return kAmbientSize; }
int TangentSize() const override { return kTangentSize; }
@@ -172,7 +171,7 @@ class AutoDiffManifold : public Manifold {
bool MinusJacobian(const double* x, double* jacobian) const override;
const Functor & functor() const { return *functor_; }
const Functor& functor() const { return *functor_; }
private:
std::unique_ptr<Functor> functor_;
+1 -1
View File
@@ -71,7 +71,7 @@ namespace ceres {
// ccf_residual[i] = f_i(my_cost_function_residual[i])
//
// and the Jacobian will be affected appropriately.
class CERES_EXPORT ConditionedCostFunction : public CostFunction {
class CERES_EXPORT ConditionedCostFunction final : public CostFunction {
public:
// Builds a cost function based on a wrapped cost function, and a
// per-residual conditioner. Takes ownership of all of the wrapped cost
@@ -77,7 +77,7 @@ namespace ceres {
// pass. There is a tradeoff with the size of the passes; you may want
// to experiment with the stride.
template <typename CostFunctor, int Stride = 4>
class DynamicAutoDiffCostFunction : public DynamicCostFunction {
class DynamicAutoDiffCostFunction final : public DynamicCostFunction {
public:
// Takes ownership by default.
DynamicAutoDiffCostFunction(CostFunctor* functor,
@@ -77,7 +77,7 @@ namespace ceres {
// cost_function.AddParameterBlock(10);
// cost_function.SetNumResiduals(21);
template <typename CostFunctor, NumericDiffMethodType method = CENTRAL>
class DynamicNumericDiffCostFunction : public DynamicCostFunction {
class DynamicNumericDiffCostFunction final : public DynamicCostFunction {
public:
explicit DynamicNumericDiffCostFunction(
const CostFunctor* functor,
+10 -10
View File
@@ -129,7 +129,7 @@ class CERES_EXPORT LossFunction {
// It is not normally necessary to use this, as passing nullptr for the
// loss function when building the problem accomplishes the same
// thing.
class CERES_EXPORT TrivialLoss : public LossFunction {
class CERES_EXPORT TrivialLoss final : public LossFunction {
public:
void Evaluate(double, double*) const override;
};
@@ -172,7 +172,7 @@ class CERES_EXPORT TrivialLoss : public LossFunction {
//
// The scaling parameter 'a' corresponds to 'delta' on this page:
// http://en.wikipedia.org/wiki/Huber_Loss_Function
class CERES_EXPORT HuberLoss : public LossFunction {
class CERES_EXPORT HuberLoss final : public LossFunction {
public:
explicit HuberLoss(double a) : a_(a), b_(a * a) {}
void Evaluate(double, double*) const override;
@@ -188,7 +188,7 @@ class CERES_EXPORT HuberLoss : public LossFunction {
// rho(s) = 2 (sqrt(1 + s) - 1).
//
// At s = 0: rho = [0, 1, -1 / (2 * a^2)].
class CERES_EXPORT SoftLOneLoss : public LossFunction {
class CERES_EXPORT SoftLOneLoss final : public LossFunction {
public:
explicit SoftLOneLoss(double a) : b_(a * a), c_(1 / b_) {}
void Evaluate(double, double*) const override;
@@ -205,7 +205,7 @@ class CERES_EXPORT SoftLOneLoss : public LossFunction {
// rho(s) = log(1 + s).
//
// At s = 0: rho = [0, 1, -1 / a^2].
class CERES_EXPORT CauchyLoss : public LossFunction {
class CERES_EXPORT CauchyLoss final : public LossFunction {
public:
explicit CauchyLoss(double a) : b_(a * a), c_(1 / b_) {}
void Evaluate(double, double*) const override;
@@ -226,7 +226,7 @@ class CERES_EXPORT CauchyLoss : public LossFunction {
// rho(s) = a atan(s / a).
//
// At s = 0: rho = [0, 1, 0].
class CERES_EXPORT ArctanLoss : public LossFunction {
class CERES_EXPORT ArctanLoss final : public LossFunction {
public:
explicit ArctanLoss(double a) : a_(a), b_(1 / (a * a)) {}
void Evaluate(double, double*) const override;
@@ -265,7 +265,7 @@ class CERES_EXPORT ArctanLoss : public LossFunction {
// concentrated in the range a - b to a + b.
//
// At s = 0: rho = [0, ~0, ~0].
class CERES_EXPORT TolerantLoss : public LossFunction {
class CERES_EXPORT TolerantLoss final : public LossFunction {
public:
explicit TolerantLoss(double a, double b);
void Evaluate(double, double*) const override;
@@ -284,7 +284,7 @@ class CERES_EXPORT TolerantLoss : public LossFunction {
// rho(s) = a^2 / 3 for s > a^2.
//
// At s = 0: rho = [0, 1, -2 / a^2]
class CERES_EXPORT TukeyLoss : public ceres::LossFunction {
class CERES_EXPORT TukeyLoss final : public ceres::LossFunction {
public:
explicit TukeyLoss(double a) : a_squared_(a * a) {}
void Evaluate(double, double*) const override;
@@ -296,7 +296,7 @@ class CERES_EXPORT TukeyLoss : public ceres::LossFunction {
// Composition of two loss functions. The error is the result of first
// evaluating g followed by f to yield the composition f(g(s)).
// The loss functions must not be nullptr.
class CERES_EXPORT ComposedLoss : public LossFunction {
class CERES_EXPORT ComposedLoss final : public LossFunction {
public:
explicit ComposedLoss(const LossFunction* f,
Ownership ownership_f,
@@ -327,7 +327,7 @@ class CERES_EXPORT ComposedLoss : public LossFunction {
// function, rho = nullptr is a valid input and will result in the input
// being scaled by a. This provides a simple way of implementing a
// scaled ResidualBlock.
class CERES_EXPORT ScaledLoss : public LossFunction {
class CERES_EXPORT ScaledLoss final : public LossFunction {
public:
// Constructs a ScaledLoss wrapping another loss function. Takes
// ownership of the wrapped loss function or not depending on the
@@ -389,7 +389,7 @@ class CERES_EXPORT ScaledLoss : public LossFunction {
//
// Solve(options, &problem, &summary)
//
class CERES_EXPORT LossFunctionWrapper : public LossFunction {
class CERES_EXPORT LossFunctionWrapper final : public LossFunction {
public:
LossFunctionWrapper(LossFunction* rho, Ownership ownership)
: rho_(rho), ownership_(ownership) {}
+7 -7
View File
@@ -223,7 +223,7 @@ class CERES_EXPORT Manifold {
// subtraction:
// Plus(x, delta) = x + delta
// Minus(y, x) = y - x.
class CERES_EXPORT EuclideanManifold : public Manifold {
class CERES_EXPORT EuclideanManifold final : public Manifold {
public:
EuclideanManifold(int size);
int AmbientSize() const override;
@@ -246,7 +246,7 @@ class CERES_EXPORT EuclideanManifold : public Manifold {
};
// Hold a subset of the parameters inside a parameter block constant.
class CERES_EXPORT SubsetManifold : public Manifold {
class CERES_EXPORT SubsetManifold final : public Manifold {
public:
SubsetManifold(int size, const std::vector<int>& constant_parameters);
int AmbientSize() const override;
@@ -281,7 +281,7 @@ class CERES_EXPORT SubsetManifold : public Manifold {
//
// is the manifold for a rigid transformation, where the rotation is represented
// using a quaternion.
class CERES_EXPORT ProductManifold : public Manifold {
class CERES_EXPORT ProductManifold final : public Manifold {
public:
ProductManifold(const ProductManifold&) = delete;
ProductManifold& operator=(const ProductManifold&) = delete;
@@ -357,7 +357,7 @@ class CERES_EXPORT ProductManifold : public Manifold {
// (|q|=1), q^-1 = [q0; -q1; -q2; -q3]
//
// and to_delta( [q0; u_{3x1}] ) = u / |u| * atan2(|u|, q0)
class CERES_EXPORT QuaternionManifold : public Manifold {
class CERES_EXPORT QuaternionManifold final : public Manifold {
public:
int AmbientSize() const override { return 4; }
int TangentSize() const override { return 3; }
@@ -381,7 +381,7 @@ class CERES_EXPORT QuaternionManifold : public Manifold {
//
// Since Ceres operates on parameter blocks which are raw double pointers this
// difference is important and requires a different manifold.
class CERES_EXPORT EigenQuaternionManifold : public Manifold {
class CERES_EXPORT EigenQuaternionManifold final : public Manifold {
public:
int AmbientSize() const override { return 4; }
int TangentSize() const override { return 3; }
@@ -431,7 +431,7 @@ class CERES_EXPORT EigenQuaternionManifold : public Manifold {
// Hertzberg, R. Wagner, U. Frese and L. Schroder for more details
// (https://arxiv.org/pdf/1107.1119.pdf)
template <int AmbientSpaceDimension>
class SphereManifold : public Manifold {
class SphereManifold final : public Manifold {
public:
static_assert(
AmbientSpaceDimension == DYNAMIC || AmbientSpaceDimension > 1,
@@ -502,7 +502,7 @@ class SphereManifold : public Manifold {
// LineManifold<ceres::DYNAMIC> manifold(ambient_dim);
//
template <int AmbientSpaceDimension>
class LineManifold : public Manifold {
class LineManifold final : public Manifold {
public:
static_assert(AmbientSpaceDimension == DYNAMIC || AmbientSpaceDimension >= 2,
"The ambient space must be at least 2.");
+1 -1
View File
@@ -57,7 +57,7 @@ namespace ceres {
// which would be the case if the covariance matrix S is rank
// deficient.
class CERES_EXPORT NormalPrior : public CostFunction {
class CERES_EXPORT NormalPrior final : public CostFunction {
public:
// Check that the number of rows in the vector b are the same as the
// number of columns in the matrix A, crash otherwise.
+3 -2
View File
@@ -179,7 +179,8 @@ template <typename CostFunctor,
NumericDiffMethodType method = CENTRAL,
int kNumResiduals = 0, // Number of residuals, or ceres::DYNAMIC
int... Ns> // Parameters dimensions for each block.
class NumericDiffCostFunction : public SizedCostFunction<kNumResiduals, Ns...> {
class NumericDiffCostFunction final
: public SizedCostFunction<kNumResiduals, Ns...> {
public:
NumericDiffCostFunction(
CostFunctor* functor,
@@ -246,7 +247,7 @@ class NumericDiffCostFunction : public SizedCostFunction<kNumResiduals, Ns...> {
return true;
}
const CostFunctor & functor() const { return *functor_; }
const CostFunctor& functor() const { return *functor_; }
private:
std::unique_ptr<CostFunctor> functor_;
@@ -43,7 +43,6 @@
#include "ceres/numeric_diff_options.h"
#include "ceres/types.h"
namespace ceres {
// Creates FirstOrderFunctions as needed by the GradientProblem
@@ -103,7 +102,7 @@ namespace ceres {
template <typename FirstOrderFunctor,
NumericDiffMethodType method,
int kNumParameters>
class NumericDiffFirstOrderFunction : public FirstOrderFunction {
class NumericDiffFirstOrderFunction final : public FirstOrderFunction {
public:
NumericDiffFirstOrderFunction(
FirstOrderFunctor* functor,
@@ -151,7 +150,7 @@ class NumericDiffFirstOrderFunction : public FirstOrderFunction {
int NumParameters() const override { return kNumParameters; }
const FirstOrderFunctor & functor() const { return *functor_; }
const FirstOrderFunctor& functor() const { return *functor_; }
private:
std::unique_ptr<FirstOrderFunctor> functor_;