query.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009, Willow Garage, Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of Willow Garage, Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived from
14 // this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 // POSSIBILITY OF SUCH DAMAGE.
27 
28 #include "rosbag/query.h"
29 #include "rosbag/bag.h"
30 
31 #include <boost/foreach.hpp>
32 
33 #define foreach BOOST_FOREACH
34 
35 using std::map;
36 using std::string;
37 using std::vector;
38 using std::multiset;
39 
40 namespace rosbag {
41 
42 // Query
43 
44 Query::Query(boost::function<bool(ConnectionInfo const*)>& query, ros::Time const& start_time, ros::Time const& end_time)
45  : query_(query), start_time_(start_time), end_time_(end_time)
46 {
47 }
48 
49 boost::function<bool(ConnectionInfo const*)> const& Query::getQuery() const {
50  return query_;
51 }
52 
53 ros::Time const& Query::getStartTime() const { return start_time_; }
54 ros::Time const& Query::getEndTime() const { return end_time_; }
55 
56 // TopicQuery
57 
58 TopicQuery::TopicQuery(std::string const& topic) {
59  topics_.push_back(topic);
60 }
61 
62 TopicQuery::TopicQuery(std::vector<std::string> const& topics) : topics_(topics) { }
63 
64 bool TopicQuery::operator()(ConnectionInfo const* info) const {
65  foreach(string const& topic, topics_)
66  if (topic == info->topic)
67  return true;
68 
69  return false;
70 }
71 
72 // TypeQuery
73 
74 TypeQuery::TypeQuery(std::string const& type) {
75  types_.push_back(type);
76 }
77 
78 TypeQuery::TypeQuery(std::vector<std::string> const& types) : types_(types) { }
79 
80 bool TypeQuery::operator()(ConnectionInfo const* info) const {
81  foreach(string const& type, types_)
82  if (type == info->datatype)
83  return true;
84 
85  return false;
86 }
87 
88 // BagQuery
89 
90 BagQuery::BagQuery(Bag const* _bag, Query const& _query, uint32_t _bag_revision) : bag(_bag), query(_query), bag_revision(_bag_revision) {
91 }
92 
93 // MessageRange
94 
95 MessageRange::MessageRange(std::multiset<IndexEntry>::const_iterator const& _begin,
96  std::multiset<IndexEntry>::const_iterator const& _end,
97  ConnectionInfo const* _connection_info,
98  BagQuery const* _bag_query)
99  : begin(_begin), end(_end), connection_info(_connection_info), bag_query(_bag_query)
100 {
101 }
102 
103 // ViewIterHelper
104 
105 ViewIterHelper::ViewIterHelper(std::multiset<IndexEntry>::const_iterator _iter, MessageRange const* _range)
106  : iter(_iter), range(_range)
107 {
108 }
109 
111  return (a.iter)->time > (b.iter)->time;
112 }
113 
114 } // namespace rosbag
boost::function< bool(ConnectionInfo const *)> const & getQuery() const
Get the query functor.
Definition: query.cpp:49
bool operator()(ConnectionInfo const *) const
Definition: query.cpp:80
TypeQuery(std::string const &type)
Definition: query.cpp:74
bool operator()(ViewIterHelper const &a, ViewIterHelper const &b)
Definition: query.cpp:110
boost::function< bool(ConnectionInfo const *)> query_
Definition: query.h:70
The actual iterator data structure.
Definition: query.h:123
std::vector< std::string > topics_
Definition: query.h:84
ViewIterHelper(std::multiset< IndexEntry >::const_iterator _iter, MessageRange const *_range)
Definition: query.cpp:105
std::vector< std::string > types_
Definition: query.h:96
bool operator()(ConnectionInfo const *) const
Definition: query.cpp:64
MessageRange(std::multiset< IndexEntry >::const_iterator const &_begin, std::multiset< IndexEntry >::const_iterator const &_end, ConnectionInfo const *_connection_info, BagQuery const *_bag_query)
Definition: query.cpp:95
ros::Time start_time_
Definition: query.h:71
BagQuery(Bag const *_bag, Query const &_query, uint32_t _bag_revision)
Definition: query.cpp:90
std::multiset< IndexEntry >::const_iterator iter
Definition: query.h:127
ros::Time const & getStartTime() const
Get the start-time.
Definition: query.cpp:53
ros::Time end_time_
Definition: query.h:72
Pairs of queries and the bags they come from (used internally by View)
Definition: query.h:100
ros::Time const & getEndTime() const
Get the end-time.
Definition: query.cpp:54
std::string datatype
Definition: structures.h:53
Definition: bag.h:78
Query(boost::function< bool(ConnectionInfo const *)> &query, ros::Time const &start_time=ros::TIME_MIN, ros::Time const &end_time=ros::TIME_MAX)
The base query takes an optional time-range.
Definition: query.cpp:44
TopicQuery(std::string const &topic)
Definition: query.cpp:58


rosbag_storage
Author(s):
autogenerated on Sun Feb 3 2019 03:29:47