Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 828547f2774f
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8006b182e042
Choose a head ref
  • 4 commits
  • 5 files changed
  • 1 contributor

Commits on May 16, 2020

  1. Copy the full SHA
    f002533 View commit details
  2. Adjust DiscreteTrajectory.

    pleroy committed May 16, 2020
    Copy the full SHA
    d0aed6a View commit details
  3. Comments.

    pleroy committed May 16, 2020
    Copy the full SHA
    b3feef8 View commit details

Commits on May 17, 2020

  1. Merge pull request #2573 from pleroy/2570b

    Pass the iterator traits as a template parameter to Forkable and ForkableIterator
    pleroy authored May 17, 2020
    Copy the full SHA
    8006b18 View commit details
Showing with 145 additions and 134 deletions.
  1. +16 −12 physics/discrete_trajectory.hpp
  2. +5 −4 physics/discrete_trajectory_body.hpp
  3. +18 −27 physics/forkable.hpp
  4. +82 −74 physics/forkable_body.hpp
  5. +24 −17 physics/forkable_test.cpp
28 changes: 16 additions & 12 deletions physics/discrete_trajectory.hpp
Original file line number Diff line number Diff line change
@@ -32,16 +32,18 @@ namespace internal_forkable {
using base::not_constructible;

template<typename Frame>
struct ForkableTraits<DiscreteTrajectory<Frame>> : not_constructible {
using TimelineConstIterator =
typename std::map<Instant, DegreesOfFreedom<Frame>>::const_iterator;
struct DiscreteTrajectoryTraits : not_constructible {
using Timeline = typename std::map<Instant, DegreesOfFreedom<Frame>>;
using TimelineConstIterator = typename Timeline::const_iterator;

static Instant const& time(TimelineConstIterator it);
};

template<typename Frame>
class DiscreteTrajectoryIterator
: public ForkableIterator<DiscreteTrajectory<Frame>,
DiscreteTrajectoryIterator<Frame>> {
DiscreteTrajectoryIterator<Frame>,
DiscreteTrajectoryTraits<Frame>> {
public:
struct reference {
Instant const& time;
@@ -66,20 +68,17 @@ using geometry::Position;
using geometry::Vector;
using geometry::Velocity;
using internal_forkable::DiscreteTrajectoryIterator;
using internal_forkable::DiscreteTrajectoryTraits;
using quantities::Acceleration;
using quantities::Length;
using quantities::Speed;
using numerics::Hermite3;

template<typename Frame>
class DiscreteTrajectory : public Forkable<DiscreteTrajectory<Frame>,
DiscreteTrajectoryIterator<Frame>>,
DiscreteTrajectoryIterator<Frame>,
DiscreteTrajectoryTraits<Frame>>,
public Trajectory<Frame> {
using Timeline = std::map<Instant, DegreesOfFreedom<Frame>>;
using TimelineConstIterator = typename Forkable<
DiscreteTrajectory<Frame>,
DiscreteTrajectoryIterator<Frame>>::TimelineConstIterator;

public:
using Iterator = DiscreteTrajectoryIterator<Frame>;

@@ -177,6 +176,9 @@ class DiscreteTrajectory : public Forkable<DiscreteTrajectory<Frame>,
std::vector<DiscreteTrajectory<Frame>**> const& forks);

protected:
using TimelineConstIterator =
typename DiscreteTrajectoryTraits<Frame>::TimelineConstIterator;

// The API inherited from Forkable.
not_null<DiscreteTrajectory*> that() override;
not_null<DiscreteTrajectory const*> that() const override;
@@ -190,6 +192,8 @@ class DiscreteTrajectory : public Forkable<DiscreteTrajectory<Frame>,
std::int64_t timeline_size() const override;

private:
using Timeline = typename DiscreteTrajectoryTraits<Frame>::Timeline;

class Downsampling {
public:
Downsampling(std::int64_t max_dense_intervals,
@@ -262,9 +266,9 @@ class DiscreteTrajectory : public Forkable<DiscreteTrajectory<Frame>,

std::optional<Downsampling> downsampling_;

template<typename, typename>
template<typename, typename, typename>
friend class internal_forkable::ForkableIterator;
template<typename, typename>
template<typename, typename, typename>
friend class internal_forkable::Forkable;

// For using the private constructor in maps.
9 changes: 5 additions & 4 deletions physics/discrete_trajectory_body.hpp
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ namespace internal_forkable {
using geometry::Instant;

template<typename Frame>
Instant const& ForkableTraits<DiscreteTrajectory<Frame>>::time(
Instant const& DiscreteTrajectoryTraits<Frame>::time(
TimelineConstIterator const it) {
return it->first;
}
@@ -505,7 +505,8 @@ template<typename Frame>
void DiscreteTrajectory<Frame>::WriteSubTreeToMessage(
not_null<serialization::DiscreteTrajectory*> const message,
std::vector<DiscreteTrajectory<Frame>*>& forks) const {
Forkable<DiscreteTrajectory, Iterator>::WriteSubTreeToMessage(message, forks);
Forkable<DiscreteTrajectory, Iterator, DiscreteTrajectoryTraits<Frame>>::
WriteSubTreeToMessage(message, forks);
if (Flags::IsPresent("zfp", "off")) {
for (auto const& [instant, degrees_of_freedom] : timeline_) {
auto const instantaneous_degrees_of_freedom = message->add_timeline();
@@ -633,8 +634,8 @@ void DiscreteTrajectory<Frame>::FillSubTreeFromMessage(
downsampling_.emplace(
Downsampling::ReadFromMessage(message.downsampling(), timeline_));
}
Forkable<DiscreteTrajectory, Iterator>::FillSubTreeFromMessage(message,
forks);
Forkable<DiscreteTrajectory, Iterator, DiscreteTrajectoryTraits<Frame>>::
FillSubTreeFromMessage(message, forks);
}

template<typename Frame>
45 changes: 18 additions & 27 deletions physics/forkable.hpp
Original file line number Diff line number Diff line change
@@ -29,30 +29,25 @@ using geometry::Instant;
// and Forkable may then be instantiated using ForkableIterator.
// The template parameters with 1337 names are those that participate in this
// mutual CRTP.

template<typename Tr4jectory, typename It3rator>
class Forkable;

// This traits class must export declarations similar to the following:
//
// using TimelineConstIterator = ...;
// static Instant const& time(TimelineConstIterator it);
// Both classes have a Traits template parameter that gathers common
// implementation properties. The Traits class must export declarations similar
// to the following:
// using Timeline = ...;
// using TimelineConstIterator = ...;
// static Instant const& time(TimelineConstIterator it);
//
// TimelineConstIterator must be an STL-like iterator in the timeline of
// Tr4jectory. |time()| must return the corresponding time.
//
// NOTE(phl): This was originally written as a trait under the assumption that
// we would want to expose STL iterators to clients. This doesn't seem like a
// good idea anymore, so maybe this should turn into another CRTP class.
template<typename Tr4jectory>
struct ForkableTraits;
// Tr4jectory. |time()| must return the corresponding time. Iterators must be
// STL-like and *must*not* be invalidated when the trajectory changes.

template<typename Tr4jectory, typename It3rator, typename Traits>
class Forkable;

// A template for iterating over the timeline of a Forkable object, taking forks
// into account.
template<typename Tr4jectory, typename It3rator>
template<typename Tr4jectory, typename It3rator, typename Traits>
class ForkableIterator {
using TimelineConstIterator =
typename ForkableTraits<Tr4jectory>::TimelineConstIterator;
using TimelineConstIterator = typename Traits::TimelineConstIterator;

public:
ForkableIterator() = default;
@@ -93,21 +88,15 @@ class ForkableIterator {
TimelineConstIterator current_;
std::deque<not_null<Tr4jectory const*>> ancestry_; // Pointers not owned.

template<typename, typename>
template<typename, typename, typename>
friend class Forkable;
};

// This template represents a trajectory which is forkable and iterable (using
// a ForkableIterator).
template<typename Tr4jectory, typename It3rator>
template<typename Tr4jectory, typename It3rator, typename Traits>
class Forkable {
public:
// An iterator into the timeline of the trajectory. Must be STL-like.
// Beware, if these iterators are invalidated all the guarantees of Forkable
// are void.
using TimelineConstIterator =
typename ForkableTraits<Tr4jectory>::TimelineConstIterator;

Forkable() = default;
virtual ~Forkable() = default;

@@ -153,6 +142,8 @@ class Forkable {
bool Empty() const;

protected:
using TimelineConstIterator = typename Traits::TimelineConstIterator;

// The API that must be implemented by subclasses.

// Must return |this| of the proper type.
@@ -236,7 +227,7 @@ class Forkable {
std::optional<TimelineConstIterator> position_in_parent_timeline_;
Children children_;

template<typename, typename>
template<typename, typename, typename>
friend class ForkableIterator;
};

Loading