diff -r a6d55a2e75be -r 782e3408c2ab contentstorage/caclient/src/caservice.cpp --- a/contentstorage/caclient/src/caservice.cpp Fri Mar 26 13:00:55 2010 +0200 +++ b/contentstorage/caclient/src/caservice.cpp Fri Apr 16 14:45:49 2010 +0300 @@ -103,15 +103,15 @@ \endcode */ -CaEntry *CaService::getEntry(int entryId) const +QSharedPointer CaService::getEntry(int entryId) const { - QList entries = getEntries(QList () << entryId); + QList< QSharedPointer > entries = getEntries(QList () << entryId); if (entries.count()) { // there should be exactly one entry with specified ID if present Q_ASSERT(entries.count() == 1); return entries[0]; } else { - return NULL; + return QSharedPointer(); } } @@ -135,7 +135,7 @@ \endcode */ -QList CaService::getEntries(const QList &entryIdList) const +QList< QSharedPointer > CaService::getEntries(const QList &entryIdList) const { return m_d->getEntries(entryIdList); } @@ -162,7 +162,7 @@ \endcode */ -QList CaService::getEntries(const CaQuery &query) const +QList< QSharedPointer > CaService::getEntries(const CaQuery &query) const { return m_d->getEntries(query); } @@ -216,7 +216,7 @@ ... \endcode */ -CaEntry *CaService::createEntry(const CaEntry &entry) const +QSharedPointer CaService::createEntry(const CaEntry &entry) const { return m_d->createEntry(entry); } @@ -284,15 +284,15 @@ \example \code ... - bool result = service->removeEntries( QList() << newItem ); + bool result = service->removeEntries( QList< QSharedPointer >() << newItem ); \b Output: result == true \endcode */ -bool CaService::removeEntries(const QList &entryList) const +bool CaService::removeEntries(const QList< QSharedPointer > &entryList) const { QList idList; - CaEntry *entry(NULL); + QSharedPointer entry; foreach(entry, entryList) { idList << entry->id(); } @@ -449,10 +449,10 @@ \endcode */ bool CaService::insertEntriesIntoGroup(const CaEntry &group, - const QList &entryList, int beforeEntryId) const + const QList< QSharedPointer > &entryList, int beforeEntryId) const { QList idList; - CaEntry *entry(NULL); + QSharedPointer entry; foreach(entry, entryList) { idList << entry->id(); } @@ -563,10 +563,10 @@ \endcode */ bool CaService::removeEntriesFromGroup(const CaEntry &group, - const QList &entryList) const + const QList< QSharedPointer > &entryList) const { QList idList; - CaEntry *entry(NULL); + QSharedPointer entry; foreach(entry, entryList) { idList << entry->id(); } @@ -681,17 +681,17 @@ itemToAppend.setTypeName( "TypeNameAppend" ); CaEntry * entryToAppend = service->createEntry( itemToAppend ); bool result = service->appendEntriesToGroup( - *newGroup, QList() << entryToAppend ); + *newGroup, QList< QSharedPointer >() << entryToAppend ); ... \b Output: result == true \endcode */ bool CaService::appendEntriesToGroup(const CaEntry &group, - const QList &entryList) const + const QList< QSharedPointer > &entryList) const { QList idList; - CaEntry *entry(NULL); + QSharedPointer entry; foreach(entry, entryList) { idList << entry->id(); } @@ -797,10 +797,10 @@ \endcode */ bool CaService::prependEntriesToGroup(const CaEntry &group, - const QList &entryList) const + const QList< QSharedPointer > &entryList) const { QList idList; - CaEntry *entry(NULL); + QSharedPointer entry; foreach(entry, entryList) { idList << entry->id(); } @@ -831,11 +831,10 @@ { bool result = false; - CaEntry *const temporaryEntry = getEntry(entryId); + const QSharedPointer temporaryEntry = getEntry(entryId); - if (temporaryEntry != NULL) { + if (!temporaryEntry.isNull()) { result = executeCommand(*temporaryEntry, command); - delete temporaryEntry; } return result; } @@ -957,14 +956,14 @@ \param entryIdList list of entry ids \retval list of entries (pointers) */ -QList CaServicePrivate::getEntries(const QList &entryIdList) const +QList< QSharedPointer > CaServicePrivate::getEntries(const QList &entryIdList) const { qDebug() << "CaServicePrivate::getEntries" << "entryIdList:" << entryIdList; CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::getEntries"); - QList resultList; + QList< QSharedPointer > resultList; mErrorCode = mProxy->getData(entryIdList, resultList); @@ -987,9 +986,9 @@ \param query the query information to select specific entries. \param placeholder list of entries for a specific select. */ -QList CaServicePrivate::getEntries(const CaQuery &query) const +QList< QSharedPointer > CaServicePrivate::getEntries(const CaQuery &query) const { - QList resultList; + QList< QSharedPointer > resultList; mErrorCode = mProxy->getData(query, resultList); @@ -1019,36 +1018,29 @@ \param query const reference to entry to copy \retval pointer to newely created copy */ -CaEntry *CaServicePrivate::createEntry(const CaEntry &entry) +QSharedPointer CaServicePrivate::createEntry(const CaEntry &entry) { qDebug() << "CaServicePrivate::createEntry" << "entry id:" << entry.id(); CACLIENTTEST_FUNC_ENTRY("CaServicePrivate::createEntry"); - CaEntry *newEntry = NULL; ErrorCode addDataResult = NoErrorCode; - try { - newEntry = new CaEntry(entry.role()); + QSharedPointer newEntry (new CaEntry(entry.role())); - QScopedPointer entryClone(new CaEntry(entry)); - - const int nonExistingObjectId = 0; - - CaObjectAdapter::setId(*entryClone, nonExistingObjectId); + QScopedPointer entryClone(new CaEntry(entry)); + const int nonExistingObjectId = 0; + CaObjectAdapter::setId(*entryClone, nonExistingObjectId); - addDataResult = - mProxy->addData(*entryClone, *newEntry); - } catch (const std::bad_alloc &) { - addDataResult = OutOfMemoryErrorCode; - } + addDataResult = + mProxy->addData(*entryClone, *newEntry); + // return empty pointer if nothing was added if (addDataResult != NoErrorCode) { - delete newEntry; - newEntry = NULL; + newEntry.clear(); } - + mErrorCode = addDataResult; qDebug() << "CaServicePrivate::createEntry mErrorCode:" << mErrorCode;