Kaydet (Commit) d48cf244 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

loplugin:useuniqueptr in connectivity/source/drivers/macab/

...which revealed that lcl_CFType.cf should rather be of type CFTypeID (i.e.,
unsigned long), and required some adaption of for loops to cope with the type
differences between old sal_Int32 length vars and new std::vector::size calls.

Change-Id: Ic87acbb8b4255627fa976d3615bb319237aa4deb
Reviewed-on: https://gerrit.libreoffice.org/45154Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst ac5e8ce2
...@@ -188,8 +188,6 @@ void MacabRecords::initialize() ...@@ -188,8 +188,6 @@ void MacabRecords::initialize()
MacabRecords::~MacabRecords() MacabRecords::~MacabRecords()
{ {
delete [] lcl_CFTypes;
delete [] requiredProperties;
} }
...@@ -315,26 +313,13 @@ sal_Int32 MacabRecords::getFieldNumber(const OUString& _columnName) const ...@@ -315,26 +313,13 @@ sal_Int32 MacabRecords::getFieldNumber(const OUString& _columnName) const
*/ */
void MacabRecords::bootstrap_CF_types() void MacabRecords::bootstrap_CF_types()
{ {
lcl_CFTypesLength = 6; lcl_CFTypes = {
lcl_CFTypes = new lcl_CFType[lcl_CFTypesLength]; {CFNumberGetTypeID(), kABIntegerProperty},
{CFStringGetTypeID(), kABStringProperty},
lcl_CFTypes[0].cf = CFNumberGetTypeID(); {CFDateGetTypeID(), kABDateProperty},
lcl_CFTypes[0].ab = kABIntegerProperty; {CFArrayGetTypeID(), kABArrayProperty},
{CFDictionaryGetTypeID(), kABDictionaryProperty},
lcl_CFTypes[1].cf = CFStringGetTypeID(); {CFDataGetTypeID(), kABDataProperty}};
lcl_CFTypes[1].ab = kABStringProperty;
lcl_CFTypes[2].cf = CFDateGetTypeID();
lcl_CFTypes[2].ab = kABDateProperty;
lcl_CFTypes[3].cf = CFArrayGetTypeID();
lcl_CFTypes[3].ab = kABArrayProperty;
lcl_CFTypes[4].cf = CFDictionaryGetTypeID();
lcl_CFTypes[4].ab = kABDictionaryProperty;
lcl_CFTypes[5].cf = CFDataGetTypeID();
lcl_CFTypes[5].ab = kABDataProperty;
} }
...@@ -344,15 +329,9 @@ void MacabRecords::bootstrap_CF_types() ...@@ -344,15 +329,9 @@ void MacabRecords::bootstrap_CF_types()
*/ */
void MacabRecords::bootstrap_requiredProperties() void MacabRecords::bootstrap_requiredProperties()
{ {
numRequiredProperties = 7; requiredProperties = {
requiredProperties = new CFStringRef[numRequiredProperties]; kABTitleProperty, kABFirstNameProperty, kABLastNameProperty, kABOrganizationProperty,
requiredProperties[0] = kABTitleProperty; kABAddressProperty, kABPhoneProperty, kABEmailProperty};
requiredProperties[1] = kABFirstNameProperty;
requiredProperties[2] = kABLastNameProperty;
requiredProperties[3] = kABOrganizationProperty;
requiredProperties[4] = kABAddressProperty;
requiredProperties[5] = kABPhoneProperty;
requiredProperties[6] = kABEmailProperty;
} }
...@@ -384,12 +363,12 @@ MacabHeader *MacabRecords::createHeaderForRecordType(const CFArrayRef _records, ...@@ -384,12 +363,12 @@ MacabHeader *MacabRecords::createHeaderForRecordType(const CFArrayRef _records,
CFStringRef *nonRequiredProperties; CFStringRef *nonRequiredProperties;
sal_Int32 numRecords = (sal_Int32) CFArrayGetCount(_records); sal_Int32 numRecords = (sal_Int32) CFArrayGetCount(_records);
sal_Int32 numProperties = (sal_Int32) CFArrayGetCount(allProperties); sal_Int32 numProperties = (sal_Int32) CFArrayGetCount(allProperties);
sal_Int32 numNonRequiredProperties = numProperties - numRequiredProperties; sal_Int32 numNonRequiredProperties = numProperties - requiredProperties.size();
/* While searching through the properties for required properties, these /* While searching through the properties for required properties, these
* sal_Bools will keep track of what we have found. * sal_Bools will keep track of what we have found.
*/ */
bool bFoundRequiredProperties[numRequiredProperties]; bool bFoundRequiredProperties[requiredProperties.size()];
/* We have three MacabHeaders: headerDataForProperty is where we /* We have three MacabHeaders: headerDataForProperty is where we
...@@ -404,7 +383,7 @@ MacabHeader *MacabRecords::createHeaderForRecordType(const CFArrayRef _records, ...@@ -404,7 +383,7 @@ MacabHeader *MacabRecords::createHeaderForRecordType(const CFArrayRef _records,
MacabHeader *nonRequiredHeader = new MacabHeader(); MacabHeader *nonRequiredHeader = new MacabHeader();
/* Other variables... */ /* Other variables... */
sal_Int32 i, j, k; sal_Int32 k;
ABRecordRef record; ABRecordRef record;
CFStringRef property; CFStringRef property;
...@@ -412,15 +391,15 @@ MacabHeader *MacabRecords::createHeaderForRecordType(const CFArrayRef _records, ...@@ -412,15 +391,15 @@ MacabHeader *MacabRecords::createHeaderForRecordType(const CFArrayRef _records,
/* Allocate and initialize... */ /* Allocate and initialize... */
nonRequiredProperties = new CFStringRef[numNonRequiredProperties]; nonRequiredProperties = new CFStringRef[numNonRequiredProperties];
k = 0; k = 0;
for(i = 0; i < numRequiredProperties; i++) for(std::vector<CFStringRef>::size_type i = 0; i < requiredProperties.size(); i++)
bFoundRequiredProperties[i] = false; bFoundRequiredProperties[i] = false;
/* Determine the non-required properties... */ /* Determine the non-required properties... */
for(i = 0; i < numProperties; i++) for(sal_Int32 i = 0; i < numProperties; i++)
{ {
bool bFoundProperty = false; bool bFoundProperty = false;
property = static_cast<CFStringRef>(CFArrayGetValueAtIndex(allProperties, i)); property = static_cast<CFStringRef>(CFArrayGetValueAtIndex(allProperties, i));
for(j = 0; j < numRequiredProperties; j++) for(std::vector<CFStringRef>::size_type j = 0; j < requiredProperties.size(); j++)
{ {
if(CFEqual(property, requiredProperties[j])) if(CFEqual(property, requiredProperties[j]))
{ {
...@@ -449,7 +428,7 @@ MacabHeader *MacabRecords::createHeaderForRecordType(const CFArrayRef _records, ...@@ -449,7 +428,7 @@ MacabHeader *MacabRecords::createHeaderForRecordType(const CFArrayRef _records,
OSL_ENSURE(k == numNonRequiredProperties, "MacabRecords::createHeaderForRecordType: Found an unexpected number of non-required properties"); OSL_ENSURE(k == numNonRequiredProperties, "MacabRecords::createHeaderForRecordType: Found an unexpected number of non-required properties");
/* Fill the header with required properties first... */ /* Fill the header with required properties first... */
for(i = 0; i < numRequiredProperties; i++) for(std::vector<CFStringRef>::size_type i = 0; i < requiredProperties.size(); i++)
{ {
if(bFoundRequiredProperties[i]) if(bFoundRequiredProperties[i])
{ {
...@@ -464,7 +443,7 @@ MacabHeader *MacabRecords::createHeaderForRecordType(const CFArrayRef _records, ...@@ -464,7 +443,7 @@ MacabHeader *MacabRecords::createHeaderForRecordType(const CFArrayRef _records,
* e-mail addresses for one of her or his contacts, and we need to * e-mail addresses for one of her or his contacts, and we need to
* get all of them. * get all of them.
*/ */
for(j = 0; j < numRecords; j++) for(sal_Int32 j = 0; j < numRecords; j++)
{ {
record = const_cast<ABRecordRef>(CFArrayGetValueAtIndex(_records, j)); record = const_cast<ABRecordRef>(CFArrayGetValueAtIndex(_records, j));
headerDataForProperty = createHeaderForProperty(record,requiredProperties[i],_recordType,true); headerDataForProperty = createHeaderForProperty(record,requiredProperties[i],_recordType,true);
...@@ -484,11 +463,11 @@ MacabHeader *MacabRecords::createHeaderForRecordType(const CFArrayRef _records, ...@@ -484,11 +463,11 @@ MacabHeader *MacabRecords::createHeaderForRecordType(const CFArrayRef _records,
} }
/* And now, non-required properties... */ /* And now, non-required properties... */
for(i = 0; i < numRecords; i++) for(sal_Int32 i = 0; i < numRecords; i++)
{ {
record = const_cast<ABRecordRef>(CFArrayGetValueAtIndex(_records, i)); record = const_cast<ABRecordRef>(CFArrayGetValueAtIndex(_records, i));
for(j = 0; j < numNonRequiredProperties; j++) for(sal_Int32 j = 0; j < numNonRequiredProperties; j++)
{ {
property = nonRequiredProperties[j]; property = nonRequiredProperties[j];
headerDataForProperty = createHeaderForProperty(record,property,_recordType,false); headerDataForProperty = createHeaderForProperty(record,property,_recordType,false);
...@@ -1115,13 +1094,12 @@ void MacabRecords::insertPropertyIntoMacabRecord(const ABPropertyType _propertyT ...@@ -1115,13 +1094,12 @@ void MacabRecords::insertPropertyIntoMacabRecord(const ABPropertyType _propertyT
ABPropertyType MacabRecords::getABTypeFromCFType(const CFTypeID cf_type ) const ABPropertyType MacabRecords::getABTypeFromCFType(const CFTypeID cf_type ) const
{ {
sal_Int32 i; for(auto const & i: lcl_CFTypes)
for(i = 0; i < lcl_CFTypesLength; i++)
{ {
/* A match! */ /* A match! */
if(lcl_CFTypes[i].cf == (sal_Int32) cf_type) if(i.cf == cf_type)
{ {
return (ABPropertyType) lcl_CFTypes[i].ab; return (ABPropertyType) i.ab;
} }
} }
return kABErrorInProperty; return kABErrorInProperty;
......
...@@ -20,6 +20,10 @@ ...@@ -20,6 +20,10 @@
#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRECORDS_HXX #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRECORDS_HXX
#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRECORDS_HXX #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MACAB_MACABRECORDS_HXX
#include <sal/config.h>
#include <vector>
#include "MacabRecord.hxx" #include "MacabRecord.hxx"
#include "MacabHeader.hxx" #include "MacabHeader.hxx"
...@@ -37,7 +41,7 @@ namespace connectivity ...@@ -37,7 +41,7 @@ namespace connectivity
* types to Address Book types). * types to Address Book types).
*/ */
struct lcl_CFType { struct lcl_CFType {
sal_Int32 cf; CFTypeID cf;
sal_Int32 ab; sal_Int32 ab;
}; };
...@@ -56,12 +60,10 @@ namespace connectivity ...@@ -56,12 +60,10 @@ namespace connectivity
OUString m_sName; OUString m_sName;
/* For converting CF types to AB types */ /* For converting CF types to AB types */
sal_Int32 lcl_CFTypesLength; std::vector<lcl_CFType> lcl_CFTypes;
lcl_CFType *lcl_CFTypes;
/* For required properties */ /* For required properties */
CFStringRef *requiredProperties; std::vector<CFStringRef> requiredProperties;
sal_Int32 numRequiredProperties;
private: private:
/* All of the private methods are for creating a MacabHeader or a /* All of the private methods are for creating a MacabHeader or a
......
...@@ -54,18 +54,16 @@ MacabComplexOrder::MacabComplexOrder() ...@@ -54,18 +54,16 @@ MacabComplexOrder::MacabComplexOrder()
MacabComplexOrder::~MacabComplexOrder() MacabComplexOrder::~MacabComplexOrder()
{ {
for (auto p: m_aOrders)
delete p;
} }
void MacabComplexOrder::addOrder(MacabOrder *pOrder) void MacabComplexOrder::addOrder(MacabOrder *pOrder)
{ {
m_aOrders.push_back(pOrder); m_aOrders.emplace_back(pOrder);
} }
sal_Int32 MacabComplexOrder::compare(const MacabRecord *record1, const MacabRecord *record2) const sal_Int32 MacabComplexOrder::compare(const MacabRecord *record1, const MacabRecord *record2) const
{ {
for (auto p: m_aOrders) for (auto const & p: m_aOrders)
{ {
sal_Int32 result = p->compare(record1, record2); sal_Int32 result = p->compare(record1, record2);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "MacabHeader.hxx" #include "MacabHeader.hxx"
#include "MacabRecord.hxx" #include "MacabRecord.hxx"
#include <memory>
#include <vector> #include <vector>
namespace connectivity namespace connectivity
...@@ -51,7 +52,7 @@ namespace connectivity ...@@ -51,7 +52,7 @@ namespace connectivity
class MacabComplexOrder : public MacabOrder class MacabComplexOrder : public MacabOrder
{ {
std::vector<MacabOrder *> m_aOrders; std::vector<std::unique_ptr<MacabOrder>> m_aOrders;
public: public:
MacabComplexOrder(); MacabComplexOrder();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment