<commit_before>/*
 * Appcelerator Kroll - licensed under the Apache Public License 2
 * see LICENSE in the root folder for details on the license.
 * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved.
 */

#include "binding.h"

namespace kroll
{
	StaticBoundObject::StaticBoundObject()
	{
	}

	StaticBoundObject::~StaticBoundObject()
	{
		ScopedLock lock(&mutex);
		std::map<std::string, Value*>::iterator iter = properties.begin();
		while (iter != properties.end())
		{
			KR_DECREF(iter->second);
			iter++;
		}
	}

	Value* StaticBoundObject::Get(const char *name)
	{
		ScopedLock lock(&mutex);

		std::map<std::string, Value*>::iterator iter;
		iter = properties.find(name);
		if (iter != properties.end()) {
			KR_ADDREF(iter->second);
			return iter->second;
		}

		return Value::Undefined();
	}

	void StaticBoundObject::Set(const char *name, Value* value)
	{
		ScopedLock lock(&mutex);

		KR_ADDREF(value);
		this->UnSet(name);
		this->properties[name] = value;
	}

	void StaticBoundObject::UnSet(const char *name)
	{
		ScopedLock lock(&mutex);
		std::map<std::string, Value*>::iterator iter = this->properties.find(name);
		if (this->properties.end() != iter)
		{
			KR_DECREF(iter->second);
			this->properties.erase(iter);
		}
	}

	void StaticBoundObject::GetPropertyNames(std::vector<const char *> *property_names)
	{
		ScopedLock lock(&mutex);
		std::map<std::string, Value*>::iterator iter = properties.begin();
		while (iter != properties.end())
		{
			property_names->push_back(strdup(iter->first.c_str()));
			iter++;
		}
	}

	void StaticBoundObject::SetObject(const char *name, BoundObject* object)
	{
		Value* obj_val = new Value(object);
		this->Set(name, obj_val);
		KR_DECREF(obj_val);
	}
}

KROLL_API kroll::RefCounted* CreateEmptyBoundObject()
{
	return new kroll::StaticBoundObject();
}
<commit_msg>Add necessary include<commit_after>/*
 * Appcelerator Kroll - licensed under the Apache Public License 2
 * see LICENSE in the root folder for details on the license.
 * Copyright (c) 2008 Appcelerator, Inc. All Rights Reserved.
 */

#include "binding.h"
#include <cstring>

namespace kroll
{
	StaticBoundObject::StaticBoundObject()
	{
	}

	StaticBoundObject::~StaticBoundObject()
	{
		ScopedLock lock(&mutex);
		std::map<std::string, Value*>::iterator iter = properties.begin();
		while (iter != properties.end())
		{
			KR_DECREF(iter->second);
			iter++;
		}
	}

	Value* StaticBoundObject::Get(const char *name)
	{
		ScopedLock lock(&mutex);

		std::map<std::string, Value*>::iterator iter;
		iter = properties.find(name);
		if (iter != properties.end()) {
			KR_ADDREF(iter->second);
			return iter->second;
		}

		return Value::Undefined();
	}

	void StaticBoundObject::Set(const char *name, Value* value)
	{
		ScopedLock lock(&mutex);

		KR_ADDREF(value);
		this->UnSet(name);
		this->properties[name] = value;
	}

	void StaticBoundObject::UnSet(const char *name)
	{
		ScopedLock lock(&mutex);
		std::map<std::string, Value*>::iterator iter = this->properties.find(name);
		if (this->properties.end() != iter)
		{
			KR_DECREF(iter->second);
			this->properties.erase(iter);
		}
	}

	void StaticBoundObject::GetPropertyNames(std::vector<const char *> *property_names)
	{
		ScopedLock lock(&mutex);
		std::map<std::string, Value*>::iterator iter = properties.begin();
		while (iter != properties.end())
		{
			property_names->push_back(strdup(iter->first.c_str()));
			iter++;
		}
	}

	void StaticBoundObject::SetObject(const char *name, BoundObject* object)
	{
		Value* obj_val = new Value(object);
		this->Set(name, obj_val);
		KR_DECREF(obj_val);
	}
}

KROLL_API kroll::RefCounted* CreateEmptyBoundObject()
{
	return new kroll::StaticBoundObject();
}

{'fraction_non_alphanumeric': 0.1574099160119209, 'fraction_numerical': 0.00270929287455974, 'mean_word_length': 4.814173228346457, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '802157', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1255, 'n_words': 256}