From 0ba3f522f3436593412f7112fd5ae984fda07782 Mon Sep 17 00:00:00 2001 From: Oleksandr Kaspruk Date: Fri, 22 Mar 2013 01:25:18 +0900 Subject: [PATCH] Coding idoms applied. isActive functional added. Change-Id: Ie9425f0b099a7a5d2b47f8f18d90157821d31b15 Signed-off-by: Oleksandr Kaspruk --- src/FUixVisionImageFeatureInfo.cpp | 25 +++++++++++-------------- src/FUixVisionImageFeatureManager.cpp | 9 +++++---- src/FUixVisionImageObject.cpp | 13 +++++++++++-- src/FUixVisionImageRecognizer.cpp | 7 ++++--- src/FUixVisionQrCodeGenerator.cpp | 12 +++++++----- src/FUixVisionQrCodeObject.cpp | 5 +++-- src/FUixVisionQrCodeRecognizer.cpp | 16 +++++----------- src/FUixVision_ImageFeatureManagerImpl.cpp | 6 +++--- src/ImageFeatureInfo.h | 5 +++++ 9 files changed, 54 insertions(+), 44 deletions(-) diff --git a/src/FUixVisionImageFeatureInfo.cpp b/src/FUixVisionImageFeatureInfo.cpp index 300cfa9..c7e39ff 100644 --- a/src/FUixVisionImageFeatureInfo.cpp +++ b/src/FUixVisionImageFeatureInfo.cpp @@ -24,13 +24,14 @@ namespace Tizen { namespace Uix { namespace Vision { ImageFeatureInfo::ImageFeatureInfo() - : __pImageFeatureInfoImpl(new _ImageFeatureInfoImpl) + : __pImageFeatureInfoImpl(0) { + std::unique_ptr<_ImageFeatureInfoImpl> pImageFeatureInfoImpl (new (std::nothrow) _ImageFeatureInfoImpl()); + __pImageFeatureInfoImpl = pImageFeatureInfoImpl.release(); } ImageFeatureInfo::~ImageFeatureInfo() { - delete __pImageFeatureInfoImpl; } Tizen::Base::String @@ -42,7 +43,9 @@ ImageFeatureInfo::GetDescription() const //get true length of path to allocate memory length = __pImageFeatureInfoImpl->GetDescription(&ch, 1); if (!length) + { return Tizen::Base::String(""); + } char* pName = new char[length + 1]; @@ -72,32 +75,26 @@ ImageFeatureInfo::GetThumbnailN(void) const int bufWidth = __pImageFeatureInfoImpl->GetThumbnailWidth(); int bufHeight = __pImageFeatureInfoImpl->GetThumbnailHeight(); - if ((bufWidth > 0) && (bufHeight > 0)) + while ((bufWidth > 0) && (bufHeight > 0)) { result res = E_FAILURE; Tizen::Base::ByteBuffer* outBuffer = new Tizen::Base::ByteBuffer(); if (outBuffer == null) { - return null; + break; } res = outBuffer->Construct(bufWidth * bufHeight); - if(IsFailed(res)) + if (IsFailed(res)) { - return null; + break; } if (__pImageFeatureInfoImpl->GetThumbnail((char*)outBuffer->GetPointer(), bufWidth, bufHeight, false)) { return outBuffer; } - else - { - return null; - } - } - else - { - return null; + break; } + return null; } bool diff --git a/src/FUixVisionImageFeatureManager.cpp b/src/FUixVisionImageFeatureManager.cpp index 16e70c2..8ef65b8 100755 --- a/src/FUixVisionImageFeatureManager.cpp +++ b/src/FUixVisionImageFeatureManager.cpp @@ -32,7 +32,6 @@ ImageFeatureManager::ImageFeatureManager(void) ImageFeatureManager::~ImageFeatureManager(void) { - delete __pImageFeatureManagerImpl; } result @@ -41,8 +40,10 @@ ImageFeatureManager::Construct(void) SysAssertf(__pImageFeatureManagerImpl == null, "Already constructed! ", "Calling Construct() twice or more on a same instance is not allowed for this class."); - __pImageFeatureManagerImpl = new (std::nothrow) _ImageFeatureManagerImpl; - SysTryReturnResult(NID_UIX, __pImageFeatureManagerImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]"); + std::unique_ptr<_ImageFeatureManagerImpl> pImageFeatureManagerImpl (new (std::nothrow) _ImageFeatureManagerImpl()); + SysTryReturn(NID_UIX, pImageFeatureManagerImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + + __pImageFeatureManagerImpl = pImageFeatureManagerImpl.release(); __pImageFeatureManagerImpl->InitDB(); return E_SUCCESS; } @@ -108,7 +109,7 @@ ImageFeatureManager::Flush(const Tizen::Base::String* featureSetFilePath) { SysAssertf(__pImageFeatureManagerImpl != null, "Not yet constructed! Consruct() should be called before use."); - return __pImageFeatureManagerImpl->SaveDB(true, featureSetFilePath); + return __pImageFeatureManagerImpl->SaveDB(true, featureSetFilePath); } result diff --git a/src/FUixVisionImageObject.cpp b/src/FUixVisionImageObject.cpp index c5eb02e..e2a1de3 100644 --- a/src/FUixVisionImageObject.cpp +++ b/src/FUixVisionImageObject.cpp @@ -22,31 +22,40 @@ namespace Tizen { namespace Uix { namespace Vision { ImageObject::ImageObject() -: __pImageObjectImpl(new _ImageObjectImpl) + : __pImageObjectImpl(0) { + std::unique_ptr<_ImageObjectImpl> pImageObjectImpl (new (std::nothrow) _ImageObjectImpl); + __pImageObjectImpl = pImageObjectImpl.release(); } ImageObject::~ImageObject() { - delete __pImageObjectImpl; } int ImageObject::GetId(void) const { if (__pImageObjectImpl) + { return __pImageObjectImpl->GetId(); + } else + { return -1; + } } int ImageObject::GetFeatureId(void) const { if (__pImageObjectImpl) + { return __pImageObjectImpl->GetFeatureId(); + } else + { return -1; + } } const Tizen::Graphics::FloatMatrix4* diff --git a/src/FUixVisionImageRecognizer.cpp b/src/FUixVisionImageRecognizer.cpp index 8dfae35..9084d2e 100755 --- a/src/FUixVisionImageRecognizer.cpp +++ b/src/FUixVisionImageRecognizer.cpp @@ -31,7 +31,6 @@ ImageRecognizer::ImageRecognizer(void) ImageRecognizer::~ImageRecognizer(void) { - delete __pImageRecognizerImpl; } result @@ -40,8 +39,10 @@ ImageRecognizer::Construct(void) SysAssertf(__pImageRecognizerImpl == null, "Already constructed! ", "Calling Construct() twice or more on a same instance is not allowed for this class."); - __pImageRecognizerImpl = new (std::nothrow) _ImageRecognizerImpl; - SysTryReturnResult(NID_UIX, __pImageRecognizerImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]"); + std::unique_ptr<_ImageRecognizerImpl> pImageRecognizerImpl (new (std::nothrow) _ImageRecognizerImpl); + SysTryReturn(NID_UIX, pImageRecognizerImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + __pImageRecognizerImpl = pImageRecognizerImpl.release(); + return E_SUCCESS; } diff --git a/src/FUixVisionQrCodeGenerator.cpp b/src/FUixVisionQrCodeGenerator.cpp index 0c78c07..2ab8958 100644 --- a/src/FUixVisionQrCodeGenerator.cpp +++ b/src/FUixVisionQrCodeGenerator.cpp @@ -30,7 +30,6 @@ QrCodeGenerator::QrCodeGenerator(void) QrCodeGenerator::~QrCodeGenerator(void) { - delete __pQrCodeGeneratorImpl; } result @@ -39,8 +38,10 @@ QrCodeGenerator::Construct(void) SysAssertf(__pQrCodeGeneratorImpl == null, "Already constructed! ", "Calling Construct() twice or more on a same instance is not allowed for this class."); - __pQrCodeGeneratorImpl = new (std::nothrow) _QrCodeGeneratorImpl; - SysTryReturnResult(NID_UIX, __pQrCodeGeneratorImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]"); + std::unique_ptr<_QrCodeGeneratorImpl> pQrCodeGeneratorImpl(new (std::nothrow) _QrCodeGeneratorImpl()); + SysTryReturn(NID_UIX, pQrCodeGeneratorImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + __pQrCodeGeneratorImpl = pQrCodeGeneratorImpl.release(); + return E_SUCCESS; } @@ -54,7 +55,6 @@ QrCodeGenerator::EncodeToBufferN(const Tizen::Base::String& message, QrCodeMode Tizen::Text::Utf8Encoding utf8; __pQrCodeGeneratorImpl->Encode((char*) utf8.GetBytesN(message)->GetPointer(), mode, error_level, compatibility); - __pQrCodeGeneratorImpl->GetSize(width, height); Tizen::Base::ByteBuffer* buffer = new Tizen::Base::ByteBuffer; @@ -63,7 +63,9 @@ QrCodeGenerator::EncodeToBufferN(const Tizen::Base::String& message, QrCodeMode if (__pQrCodeGeneratorImpl->SaveToBuffer((unsigned char*) buffer->GetPointer())) { return buffer; - } else { + } + else + { delete buffer; return null; } diff --git a/src/FUixVisionQrCodeObject.cpp b/src/FUixVisionQrCodeObject.cpp index 80b96cd..7d5b45b 100644 --- a/src/FUixVisionQrCodeObject.cpp +++ b/src/FUixVisionQrCodeObject.cpp @@ -22,13 +22,14 @@ namespace Tizen { namespace Uix { namespace Vision { QrCodeObject::QrCodeObject(void) - : __pQrCodeObjectImpl(new _QrCodeObjectImpl) + : __pQrCodeObjectImpl(0) { + std::unique_ptr<_QrCodeObjectImpl> pQrCodeObjectImpl(new (std::nothrow) _QrCodeObjectImpl()); + __pQrCodeObjectImpl = pQrCodeObjectImpl.release(); } QrCodeObject::~QrCodeObject(void) { - delete __pQrCodeObjectImpl; } int diff --git a/src/FUixVisionQrCodeRecognizer.cpp b/src/FUixVisionQrCodeRecognizer.cpp index a6a5215..29b42d9 100644 --- a/src/FUixVisionQrCodeRecognizer.cpp +++ b/src/FUixVisionQrCodeRecognizer.cpp @@ -29,13 +29,6 @@ QrCodeRecognizer::QrCodeRecognizer(void) QrCodeRecognizer::~QrCodeRecognizer(void) { - if(__pQrCodeRecognizerImpl != NULL) - { - __pQrCodeRecognizerImpl->Destroy(); - } - - delete __pQrCodeRecognizerImpl; - __pQrCodeRecognizerImpl = null; } result @@ -44,8 +37,9 @@ QrCodeRecognizer::Construct(void) SysAssertf(__pQrCodeRecognizerImpl == null, "Already constructed! ", "Calling Construct() twice or more on a same instance is not allowed for this class."); - __pQrCodeRecognizerImpl = new (std::nothrow) _QrCodeRecognizerImpl; - SysTryReturnResult(NID_UIX, __pQrCodeRecognizerImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]"); + std::unique_ptr<_QrCodeRecognizerImpl> pQrCodeRecognizerImpl(new (std::nothrow) _QrCodeRecognizerImpl()); + SysTryReturn(NID_UIX, pQrCodeRecognizerImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); + __pQrCodeRecognizerImpl = pQrCodeRecognizerImpl.release(); return __pQrCodeRecognizerImpl->Init() ? E_SUCCESS : E_FAILURE; } @@ -69,9 +63,9 @@ QrCodeRecognizer::GetFocusRoi(Tizen::Graphics::Rectangle& roi) static float array[4] = {0.f}; result r = __pQrCodeRecognizerImpl->GetROI(array) ? E_SUCCESS : E_FAILURE; - if(r == E_SUCCESS) + if (r == E_SUCCESS) { - roi.SetBounds(array[0],array[1],array[2]-array[0],array[3]-array[1]); + roi.SetBounds(array[0], array[1], array[2] - array[0], array[3] - array[1]); } return r; } diff --git a/src/FUixVision_ImageFeatureManagerImpl.cpp b/src/FUixVision_ImageFeatureManagerImpl.cpp index 5fcd8f3..2096738 100644 --- a/src/FUixVision_ImageFeatureManagerImpl.cpp +++ b/src/FUixVision_ImageFeatureManagerImpl.cpp @@ -247,13 +247,13 @@ _ImageFeatureManagerImpl::UpdateFeatureIndices(void) { __indices.RemoveAll(); - if(!__imageFeatureManager) + if (!__imageFeatureManager) return; int total = __imageFeatureManager->totalNumberOfImages(); - for(int i = 0; i < total; i++) + for (int i = 0; i < total; i++) { - if(0 != sari2::ImageFeatureInfo(__imageFeatureManager, i).imageWidth()) + if (sari2::ImageFeatureInfo(__imageFeatureManager, i).isActive()) { __indices.Add(i); } diff --git a/src/ImageFeatureInfo.h b/src/ImageFeatureInfo.h index 134e5e6..75752d1 100755 --- a/src/ImageFeatureInfo.h +++ b/src/ImageFeatureInfo.h @@ -51,6 +51,11 @@ public: /// \return Path size. unsigned int imagePath(char* path, unsigned int length) const; + + /// \brief valuate if the object is available for query. + /// \return true if object is available + bool isActive(void) const; + /// \brief Width of image of corresponding object from the database. /// \return Image width. int imageWidth(void) const; -- 2.7.4