PageRenderTime 57ms CodeModel.GetById 34ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/visualizations/Vortex/angelscript/angelscript/source/as_globalproperty.cpp

http://github.com/xbmc/xbmc
C++ | 107 lines | 52 code | 15 blank | 40 comment | 10 complexity | 837d5eccb498bf4fb4ecb91aa14b72dd MD5 | raw file
  1/*
  2   AngelCode Scripting Library
  3   Copyright (c) 2003-2009 Andreas Jonsson
  4
  5   This software is provided 'as-is', without any express or implied 
  6   warranty. In no event will the authors be held liable for any 
  7   damages arising from the use of this software.
  8
  9   Permission is granted to anyone to use this software for any 
 10   purpose, including commercial applications, and to alter it and 
 11   redistribute it freely, subject to the following restrictions:
 12
 13   1. The origin of this software must not be misrepresented; you 
 14      must not claim that you wrote the original software. If you use
 15      this software in a product, an acknowledgment in the product 
 16      documentation would be appreciated but is not required.
 17
 18   2. Altered source versions must be plainly marked as such, and 
 19      must not be misrepresented as being the original software.
 20
 21   3. This notice may not be removed or altered from any source 
 22      distribution.
 23
 24   The original version of this library can be located at:
 25   http://www.angelcode.com/angelscript/
 26
 27   Andreas Jonsson
 28   andreas@angelcode.com
 29*/
 30
 31
 32
 33
 34#include "as_config.h"
 35#include "as_property.h"
 36
 37BEGIN_AS_NAMESPACE
 38
 39asCGlobalProperty::asCGlobalProperty() 
 40{ 
 41	memory = 0; 
 42	memoryAllocated = false; 
 43	realAddress = 0; 
 44	initFunc = 0; 
 45
 46	refCount.set(1);
 47}
 48
 49asCGlobalProperty::~asCGlobalProperty()
 50{ 
 51	if( memoryAllocated ) { asDELETEARRAY(memory); } 
 52	if( initFunc )
 53		initFunc->Release();
 54}
 55
 56void asCGlobalProperty::AddRef()
 57{
 58	refCount.atomicInc();
 59}
 60
 61void asCGlobalProperty::Release()
 62{
 63	// The property doesn't delete itself. The  
 64	// engine will do that at a later time
 65	if( refCount.atomicDec() == 1 && initFunc )
 66	{
 67		// Since the initFunc holds a reference to the property,
 68		// we'll release it when we reach refCount 1. This will
 69		// break the circle and allow the engine to free the property
 70		// without the need for a GC run.
 71		initFunc->Release();
 72		initFunc = 0;
 73	}
 74}
 75
 76void *asCGlobalProperty::GetAddressOfValue()
 77{ 
 78	return (memoryAllocated || realAddress) ? memory : &storage; 
 79}
 80
 81// The global property structure is responsible for allocating the storage
 82// method for script declared variables. Each allocation is independent of
 83// other global properties, so that variables can be added and removed at
 84// any time.
 85void asCGlobalProperty::AllocateMemory() 
 86{ 
 87	if( type.GetSizeOnStackDWords() > 2 ) 
 88	{ 
 89		memory = asNEWARRAY(asDWORD, type.GetSizeOnStackDWords()); 
 90		memoryAllocated = true; 
 91	} 
 92}
 93
 94void asCGlobalProperty::SetRegisteredAddress(void *p) 
 95{ 
 96	realAddress = p; 	
 97	if( type.IsObject() && !type.IsReference() && !type.IsObjectHandle() )
 98	{
 99		// The global property is a pointer to a pointer 
100		memory = &realAddress;
101	} 
102	else
103		memory = p; 
104}
105
106
107END_AS_NAMESPACE