electron/atom/common/api/atom_api_id_weak_map.h

54 lines
1.5 KiB
C
Raw Normal View History

2013-04-25 13:46:04 +00:00
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Copyright (c) 2012 Intel Corp. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
2013-04-29 12:40:59 +00:00
#ifndef ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_
#define ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_
2013-04-25 13:46:04 +00:00
#include <map>
2014-03-16 00:30:26 +00:00
#include "atom/common/v8/scoped_persistent.h"
2014-03-16 01:37:04 +00:00
#include "base/basictypes.h"
2013-04-25 13:46:04 +00:00
#include "vendor/node/src/node_object_wrap.h"
namespace atom {
namespace api {
2014-03-16 01:37:04 +00:00
// Like ES6's WeakMap, but the key is Integer and the value is Weak Pointer.
2013-04-25 13:46:04 +00:00
class IDWeakMap : public node::ObjectWrap {
public:
static void Initialize(v8::Handle<v8::Object> target);
private:
IDWeakMap();
virtual ~IDWeakMap();
bool Has(int key) const;
void Erase(int key);
2013-04-25 13:46:04 +00:00
int GetNextID();
static void WeakCallback(v8::Isolate* isolate,
v8::Persistent<v8::Object>* value,
IDWeakMap* self);
2013-04-25 13:46:04 +00:00
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Add(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Get(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Has(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Keys(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Remove(const v8::FunctionCallbackInfo<v8::Value>& args);
2013-04-25 13:46:04 +00:00
int next_id_;
std::map<int, RefCountedV8Object> map_;
2013-04-25 13:46:04 +00:00
DISALLOW_COPY_AND_ASSIGN(IDWeakMap);
};
} // namespace api
} // namespace atom
2013-04-29 12:40:59 +00:00
#endif // ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_