Program Listing for File message_collection.h

Return to documentation for file (/tmp/ws/src/warehouse_ros/include/warehouse_ros/message_collection.h)

// Copyright 2008 Willow Garage, Inc.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//    * Redistributions of source code must retain the above copyright
//      notice, this list of conditions and the following disclaimer.
//
//    * Redistributions in binary form must reproduce the above copyright
//      notice, this list of conditions and the following disclaimer in the
//      documentation and/or other materials provided with the distribution.
//
//    * Neither the name of the Willow Garage, Inc. nor the names of its
//      contributors may be used to endorse or promote products derived from
//      this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#ifndef WAREHOUSE_ROS_MESSAGE_COLLECTION_H
#define WAREHOUSE_ROS_MESSAGE_COLLECTION_H

#include <warehouse_ros/query_results.h>

namespace warehouse_ros
{
class MessageCollectionHelper
{
public:
  virtual bool initialize(const std::string& datatype, const std::string& md5) = 0;
  virtual void insert(char* msg, size_t msg_size, Metadata::ConstPtr metadata) = 0;
  virtual ResultIteratorHelper::Ptr query(Query::ConstPtr query, const std::string& sort_by = "",
                                          bool ascending = true) const = 0;
  virtual unsigned removeMessages(Query::ConstPtr query) = 0;
  virtual void modifyMetadata(Query::ConstPtr q, Metadata::ConstPtr m) = 0;
  virtual unsigned count() = 0;
  virtual Query::Ptr createQuery() const = 0;
  virtual Metadata::Ptr createMetadata() const = 0;
  virtual std::string collectionName() const = 0;
  virtual ~MessageCollectionHelper() = default;

  typedef boost::shared_ptr<MessageCollectionHelper> Ptr;
};

template <class M>
class MessageCollection
{
public:
  MessageCollection(MessageCollectionHelper::Ptr collection);

  MessageCollection() = default;

  void insert(const M& msg, Metadata::Ptr metadata);

  typename QueryResults<M>::range_t query(Query::ConstPtr query, bool metadata_only = false,
                                          const std::string& sort_by = "", bool ascending = true) const;

  std::vector<typename MessageWithMetadata<M>::ConstPtr> queryList(Query::ConstPtr query, bool metadata_only = false,
                                                                   const std::string& sort_by = "",
                                                                   bool ascending = true) const;

  typename MessageWithMetadata<M>::ConstPtr findOne(Query::ConstPtr query, bool metadata_only = false) const;

  unsigned removeMessages(Query::ConstPtr query);

  void modifyMetadata(Query::ConstPtr q, Metadata::ConstPtr m);

  unsigned count();

  bool md5SumMatches() const;

  Query::Ptr createQuery() const;

  Metadata::Ptr createMetadata() const;

  typedef boost::shared_ptr<MessageCollection<M> > Ptr;
  typedef M message_type;

private:
  MessageCollectionHelper::Ptr collection_;
  bool md5sum_matches_ = false;
};

}  // namespace warehouse_ros

#include "impl/message_collection_impl.hpp"

#endif  // include guard