Add IsEmpty() method
[platform/core/base/bundle.git] / src / bundle_cpp.cc
index 2e5e6ca..6d1163c 100644 (file)
 #include "bundle_cpp_implementation.h"
 #include "bundle_cpp.h"
 #include "bundle_internal.h"
-
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "BUNDLE"
+#include "bundle_log.h"
 
 namespace tizen_base {
 Bundle::Impl::Impl(Bundle* parent, bool copy, bool own)
@@ -76,7 +70,7 @@ Bundle::Bundle(bundle* b, bool copy, bool own)
 }
 
 Bundle::~Bundle() {
-  if (impl_->handle_ && (impl_->own_ || impl_->copy_))
+  if (impl_ && impl_->handle_ && (impl_->own_ || impl_->copy_))
     bundle_free(impl_->handle_);
 }
 
@@ -164,9 +158,8 @@ Bundle& Bundle::operator = (const Bundle& b) {
 }
 
 Bundle::Bundle(Bundle&& b) noexcept {
-  impl_ = std::unique_ptr<Impl>(new Impl(this));
-  impl_->handle_ = b.impl_->handle_;
-  b.impl_->handle_ = nullptr;
+  impl_ = std::move(b.impl_);
+  impl_->parent_ = this;
 }
 
 Bundle& Bundle::operator = (Bundle&& b) noexcept {
@@ -177,6 +170,10 @@ Bundle& Bundle::operator = (Bundle&& b) noexcept {
   return *this;
 }
 
+bool Bundle::IsEmpty() const noexcept {
+  return (bundle_get_count(impl_->handle_) == 0) ? true : false;
+}
+
 std::vector<Bundle::KeyInfo> Bundle::GetKeys() {
   std::vector<Bundle::KeyInfo> v;
 
@@ -252,8 +249,13 @@ std::vector<std::string> Bundle::GetStringArray(const std::string& key) const {
 std::vector<unsigned char> Bundle::GetByte(const std::string& key) const {
   size_t size;
   unsigned char* bytes = nullptr;
-  bundle_get_byte(impl_->handle_, key.c_str(),
+  int ret = bundle_get_byte(impl_->handle_, key.c_str(),
       reinterpret_cast<void**>(&bytes), &size);
+  if (ret != BUNDLE_ERROR_NONE) {
+    LOGE("bundle_get_byte() is failed");
+    return {};
+  }
+
   return std::vector<unsigned char>(bytes, bytes + size);
 }