view.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2008, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of Willow Garage, Inc. nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 #ifndef ROSBAG_VIEW_H
00036 #define ROSBAG_VIEW_H
00037 
00038 #include <boost/function.hpp>
00039 #include <boost/iterator/iterator_facade.hpp>
00040 
00041 #include "rosbag/message_instance.h"
00042 #include "rosbag/query.h"
00043 #include "rosbag/macros.h"
00044 
00045 namespace rosbag {
00046 
00047 struct MessageRange;
00048 struct IndexEntry;
00049 struct ViewIterHelper;
00050 
00051 class ROSBAG_DECL View
00052 {
00053     friend class Bag;
00054 
00055 public:
00057 
00063     class iterator : public boost::iterator_facade<iterator,
00064                                                    MessageInstance,
00065                                                    boost::forward_traversal_tag>
00066     {
00067     public:
00068         iterator(iterator const& i);
00069         iterator();
00070         ~iterator();
00071 
00072     protected:
00073         iterator(View* view, bool end = false);
00074 
00075     private:
00076         friend class View;
00077         friend class boost::iterator_core_access;
00078 
00079                 void populate();
00080                 void populateSeek(std::multiset<IndexEntry>::const_iterator iter);
00081 
00082         bool equal(iterator const& other) const;
00083 
00084         void increment();
00085 
00086         MessageInstance& dereference() const;
00087 
00088     private:
00089         View* view_;
00090         std::vector<ViewIterHelper> iters_;
00091         uint32_t view_revision_;
00092         mutable MessageInstance* message_instance_;
00093     };
00094 
00095     typedef iterator const_iterator;
00096 
00097     struct TrueQuery {
00098         bool operator()(ConnectionInfo const*) const { return true; };
00099     };
00100 
00102 
00105     View(bool const& reduce_overlap = false);
00106 
00108 
00114     View(Bag const& bag, ros::Time const& start_time = ros::TIME_MIN, ros::Time const& end_time = ros::TIME_MAX, bool const& reduce_overlap = false);
00115 
00117 
00124     View(Bag const& bag, boost::function<bool(ConnectionInfo const*)> query,
00125          ros::Time const& start_time = ros::TIME_MIN, ros::Time const& end_time = ros::TIME_MAX, bool const& reduce_overlap = false);
00126 
00127     ~View();
00128 
00129     iterator begin();
00130     iterator end();
00131     uint32_t size();
00132 
00134 
00139     void addQuery(Bag const& bag, ros::Time const& start_time = ros::TIME_MIN, ros::Time const& end_time = ros::TIME_MAX);
00140 
00142 
00148     void addQuery(Bag const& bag, boost::function<bool(ConnectionInfo const*)> query,
00149                       ros::Time const& start_time = ros::TIME_MIN, ros::Time const& end_time = ros::TIME_MAX);
00150 
00151     std::vector<const ConnectionInfo*> getConnections();
00152 
00153     ros::Time getBeginTime();
00154     ros::Time getEndTime();
00155   
00156 protected:
00157     friend class iterator;
00158 
00159     void updateQueries(BagQuery* q);
00160     void update();
00161 
00162     MessageInstance* newMessageInstance(ConnectionInfo const* connection_info, IndexEntry const& index, Bag const& bag);
00163 
00164 private:
00165     View(View const& view);
00166     View& operator=(View const& view);
00167 
00168 protected:
00169     std::vector<MessageRange*> ranges_;
00170     std::vector<BagQuery*>     queries_;
00171     uint32_t                   view_revision_;
00172 
00173     uint32_t size_cache_;
00174     uint32_t size_revision_;
00175 
00176     bool reduce_overlap_;
00177 };
00178 
00179 } // namespace rosbag
00180 
00181 #endif


rosbag
Author(s): Tim Field, Jeremy Leibs, James Bowman
autogenerated on Mon Oct 6 2014 11:47:09