Add final specifier to public classes

Change-Id: Ib7291dc68d5d4141ee821689743481fc84768606
diff --git a/include/ceres/autodiff_cost_function.h b/include/ceres/autodiff_cost_function.h
index 993daf1..c080fef 100644
--- a/include/ceres/autodiff_cost_function.h
+++ b/include/ceres/autodiff_cost_function.h
@@ -151,7 +151,8 @@
 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 @@
         jacobians);
   };
 
-  const CostFunctor & functor() const { return *functor_; }
+  const CostFunctor& functor() const { return *functor_; }
 
  private:
   std::unique_ptr<CostFunctor> functor_;
diff --git a/include/ceres/autodiff_first_order_function.h b/include/ceres/autodiff_first_order_function.h
index 4ace559..5a51952 100644
--- a/include/ceres/autodiff_first_order_function.h
+++ b/include/ceres/autodiff_first_order_function.h
@@ -102,7 +102,7 @@
 // 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 @@
     static_assert(kNumParameters > 0, "kNumParameters must be positive");
   }
 
-
   bool Evaluate(const double* const parameters,
                 double* cost,
                 double* gradient) const override {
@@ -141,7 +140,7 @@
 
   int NumParameters() const override { return kNumParameters; }
 
-  const FirstOrderFunctor & functor() const { return *functor_; }
+  const FirstOrderFunctor& functor() const { return *functor_; }
 
  private:
   std::unique_ptr<FirstOrderFunctor> functor_;
diff --git a/include/ceres/autodiff_manifold.h b/include/ceres/autodiff_manifold.h
index 7b5f639..978e13e 100644
--- a/include/ceres/autodiff_manifold.h
+++ b/include/ceres/autodiff_manifold.h
@@ -145,14 +145,13 @@
 //   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 @@
 
   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_;
diff --git a/include/ceres/conditioned_cost_function.h b/include/ceres/conditioned_cost_function.h
index e80728d..e4c3dec 100644
--- a/include/ceres/conditioned_cost_function.h
+++ b/include/ceres/conditioned_cost_function.h
@@ -71,7 +71,7 @@
 //   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
diff --git a/include/ceres/dynamic_autodiff_cost_function.h b/include/ceres/dynamic_autodiff_cost_function.h
index 2812956..d72be6d 100644
--- a/include/ceres/dynamic_autodiff_cost_function.h
+++ b/include/ceres/dynamic_autodiff_cost_function.h
@@ -77,7 +77,7 @@
 // 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,
diff --git a/include/ceres/dynamic_numeric_diff_cost_function.h b/include/ceres/dynamic_numeric_diff_cost_function.h
index 9cbc8ee..793fb05 100644
--- a/include/ceres/dynamic_numeric_diff_cost_function.h
+++ b/include/ceres/dynamic_numeric_diff_cost_function.h
@@ -77,7 +77,7 @@
 //   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,
diff --git a/include/ceres/loss_function.h b/include/ceres/loss_function.h
index fc6f358..8a5a37f 100644
--- a/include/ceres/loss_function.h
+++ b/include/ceres/loss_function.h
@@ -129,7 +129,7 @@
 // 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 @@
 //
 // 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 @@
 //   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 @@
 //   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 @@
 //   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 @@
 // 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 @@
 //   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 @@
 // 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 @@
 // 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 @@
 //
 //  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) {}
diff --git a/include/ceres/manifold.h b/include/ceres/manifold.h
index a3ec9df..964baec 100644
--- a/include/ceres/manifold.h
+++ b/include/ceres/manifold.h
@@ -223,7 +223,7 @@
 // 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 @@
 };
 
 // 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 @@
 //
 // 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 @@
 // (|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 @@
 //
 // 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 @@
 // 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 @@
 //    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.");
diff --git a/include/ceres/normal_prior.h b/include/ceres/normal_prior.h
index 14ab379..c5c7f3e 100644
--- a/include/ceres/normal_prior.h
+++ b/include/ceres/normal_prior.h
@@ -57,7 +57,7 @@
 // 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.
diff --git a/include/ceres/numeric_diff_cost_function.h b/include/ceres/numeric_diff_cost_function.h
index f147b16..7235327 100644
--- a/include/ceres/numeric_diff_cost_function.h
+++ b/include/ceres/numeric_diff_cost_function.h
@@ -179,7 +179,8 @@
           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 @@
     return true;
   }
 
-  const CostFunctor & functor() const { return *functor_; }
+  const CostFunctor& functor() const { return *functor_; }
 
  private:
   std::unique_ptr<CostFunctor> functor_;
diff --git a/include/ceres/numeric_diff_first_order_function.h b/include/ceres/numeric_diff_first_order_function.h
index cd24c96..5841765 100644
--- a/include/ceres/numeric_diff_first_order_function.h
+++ b/include/ceres/numeric_diff_first_order_function.h
@@ -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 @@
 template <typename FirstOrderFunctor,
           NumericDiffMethodType method,
           int kNumParameters>
-class NumericDiffFirstOrderFunction : public FirstOrderFunction {
+class NumericDiffFirstOrderFunction final : public FirstOrderFunction {
  public:
   NumericDiffFirstOrderFunction(
       FirstOrderFunctor* functor,
@@ -151,7 +150,7 @@
 
   int NumParameters() const override { return kNumParameters; }
 
-  const FirstOrderFunctor & functor() const { return *functor_; }
+  const FirstOrderFunctor& functor() const { return *functor_; }
 
  private:
   std::unique_ptr<FirstOrderFunctor> functor_;