MojErr MojDbSearchCursor::loadIds(ObjectSet& idsOut) { LOG_TRACE("Entering function %s", __FUNCTION__); MojUInt32 groupNum = 0; bool found = false; MojSharedPtr<ObjectSet> group; GroupMap groupMap; for(;;) { // get current id MojObject id; MojUInt32 idGroupNum = 0; MojErr err = m_storageQuery->getId(id, idGroupNum, found); MojErrCheck(err); if (!found) break; // if it is in a new group, create a new set if (!group.get() || idGroupNum != groupNum) { // find/create new group GroupMap::Iterator iter; err = groupMap.find(idGroupNum, iter); MojErrCheck(err); if (iter != groupMap.end()) { group = iter.value(); } else { err = group.resetChecked(new ObjectSet); MojErrCheck(err); err = groupMap.put(idGroupNum, group); MojErrCheck(err); } groupNum = idGroupNum; } // add id to current set err = group->put(id); MojErrCheck(err); } // no matches unless all groups are accounted for MojUInt32 groupCount = m_storageQuery->groupCount(); for (MojUInt32 i = 0; i < groupCount; ++i) { if (!groupMap.contains(i)) return MojErrNone; } // find intersection of all groups GroupMap::ConstIterator begin = groupMap.begin(); for (GroupMap::ConstIterator i = begin; i != groupMap.end(); ++i) { if (i == begin) { // special handling for first group idsOut = *(i.value()); } else { MojErr err = idsOut.intersect(*(i.value())); MojErrCheck(err); } } return MojErrNone; }
MojDbLevelTableTxn &MojDbLevelEnvTxn::tableTxn(leveldb::DB *db) { // find within opened already for(TableTxns::iterator it = m_tableTxns.begin(); it != m_tableTxns.end(); ++it) { if ((*it)->db() == db) return *(*it); } // create new MojSharedPtr<MojDbLevelTableTxn> txn; txn.reset(new MojDbLevelTableTxn()); txn->begin(db); m_tableTxns.push_back(txn); return *txn; }
static MojErr takeFooShared(MojSharedPtr<FooTest> p) { MojTestAssert(p.get()); return MojErrNone; }
static MojSharedPtr<FooTest> makeFooShared() { MojSharedPtr<FooTest> p; (void) p.reset(new FooTest); return p; }