Program Listing for File Query.hpp

Return to documentation for file (/tmp/ws/src/rmf_traffic/rmf_traffic/include/rmf_traffic/schedule/Query.hpp)

/*
 * Copyright (C) 2019 Open Source Robotics Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/

#ifndef RMF_TRAFFIC__SCHEDULE__QUERY_HPP
#define RMF_TRAFFIC__SCHEDULE__QUERY_HPP

#include <rmf_traffic/detail/bidirectional_iterator.hpp>

#include <rmf_traffic/schedule/Version.hpp>
#include <rmf_traffic/schedule/Participant.hpp>

#include <rmf_traffic/Region.hpp>
#include <rmf_traffic/Time.hpp>

#include <rmf_utils/impl_ptr.hpp>

#include <unordered_set>
#include <vector>

namespace rmf_traffic {
namespace schedule {

//==============================================================================
class Query
{
public:

  template<typename E, typename I, typename F>
  using base_iterator = rmf_traffic::detail::bidirectional_iterator<E, I, F>;

  class Spacetime
  {
  public:

    using Space = geometry::Space;

    enum class Mode : uint16_t
    {
      Invalid,

      All,

      Regions,

      Timespan,
    };

    //==========================================================================
    class All
    {
    public:

      class Implementation;
    private:
      rmf_utils::impl_ptr<Implementation> _pimpl;
    };

    //==========================================================================
    class Regions
    {
    public:

      class IterImpl;
      using iterator = base_iterator<Region, IterImpl, Regions>;
      using const_iterator = base_iterator<const Region, IterImpl, Regions>;

      void push_back(Region region);

      void pop_back();

      iterator erase(iterator it);

      iterator erase(iterator first, iterator last);

      iterator begin();

      const_iterator begin() const;

      const_iterator cbegin() const;

      iterator end();

      const_iterator end() const;

      const_iterator cend() const;

      std::size_t size() const;

      class Implementation;
    private:
      Regions();
      rmf_utils::impl_ptr<Implementation> _pimpl;
    };

    //==========================================================================
    class Timespan
    {
    public:

      const std::unordered_set<std::string>& maps() const;

      Timespan& add_map(std::string map_name);

      Timespan& remove_map(const std::string& map_name);

      Timespan& clear_maps();

      bool all_maps() const;

      Timespan& all_maps(bool query_all_maps);

      const Time* get_lower_time_bound() const;

      Timespan& set_lower_time_bound(Time time);

      Timespan& remove_lower_time_bound();

      const Time* get_upper_time_bound() const;

      Timespan& set_upper_time_bound(Time time);

      Timespan& remove_upper_time_bound();

      class Implementation;
    private:
      Timespan();
      rmf_utils::impl_ptr<Implementation> _pimpl;
    };

    Spacetime();

    Spacetime(std::vector<Region> regions);

    Spacetime(std::vector<std::string> maps);

    Spacetime(
      std::vector<std::string> maps,
      Time lower_bound);

    Spacetime(
      std::vector<std::string> maps,
      Time lower_bound,
      Time upper_bound);

    Mode get_mode() const;

    All& query_all();

    Regions& query_regions(std::vector<Region> regions = {});

    Regions* regions();

    const Regions* regions() const;

    Timespan& query_timespan(
      std::vector<std::string> maps,
      Time lower_bound,
      Time upper_bound);

    Timespan& query_timespan(
      std::vector<std::string> maps,
      Time lower_bound);

    Timespan& query_timespan(std::vector<std::string> maps);

    Timespan& query_timespan(bool query_all_maps = true);

    Timespan* timespan();

    const Timespan* timespan() const;

    class Implementation;
  private:
    rmf_utils::impl_ptr<Implementation> _pimpl;
  };

  class Participants
  {
  public:

    enum class Mode : uint16_t
    {
      Invalid,

      All,

      Include,

      Exclude
    };

    class All
    {
    public:

      class Implementation;
    private:
      All();
      friend class Participants;
      rmf_utils::impl_ptr<Implementation> _pimpl;
    };

    class Include
    {
    public:

      Include(std::vector<ParticipantId> ids);

      // TODO(MXG): Consider returning unordered_set
      const std::vector<ParticipantId>& get_ids() const;

      Include& set_ids(std::vector<ParticipantId> ids);

      class Implementation;
    private:
      Include();
      friend class Participants;
      rmf_utils::impl_ptr<Implementation> _pimpl;
    };

    class Exclude
    {
    public:

      Exclude(std::vector<ParticipantId> ids);

      // TODO(MXG): Consider returning unordered_set
      const std::vector<ParticipantId>& get_ids() const;

      Exclude& set_ids(std::vector<ParticipantId> ids);

      class Implementation;
    private:
      Exclude();
      friend class Participants;
      rmf_utils::impl_ptr<Implementation> _pimpl;
    };

    Participants();

    static const Participants& make_all();

    static Participants make_only(std::vector<ParticipantId> ids);

    static Participants make_all_except(std::vector<ParticipantId> ids);

    Mode get_mode() const;

    All* all();

    const All* all() const;

    Include* include();

    const Include* include() const;

    Participants& include(std::vector<ParticipantId> ids);

    Exclude* exclude();

    const Exclude* exclude() const;

    Participants& exclude(std::vector<ParticipantId> ids);

  private:
    class Implementation;
    rmf_utils::impl_ptr<Implementation> _pimpl;
  };

  Spacetime& spacetime();

  const Spacetime& spacetime() const;

  Participants& participants();

  const Participants& participants() const;

  class Implementation;
private:
  Query();
  rmf_utils::impl_ptr<Implementation> _pimpl;
};

//==============================================================================
Query query_all();

//==============================================================================
Query make_query(
  std::vector<Region> regions);

//==============================================================================
Query make_query(
  std::vector<std::string> maps,
  const Time* start_time,
  const Time* finish_time);

//==============================================================================
bool operator==(
  const Query& lhs,
  const Query& rhs);

//==============================================================================
bool operator!=(
  const Query& lhs,
  const Query& rhs);

} // namespace schedule

namespace detail {

extern template class bidirectional_iterator<
    Region,
    schedule::Query::Spacetime::Regions::IterImpl,
    schedule::Query::Spacetime::Regions
>;

extern template class bidirectional_iterator<
    const Region,
    schedule::Query::Spacetime::Regions::IterImpl,
    schedule::Query::Spacetime::Regions
>;

} // namespace detail
} // namespace rmf_traffic

#endif // RMF_TRAFFIC__SCHEDULE__QUERY_HPP