Coding idoms applied. isActive functional added.
authorOleksandr Kaspruk <a.kaspruk@samsung.com>
Thu, 21 Mar 2013 16:25:18 +0000 (01:25 +0900)
committerKyusung Cho <ks0128.cho@samsung.com>
Fri, 5 Apr 2013 10:32:43 +0000 (19:32 +0900)
Change-Id: Ie9425f0b099a7a5d2b47f8f18d90157821d31b15
Signed-off-by: Oleksandr Kaspruk <a.kaspruk@samsung.com>
src/FUixVisionImageFeatureInfo.cpp
src/FUixVisionImageFeatureManager.cpp
src/FUixVisionImageObject.cpp
src/FUixVisionImageRecognizer.cpp
src/FUixVisionQrCodeGenerator.cpp
src/FUixVisionQrCodeObject.cpp
src/FUixVisionQrCodeRecognizer.cpp
src/FUixVision_ImageFeatureManagerImpl.cpp
src/ImageFeatureInfo.h

index 300cfa9..c7e39ff 100644 (file)
@@ -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
index 16e70c2..8ef65b8 100755 (executable)
@@ -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
index c5eb02e..e2a1de3 100644 (file)
@@ -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*
index 8dfae35..9084d2e 100755 (executable)
@@ -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;
 }
 
index 0c78c07..2ab8958 100644 (file)
@@ -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;
     }
index 80b96cd..7d5b45b 100644 (file)
@@ -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
index a6a5215..29b42d9 100644 (file)
@@ -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;
 }
index 5fcd8f3..2096738 100644 (file)
@@ -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);
         }
index 134e5e6..75752d1 100755 (executable)
@@ -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;