2015-06-24 05:22:09 +00:00
|
|
|
// 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_ID_WEAK_MAP_H_
|
|
|
|
#define ATOM_COMMON_ID_WEAK_MAP_H_
|
|
|
|
|
2016-05-11 05:46:32 +00:00
|
|
|
#include "atom/common/key_weak_map.h"
|
2015-06-24 05:22:09 +00:00
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
2016-05-11 04:40:33 +00:00
|
|
|
// Provides key increments service in addition to KeyWeakMap.
|
2016-05-11 05:46:32 +00:00
|
|
|
class IDWeakMap : public KeyWeakMap<int32_t> {
|
2016-05-11 04:40:33 +00:00
|
|
|
public:
|
|
|
|
IDWeakMap();
|
|
|
|
~IDWeakMap() override;
|
|
|
|
|
|
|
|
// Adds |object| to WeakMap and returns its allocated |id|.
|
|
|
|
int32_t Add(v8::Isolate* isolate, v8::Local<v8::Object> object);
|
|
|
|
|
2015-06-24 05:22:09 +00:00
|
|
|
private:
|
|
|
|
// Returns next available ID.
|
2015-06-24 05:35:39 +00:00
|
|
|
int32_t GetNextID();
|
2015-06-24 05:22:09 +00:00
|
|
|
|
|
|
|
// ID of next stored object.
|
|
|
|
int32_t next_id_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(IDWeakMap);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_COMMON_ID_WEAK_MAP_H_
|