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
00039 #ifndef MONGO_ROS_MESSAGE_COLLECTION_H
00040 #define MONGO_ROS_MESSAGE_COLLECTION_H
00041
00042 #include <mongo_ros/query_results.h>
00043 #include <ros/ros.h>
00044
00045 namespace mongo_ros
00046 {
00047
00051 template <class M>
00052 class MessageCollection
00053 {
00054 public:
00055
00062 MessageCollection (const std::string& db_name,
00063 const std::string& collection_name,
00064 const std::string& db_host="",
00065 const unsigned db_port=0);
00066
00075 void insert (const M& msg, const Metadata& metadata = Metadata());
00076
00081 typename QueryResults<M>::range_t
00082 queryResults (const mongo::BSONObj& query, bool metadata_only = false,
00083 const std::string& sort_by = "", bool ascending=true) const;
00084
00086 typename QueryResults<M>::range_t
00087 queryResults (const mongo::Query& query, bool metadata_only = false) const;
00088
00091 std::vector<typename MessageWithMetadata<M>::ConstPtr >
00092 pullAllResults (const mongo::BSONObj& query, bool metadata_only = false,
00093 const std::string& sort_by = "", bool ascending=true) const;
00094
00095
00099 typename MessageWithMetadata<M>::ConstPtr
00100 findOne (const Query& query, bool metadata_only = false) const;
00101
00103 unsigned removeMessages (const mongo::BSONObj& query);
00104
00107 MessageCollection& ensureIndex (const std::string& field);
00108
00113 void modifyMetadata (const Query& q, const Metadata& m);
00114
00116 unsigned count ();
00117
00118 private:
00119
00120
00121 void initialize (const std::string& db, const std::string& coll,
00122 const std::string& host, unsigned port);
00123
00124 const std::string ns_;
00125 boost::shared_ptr<mongo::DBClientConnection> conn_;
00126 boost::shared_ptr<mongo::GridFS> gfs_;
00127 ros::NodeHandle nh_;
00128 ros::Publisher insertion_pub_;
00129 };
00130
00131
00132 }
00133
00134 #include "../../src/message_collection_impl.h"
00135
00136 #endif // include guard