22 #include "computable.h" 26 using namespace mongo;
43 Query query_to_compute,
44 std::string collection,
45 const boost::function<std::list<BSONObj>(BSONObj, std::string)> &compute_function,
49 this->compute_function = compute_function;
50 this->query_to_compute = query_to_compute;
51 this->collection = collection;
53 this->caching_time = (int)(caching_time * 1000.0);
54 this->priority = priority;
57 Computable::~Computable()
70 std::list<BSONObj> docs = compute_function(query, collection);
71 long long milliseconds_since_epoch =
72 std::chrono::system_clock::now().time_since_epoch() / std::chrono::milliseconds(1);
73 long long cached_until = milliseconds_since_epoch + caching_time;
75 for (BSONObj &obj : docs) {
76 BSONObjBuilder info_b;
77 info_b.append(
"computed",
true);
78 info_b.append(
"cached_until", cached_until);
80 obj_b.appendElements(obj);
81 obj_b.append(
"_robmem_info", info_b.obj());
95 return query_to_compute;
int get_priority()
Gets the priority of the computable.
std::list< mongo::BSONObj > compute(mongo::BSONObj query)
Compute demanded information and insert it into the robot memory.
mongo::Query get_query()
Gets the query that defines what information is computed by the Computable.
Computable(mongo::Query query_to_compute, std::string collection, const boost::function< std::list< mongo::BSONObj >(mongo::BSONObj, std::string)> &compute_function, double caching_time=0.0, int priority=0)
Constructor for object holding information about a computable.
std::string get_collection()
Gets the collection the computable adds information to.