Update class Bundle 48/199748/1
authormk5004.lee <mk5004.lee@samsung.com>
Thu, 14 Feb 2019 10:50:37 +0000 (19:50 +0900)
committermk5004.lee <mk5004.lee@samsung.com>
Thu, 14 Feb 2019 10:50:37 +0000 (19:50 +0900)
Change-Id: I69dadb8de286ee8772aae5e7ad91ec9fa3756279
Signed-off-by: mk5004.lee <mk5004.lee@samsung.com>
notification-ex/bundle.cc
notification-ex/bundle.h

index 4ff78e9..04d9a6e 100644 (file)
@@ -27,7 +27,61 @@ namespace notification {
 namespace item {
 
 Bundle::Bundle() {
-       raw_ = bundle_create();
+  raw_ = bundle_create();
+  if (raw_ == NULL)
+    THROW(NOTIFICATION_ERROR_OUT_OF_MEMORY);
+}
+
+Bundle::Bundle(std::string raw) {
+  if (!raw.empty()) {
+    raw_ = bundle_decode(reinterpret_cast<const bundle_raw*>(raw.c_str()),
+                         raw.length());
+    if (raw_ == NULL) {
+      int ret = get_last_result();
+      if (ret == BUNDLE_ERROR_OUT_OF_MEMORY)
+        THROW(NOTIFICATION_ERROR_OUT_OF_MEMORY);
+      else
+        THROW(NOTIFICATION_ERROR_INVALID_PARAMETER);
+    }
+  } else {
+    raw_ = bundle_create();
+    if (raw_ == NULL)
+      THROW(NOTIFICATION_ERROR_OUT_OF_MEMORY);
+  }
+}
+
+Bundle::Bundle(bundle* raw) {
+  raw_ = bundle_dup(raw);
+  if (raw_ == NULL)
+    THROW(NOTIFICATION_ERROR_OUT_OF_MEMORY);
+}
+
+Bundle::Bundle(Bundle&& b) : raw_(b.raw_) {
+  b.raw_ = nullptr;
+}
+
+Bundle& Bundle::operator = (Bundle&& b) {
+  raw_ = b.raw_;
+  b.raw_ = nullptr;
+  return *this;
+}
+
+Bundle::Bundle(const Bundle& b) : raw_(bundle_dup(b.raw_)) {
+}
+
+Bundle& Bundle::operator = (const Bundle& b) {
+  raw_ = bundle_dup(b.raw_);
+  if (raw_ == NULL)
+    THROW(NOTIFICATION_ERROR_OUT_OF_MEMORY);
+  return *this;
+}
+
+const bundle* Bundle::GetConstRaw() const {
+  return raw_;
+}
+
+bundle* Bundle::GetRaw() {
+  return raw_;
 }
 
 const char* Bundle::ToString() {
index 3246789..894f8b3 100644 (file)
@@ -31,7 +31,18 @@ namespace item {
 class EXPORT_API Bundle {
  public:
   Bundle();
+  explicit Bundle(std::string raw);
+  explicit Bundle(bundle* raw);
   ~Bundle();
+
+  Bundle(const Bundle&);
+  Bundle& operator=(const Bundle&);
+
+  Bundle(Bundle && other);
+  Bundle& operator=(Bundle && other);
+
+  const bundle* GetConstRaw() const;
+  bundle* GetRaw();
   const char* ToString();
 
  private: