Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <rosmatlab/rosbag/query.h>
00030
00031 #include <rosmatlab/options.h>
00032 #include <rosmatlab/connection_header.h>
00033 #include <rosmatlab/conversion.h>
00034 #include <rosmatlab/log.h>
00035
00036 #include <ros/forwards.h>
00037 #include <rosbag/structures.h>
00038
00039 #include <introspection/message.h>
00040
00041 #include <boost/algorithm/string/replace.hpp>
00042
00043
00044 namespace rosmatlab {
00045 namespace rosbag {
00046
00047 Query::Query()
00048 : start_time_(ros::TIME_MIN)
00049 , end_time_(ros::TIME_MAX)
00050 {
00051 }
00052
00053 Query::Query(int nrhs, const mxArray *prhs[])
00054 : start_time_(ros::TIME_MIN)
00055 , end_time_(ros::TIME_MAX)
00056 {
00057 init(Options(nrhs, prhs, true));
00058 }
00059
00060 Query::Query(const Options &options)
00061 : start_time_(ros::TIME_MIN)
00062 , end_time_(ros::TIME_MAX)
00063 {
00064 init(options);
00065 }
00066
00067 Query::Query(const std::string &topic)
00068 : start_time_(ros::TIME_MIN)
00069 , end_time_(ros::TIME_MAX)
00070 {
00071 topics_.insert(topic);
00072 }
00073
00074 Query::~Query()
00075 {
00076 }
00077
00078 void Query::init(const Options &options)
00079 {
00080 if (options.hasKey("start")) start_time_ = ros::Time(options.getDouble("start"));
00081 if (options.hasKey("stop")) end_time_ = ros::Time(options.getDouble("stop"));
00082 if (options.hasKey("topic")) topics_.insert(options.getStrings("topic").begin(), options.getStrings("topic").end());
00083 if (options.hasKey("datatype")) datatypes_.insert(options.getStrings("datatype").begin(), options.getStrings("datatype").end());
00084 if (options.hasKey("md5sum")) md5sums_.insert(options.getStrings("md5sum").begin(), options.getStrings("md5sum").end());
00085
00086
00087 if (options.hasKey("")) topics_.insert(options.getStrings("").begin(), options.getStrings("").end());
00088
00089 options.throwOnUnused();
00090 }
00091
00092 bool Query::operator()(const ConnectionInfo *info)
00093 {
00094 if (topics_.size() > 0 && topics_.count(info->topic) == 0) return false;
00095 if (datatypes_.size() > 0 && datatypes_.count(info->datatype) == 0) return false;
00096 if (md5sums_.size() > 0 && md5sums_.count(info->md5sum) == 0) return false;
00097 return true;
00098 }
00099
00100 ros::Time const& Query::getStartTime() const { return start_time_; }
00101 ros::Time const& Query::getEndTime() const { return end_time_; }
00102
00103 mxArray *Query::toMatlab(const std::vector<boost::shared_ptr<Query> > &queries) {
00104 mxArray *result;
00105 static const char *fieldnames[] = { "Topic", "DataType", "MD5Sum", "StartTime", "EndTime" };
00106 result = mxCreateStructMatrix(queries.size(), 1, 5, fieldnames);
00107
00108 for(mwIndex i = 0; i < queries.size(); ++i) {
00109 const Query &query = *queries[i];
00110
00111 {
00112 mxArray *cell = mxCreateCellMatrix(1, query.topics_.size());
00113 mwIndex j = 0;
00114 for(Filter::const_iterator it = query.topics_.begin(); it != query.topics_.end(); ++it)
00115 mxSetCell(cell, j++, mxCreateString(it->c_str()));
00116 mxSetField(result, i, "Topic", cell);
00117 }
00118
00119 {
00120 mxArray *cell = mxCreateCellMatrix(1, query.datatypes_.size());
00121 mwIndex j = 0;
00122 for(Filter::const_iterator it = query.datatypes_.begin(); it != query.datatypes_.end(); ++it)
00123 mxSetCell(cell, j++, mxCreateString(it->c_str()));
00124 mxSetField(result, i, "DataType", cell);
00125 }
00126
00127 {
00128 mxArray *cell = mxCreateCellMatrix(1, query.md5sums_.size());
00129 mwIndex j = 0;
00130 for(Filter::const_iterator it = query.md5sums_.begin(); it != query.md5sums_.end(); ++it)
00131 mxSetCell(cell, j++, mxCreateString(it->c_str()));
00132 mxSetField(result, i, "MD5Sum", cell);
00133 }
00134
00135 mxSetField(result, i, "StartTime", mxCreateTime(query.getStartTime()));
00136 mxSetField(result, i, "EndTime", mxCreateTime(query.getEndTime()));
00137 }
00138
00139 return result;
00140 }
00141
00142 TopicFilterQuery::TopicFilterQuery(::rosbag::Query& base, const std::string& topic)
00143 : base_(base)
00144 , topic_(topic)
00145 {
00146 }
00147
00148 TopicFilterQuery::~TopicFilterQuery()
00149 {
00150 }
00151
00152 bool TopicFilterQuery::operator()(const ConnectionInfo *info) {
00153 return (base_.getQuery()(info)) && (info->topic == topic_);
00154 }
00155
00156
00157 }
00158 }
00159