Turn api::IDWeakMap into api::KeyWeakMap<T>
authorCheng Zhao <zcbenz@gmail.com>
Wed, 11 May 2016 09:21:35 +0000 (18:21 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 11 May 2016 09:21:35 +0000 (18:21 +0900)
atom/common/api/atom_api_id_weak_map.cc [deleted file]
atom/common/api/atom_api_id_weak_map.h [deleted file]
atom/common/api/atom_api_key_weak_map.cc [new file with mode: 0644]
atom/common/api/atom_api_key_weak_map.h [new file with mode: 0644]
filenames.gypi

diff --git a/atom/common/api/atom_api_id_weak_map.cc b/atom/common/api/atom_api_id_weak_map.cc
deleted file mode 100644 (file)
index 9345794..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright (c) 2015 GitHub, Inc.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#include "atom/common/api/atom_api_id_weak_map.h"
-
-#include "atom/common/node_includes.h"
-#include "native_mate/dictionary.h"
-
-namespace atom {
-
-namespace api {
-
-IDWeakMap::IDWeakMap(v8::Isolate* isolate) {
-  Init(isolate);
-}
-
-IDWeakMap::~IDWeakMap() {
-}
-
-void IDWeakMap::Set(v8::Isolate* isolate,
-                    int32_t id,
-                    v8::Local<v8::Object> object) {
-  id_weak_map_.Set(isolate, id, object);
-}
-
-v8::Local<v8::Object> IDWeakMap::Get(v8::Isolate* isolate, int32_t id) {
-  return id_weak_map_.Get(isolate, id).ToLocalChecked();
-}
-
-bool IDWeakMap::Has(int32_t id) {
-  return id_weak_map_.Has(id);
-}
-
-void IDWeakMap::Remove(int32_t id) {
-  id_weak_map_.Remove(id);
-}
-
-// static
-void IDWeakMap::BuildPrototype(v8::Isolate* isolate,
-                               v8::Local<v8::ObjectTemplate> prototype) {
-  mate::ObjectTemplateBuilder(isolate, prototype)
-      .SetMethod("set", &IDWeakMap::Set)
-      .SetMethod("get", &IDWeakMap::Get)
-      .SetMethod("has", &IDWeakMap::Has)
-      .SetMethod("remove", &IDWeakMap::Remove);
-}
-
-// static
-mate::Handle<IDWeakMap> IDWeakMap::Create(v8::Isolate* isolate) {
-  return mate::CreateHandle(isolate, new IDWeakMap(isolate));
-}
-
-}  // namespace api
-
-}  // namespace atom
-
-namespace {
-
-using atom::api::IDWeakMap;
-
-void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
-                v8::Local<v8::Context> context, void* priv) {
-  mate::Dictionary dict(context->GetIsolate(), exports);
-  dict.SetMethod("createIDWeakMap", &atom::api::IDWeakMap::Create);
-}
-
-}  // namespace
-
-NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_id_weak_map, Initialize)
diff --git a/atom/common/api/atom_api_id_weak_map.h b/atom/common/api/atom_api_id_weak_map.h
deleted file mode 100644 (file)
index 6d5a8bf..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (c) 2015 GitHub, Inc.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#ifndef ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_
-#define ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_
-
-#include "atom/common/key_weak_map.h"
-#include "native_mate/object_template_builder.h"
-#include "native_mate/handle.h"
-
-namespace atom {
-
-namespace api {
-
-class IDWeakMap : public mate::Wrappable<IDWeakMap> {
- public:
-  static mate::Handle<IDWeakMap> Create(v8::Isolate* isolate);
-
-  static void BuildPrototype(v8::Isolate* isolate,
-                             v8::Local<v8::ObjectTemplate> prototype);
-
- protected:
-  explicit IDWeakMap(v8::Isolate* isolate);
-  ~IDWeakMap();
-
- private:
-  // Api for IDWeakMap.
-  void Set(v8::Isolate* isolate, int32_t id, v8::Local<v8::Object> object);
-  v8::Local<v8::Object> Get(v8::Isolate* isolate, int32_t id);
-  bool Has(int32_t id);
-  void Remove(int32_t id);
-
-  atom::KeyWeakMap<int32_t> id_weak_map_;
-
-  DISALLOW_COPY_AND_ASSIGN(IDWeakMap);
-};
-
-}  // namespace api
-
-}  // namespace atom
-
-#endif  // ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_
diff --git a/atom/common/api/atom_api_key_weak_map.cc b/atom/common/api/atom_api_key_weak_map.cc
new file mode 100644 (file)
index 0000000..be703c2
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright (c) 2016 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "atom/common/api/atom_api_key_weak_map.h"
+
+#include "atom/common/node_includes.h"
+#include "native_mate/dictionary.h"
+
+namespace {
+
+void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
+                v8::Local<v8::Context> context, void* priv) {
+  mate::Dictionary dict(context->GetIsolate(), exports);
+  dict.SetMethod("createIDWeakMap",
+                 &atom::api::KeyWeakMap<int32_t>::Create);
+}
+
+}  // namespace
+
+NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_id_weak_map, Initialize)
diff --git a/atom/common/api/atom_api_key_weak_map.h b/atom/common/api/atom_api_key_weak_map.h
new file mode 100644 (file)
index 0000000..b13338b
--- /dev/null
@@ -0,0 +1,65 @@
+// Copyright (c) 2016 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_COMMON_API_ATOM_API_KEY_WEAK_MAP_H_
+#define ATOM_COMMON_API_ATOM_API_KEY_WEAK_MAP_H_
+
+#include "atom/common/key_weak_map.h"
+#include "native_mate/object_template_builder.h"
+#include "native_mate/handle.h"
+
+namespace atom {
+
+namespace api {
+
+template<typename K>
+class KeyWeakMap : public mate::Wrappable<KeyWeakMap<K>> {
+ public:
+  static mate::Handle<KeyWeakMap<K>> Create(v8::Isolate* isolate) {
+    return mate::CreateHandle(isolate, new KeyWeakMap<K>(isolate));
+  }
+
+  static void BuildPrototype(v8::Isolate* isolate,
+                             v8::Local<v8::ObjectTemplate> prototype) {
+    mate::ObjectTemplateBuilder(isolate, prototype)
+        .SetMethod("set", &KeyWeakMap<K>::Set)
+        .SetMethod("get", &KeyWeakMap<K>::Get)
+        .SetMethod("has", &KeyWeakMap<K>::Has)
+        .SetMethod("remove", &KeyWeakMap<K>::Remove);
+  }
+
+ protected:
+  explicit KeyWeakMap(v8::Isolate* isolate) {
+    mate::Wrappable<KeyWeakMap<K>>::Init(isolate);
+  }
+  ~KeyWeakMap() override {}
+
+ private:
+  // API for KeyWeakMap.
+  void Set(v8::Isolate* isolate, const K& key, v8::Local<v8::Object> object) {
+    key_weak_map_.Set(isolate, key, object);
+  }
+
+  v8::Local<v8::Object> Get(v8::Isolate* isolate, const K& key) {
+    return key_weak_map_.Get(isolate, key).ToLocalChecked();
+  }
+
+  bool Has(const K& key) {
+    return key_weak_map_.Has(key);
+  }
+
+  void Remove(const K& key) {
+    key_weak_map_.Remove(key);
+  }
+
+  atom::KeyWeakMap<K> key_weak_map_;
+
+  DISALLOW_COPY_AND_ASSIGN(KeyWeakMap);
+};
+
+}  // namespace api
+
+}  // namespace atom
+
+#endif  // ATOM_COMMON_API_ATOM_API_KEY_WEAK_MAP_H_
index fa1b1d770a3271be9281867f57ce880443d11d8d..e85f150615a3cda5f954d9d6d99edaf4d244228f 100644 (file)
       'atom/common/api/atom_api_asar.cc',
       'atom/common/api/atom_api_clipboard.cc',
       'atom/common/api/atom_api_crash_reporter.cc',
-      'atom/common/api/atom_api_id_weak_map.cc',
-      'atom/common/api/atom_api_id_weak_map.h',
+      'atom/common/api/atom_api_key_weak_map.cc',
+      'atom/common/api/atom_api_key_weak_map.h',
       'atom/common/api/atom_api_native_image.cc',
       'atom/common/api/atom_api_native_image.h',
       'atom/common/api/atom_api_native_image_mac.mm',