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: 2959395440d2
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0b544ddf5343
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Nov 6, 2021

  1. Convert iterators.

    pleroy committed Nov 6, 2021
    Copy the full SHA
    ac413f8 View commit details
  2. Merge pull request #3192 from pleroy/Iterators

    Convert Iterator to DiscreteTraject0ry
    pleroy authored Nov 6, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0b544dd View commit details
Showing with 25 additions and 27 deletions.
  1. +9 −9 ksp_plugin/iterators.hpp
  2. +16 −18 ksp_plugin/iterators_body.hpp
18 changes: 9 additions & 9 deletions ksp_plugin/iterators.hpp
Original file line number Diff line number Diff line change
@@ -5,13 +5,13 @@
#include "ksp_plugin/frames.hpp"
#include "ksp_plugin/identification.hpp"
#include "ksp_plugin/plugin.hpp"
#include "physics/discrete_trajectory.hpp"
#include "physics/discrete_traject0ry.hpp"

namespace principia {
namespace ksp_plugin {

using base::not_null;
using physics::DiscreteTrajectory;
using physics::DiscreteTraject0ry;

// A wrapper for a container and an iterator into that container.
class Iterator {
@@ -47,31 +47,31 @@ class TypedIterator : public Iterator {
typename Container::const_iterator iterator_;
};

// A specialization for |DiscreteTrajectory<World>|.
// A specialization for |DiscreteTraject0ry<World>|.
template<>
class TypedIterator<DiscreteTrajectory<World>> : public Iterator {
class TypedIterator<DiscreteTraject0ry<World>> : public Iterator {
public:
TypedIterator(not_null<std::unique_ptr<DiscreteTrajectory<World>>> trajectory,
TypedIterator(DiscreteTraject0ry<World> trajectory,
not_null<Plugin const*> plugin);

// Obtains the element denoted by this iterator and converts it to some
// |Interchange| type using |convert|.
template<typename Interchange>
Interchange Get(
std::function<Interchange(
DiscreteTrajectory<World>::Iterator const&)> const& convert) const;
DiscreteTraject0ry<World>::iterator const&)> const& convert) const;

bool AtEnd() const override;
void Increment() override;
void Reset() override;
int Size() const override;

DiscreteTrajectory<World>::Iterator iterator() const;
DiscreteTraject0ry<World>::iterator iterator() const;
not_null<Plugin const*> plugin() const;

private:
not_null<std::unique_ptr<DiscreteTrajectory<World>>> trajectory_;
DiscreteTrajectory<World>::Iterator iterator_;
DiscreteTraject0ry<World> trajectory_;
DiscreteTraject0ry<World>::iterator iterator_;
not_null<Plugin const*> plugin_;
};

34 changes: 16 additions & 18 deletions ksp_plugin/iterators_body.hpp
Original file line number Diff line number Diff line change
@@ -42,46 +42,44 @@ int TypedIterator<Container>::Size() const {
return container_.size();
}

inline TypedIterator<DiscreteTrajectory<World>>::TypedIterator(
not_null<std::unique_ptr<DiscreteTrajectory<World>>> trajectory,
inline TypedIterator<DiscreteTraject0ry<World>>::TypedIterator(
DiscreteTraject0ry<World> trajectory,
not_null<Plugin const*> const plugin)
: trajectory_(std::move(trajectory)),
iterator_(trajectory_->begin()),
plugin_(plugin) {
CHECK(trajectory_->is_root());
}
iterator_(trajectory_.begin()),
plugin_(plugin) {}

template<typename Interchange>
Interchange TypedIterator<DiscreteTrajectory<World>>::Get(
Interchange TypedIterator<DiscreteTraject0ry<World>>::Get(
std::function<Interchange(
DiscreteTrajectory<World>::Iterator const&)> const& convert) const {
DiscreteTraject0ry<World>::iterator const&)> const& convert) const {
CHECK(iterator_ != trajectory_->end());
return convert(iterator_);
}

inline bool TypedIterator<DiscreteTrajectory<World>>::AtEnd() const {
return iterator_ == trajectory_->end();
inline bool TypedIterator<DiscreteTraject0ry<World>>::AtEnd() const {
return iterator_ == trajectory_.end();
}

inline void TypedIterator<DiscreteTrajectory<World>>::Increment() {
inline void TypedIterator<DiscreteTraject0ry<World>>::Increment() {
++iterator_;
}

inline void TypedIterator<DiscreteTrajectory<World>>::Reset() {
iterator_ = trajectory_->begin();
inline void TypedIterator<DiscreteTraject0ry<World>>::Reset() {
iterator_ = trajectory_.begin();
}

inline int TypedIterator<DiscreteTrajectory<World>>::Size() const {
return trajectory_->Size();
inline int TypedIterator<DiscreteTraject0ry<World>>::Size() const {
return trajectory_.size();
}

inline DiscreteTrajectory<World>::Iterator TypedIterator<
DiscreteTrajectory<World>>::iterator() const {
inline DiscreteTraject0ry<World>::iterator TypedIterator<
DiscreteTraject0ry<World>>::iterator() const {
return iterator_;
}

inline not_null<Plugin const*> TypedIterator<
DiscreteTrajectory<World>>::plugin() const {
DiscreteTraject0ry<World>>::plugin() const {
return plugin_;
}