Adjust pimpl idiom to button item 57/200257/3
authorhyunho <hhstark.kang@samsung.com>
Thu, 21 Feb 2019 01:48:34 +0000 (10:48 +0900)
committerhyunho <hhstark.kang@samsung.com>
Thu, 21 Feb 2019 09:57:05 +0000 (18:57 +0900)
Change-Id: I5e80de438418fec3eb0a0bcddb9e4f6a6cf20562
Signed-off-by: hyunho <hhstark.kang@samsung.com>
notification-ex/button_item.cc
notification-ex/button_item.h
notification-ex/button_item_implementation.h [new file with mode: 0644]

index 852bb7d..f4a33d8 100644 (file)
@@ -19,6 +19,7 @@
 #include <memory>
 
 #include "notification-ex/button_item.h"
+#include "notification-ex/button_item_implementation.h"
 #include "notification-ex/item_factory.h"
 
 #ifdef LOG_TAG
 #define LOG_TAG "NOTIFICATION_EX"
 #define BUTTON_TITLE_KEY "__BUTTON_TITLE_KEY__"
 
+using namespace std;
 namespace notification {
 namespace item {
 
 ButtonItem::ButtonItem(string title,
       std::shared_ptr<AbstractAction> action)
-  : AbstractItem(AbstractItem::Button, action), title_(title) {
+  : AbstractItem(AbstractItem::Button, action), impl_(new Impl(this, title)) {
 }
 
 ButtonItem::ButtonItem(string id, string title,
       std::shared_ptr<AbstractAction> action)
-  : AbstractItem(id, AbstractItem::Button, action), title_(title) {
+  : AbstractItem(id, AbstractItem::Button, action), impl_(new Impl(this, title)) {
 }
+
 ButtonItem::~ButtonItem() = default;
+ButtonItem::Impl::~Impl() = default;
+
+ButtonItem::Impl::Impl(ButtonItem* parent, string title)
+  : title_(title), parent_(parent) {
+  LOGI("ButtonItem impl created");
+}
 
 Bundle ButtonItem::Serialize() {
   Bundle b;
   b = AbstractItem::Serialize();
-  b.Add(BUTTON_TITLE_KEY, title_);
+  b.Add(BUTTON_TITLE_KEY, impl_->title_);
   return b;
 }
 
 void ButtonItem::Deserialize(Bundle b) {
   AbstractItem::Deserialize(b);
-  title_ = b.GetString(BUTTON_TITLE_KEY);
+  impl_->title_ = b.GetString(BUTTON_TITLE_KEY);
 }
 
 AbstractItem& ButtonItem::FindByID(std::string id) {
@@ -61,7 +70,7 @@ AbstractItem& ButtonItem::FindByID(std::string id) {
 }
 
 std::string ButtonItem::GetTitle() const {
-  return title_;
+  return impl_->title_;
 }
 
 }  // namespace item
index 3282269..246ffc7 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "notification-ex/abstract_item.h"
 
-using namespace std;
 namespace notification {
 namespace item {
 
@@ -41,7 +40,8 @@ class EXPORT_API ButtonItem : public AbstractItem {
   std::string GetTitle() const;
 
  private:
-  std::string title_;
+  class Impl;
+  std::unique_ptr<Impl> impl_;
 };  // class ButtonItem
 
 }  // namespace item
diff --git a/notification-ex/button_item_implementation.h b/notification-ex/button_item_implementation.h
new file mode 100644 (file)
index 0000000..bab5b46
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_BUTTON_ITEM_IMPLEMENTATION_H_
+#define NOTIFICATION_EX_BUTTON_ITEM_IMPLEMENTATION_H_
+
+#include <string>
+#include <memory>
+#include <list>
+
+#include "notification-ex/button_item.h"
+
+namespace notification {
+namespace item {
+
+class ButtonItem::Impl {
+ public:
+  virtual ~Impl();
+
+ private:
+  Impl(ButtonItem* parent, std::string title);
+
+ private:
+  friend class ButtonItem;
+
+  std::string title_;
+  ButtonItem* parent_;
+};
+
+}  // namespace item
+}  // namespace notification
+
+#endif  // NOTIFICATION_EX_BUTTON_ITEM_IMPLEMENTATION_H_