Welcome to mirror list, hosted at ThFree Co, Russian Federation.

weakref.h « weakref « add_on « angelscript « Scripting « Source - github.com/WolfireGames/overgrowth.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ac24ea9571624d7109ef34f034e2db032be24d34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef SCRIPTWEAKREF_H
#define SCRIPTWEAKREF_H

// The CScriptWeakRef class was originally implemented by vroad in March 2013

#ifndef ANGELSCRIPT_H 
// Avoid having to inform include path if header is already include before
#include <angelscript.h>
#endif


BEGIN_AS_NAMESPACE

class CScriptWeakRef 
{
public:
	// Constructors
	CScriptWeakRef(asITypeInfo *type);
	CScriptWeakRef(const CScriptWeakRef &other);
	CScriptWeakRef(void *ref, asITypeInfo *type);

	~CScriptWeakRef();

	// Copy the stored value from another weakref object
	CScriptWeakRef &operator=(const CScriptWeakRef &other);

	// Compare equalness
	bool operator==(const CScriptWeakRef &o) const;
	bool operator!=(const CScriptWeakRef &o) const;

	// Sets a new reference
	CScriptWeakRef &Set(void *newRef);

	// Returns the object if it is still alive
	// This will increment the refCount of the returned object
	void *Get() const;

	// Returns true if the contained reference is the same
	bool Equals(void *ref) const;

	// Returns the type of the reference held
	asITypeInfo *GetRefType() const;

protected:
	// These functions need to have access to protected
	// members in order to call them from the script engine
	friend void RegisterScriptWeakRef_Native(asIScriptEngine *engine);

	void                  *m_ref;
	asITypeInfo           *m_type;
	asILockableSharedBool *m_weakRefFlag;
};

void RegisterScriptWeakRef(asIScriptEngine *engine);

END_AS_NAMESPACE

#endif