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
00030
00041 namespace mongo_ros
00042 {
00043
00044 using std::vector;
00045 using std::string;
00046
00047 template <class M>
00048 ResultIterator<M>::ResultIterator
00049 (boost::shared_ptr<mongo::DBClientConnection> conn,
00050 const string& ns, const mongo::Query& query,
00051 boost::shared_ptr<mongo::GridFS> gfs,
00052 const bool metadata_only) :
00053 metadata_only_(metadata_only),
00054 cursor_(new Cursor(conn->query(ns, query))),
00055 gfs_(gfs)
00056 {
00057 if ((*cursor_)->more())
00058 next_ = (*cursor_)->nextSafe();
00059 }
00060
00061 template <class M>
00062 ResultIterator<M>::ResultIterator () :
00063 metadata_only_(false)
00064 {
00065 }
00066
00067 template <class M>
00068 ResultIterator<M>::ResultIterator (const ResultIterator<M>& res) :
00069 metadata_only_(res.metadata_only_), cursor_(res.cursor_),
00070 next_(res.next_), gfs_(res.gfs_)
00071 {
00072 }
00073
00074 template <class M>
00075 void ResultIterator<M>::increment ()
00076 {
00077 ROS_ASSERT (next_);
00078 if ((*cursor_)->more())
00079 next_ = (*cursor_)->nextSafe();
00080 else
00081 next_.reset();
00082 }
00083
00084 template <class M>
00085 typename MessageWithMetadata<M>::ConstPtr
00086 ResultIterator<M>::dereference () const
00087 {
00088 ROS_ASSERT (next_);
00089
00090
00091 typename MessageWithMetadata<M>::Ptr m(new MessageWithMetadata<M>(next_->copy()));
00092 if (!metadata_only_)
00093 {
00094 mongo::OID blob_id;
00095 (*next_)["blob_id"].Val(blob_id);
00096 mongo::BSONObj q = BSON ("_id" << blob_id);
00097 mongo::GridFile f = gfs_->findFile(q);
00098 ROS_ASSERT(f.exists());
00099 std::stringstream ss (std::ios_base::out);
00100 f.write(ss);
00101 std::string str = ss.str();
00102
00103 uint8_t* buf = (uint8_t*) str.c_str();
00104 ros::serialization::IStream istream(buf, str.size());
00105 ros::serialization::Serializer<M>::read(istream, *m);
00106 }
00107
00108 return m;
00109 }
00110
00111 template <class M>
00112 bool ResultIterator<M>::equal (const ResultIterator<M>& other) const
00113 {
00114
00115 if (next_ && other.next_)
00116 ROS_WARN ("Unexpected case of equality check of two not-past-the-end "
00117 "iterators in ResultIterator");
00118 return (!next_ && !other.next_);
00119 }
00120
00121
00122 }