Program Listing for File Log.hpp

Return to documentation for file (/tmp/ws/src/rmf_task/rmf_task/include/rmf_task/Log.hpp)

/*
 * Copyright (C) 2021 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_TASK__LOG_HPP
#define RMF_TASK__LOG_HPP

#include <rmf_utils/impl_ptr.hpp>

#include <functional>
#include <memory>
#include <string>

#include <rmf_traffic/Time.hpp>

namespace rmf_task {

class Log;
using ConstLogPtr = std::shared_ptr<const Log>;

//==============================================================================
class Log
{
public:
  // Inner class declarations. See below for their definitions.
  class Entry;
  class View;
  class Reader;

  enum class Tier : uint32_t
  {
    Uninitialized = 0,

    Info,

    Warning,

    Error
  };

  Log(std::function<rmf_traffic::Time()> clock = nullptr);

  // TODO(MXG): Should we have a debug log option?

  void info(std::string text);

  void warn(std::string text);

  void error(std::string text);

  void push(Tier tier, std::string text);

  void insert(Log::Entry entry);

  View view() const;

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

//==============================================================================
class Log::Entry
{
public:

  Tier tier() const;

  uint32_t seq() const;

  rmf_traffic::Time time() const;

  const std::string& text() const;

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

//==============================================================================
class Log::View
{
public:
  class Implementation;
private:
  View();
  rmf_utils::impl_ptr<Implementation> _pimpl;
};

//==============================================================================
class Log::Reader
{
public:

  Reader();

  class Iterable;

  Iterable read(const View& view);

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

//==============================================================================
class Log::Reader::Iterable
{
public:

  class iterator;
  using const_iterator = iterator;

  iterator begin() const;

  iterator end() const;

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

//==============================================================================
class Log::Reader::Iterable::iterator
{
public:

  const Entry& operator*() const;

  const Entry* operator->() const;

  iterator& operator++();

  iterator operator++(int);

  bool operator==(const iterator& other) const;

  bool operator!=(const iterator& other) const;

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

} // namespace rmf_task

#endif // RMF_TASK__LOG_HPP