<commit_before>/*
 * This file is part of Kotaka, a mud library for DGD
 * http://github.com/shentino/kotaka
 *
 * Copyright (C) 2012-2013  <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <kotaka/checkarg.h>
#include <kotaka/paths.h>
#include <kotaka/privilege.h>

private object *archetypes;

static void create()
{
	if (!archetypes) {
		archetypes = ({ });
	}
}

int is_archetype_of(object test)
{
	int index;
	int sz;
	object *arch;

	arch = test->query_archetypes();
	sz = sizeof(arch);

	if (sizeof(arch & ({ this_object() }))) {
		return 1;
	}

	for(index = 0; index < sz; index++) {
		if (is_archetype_of(arch[index])) {
			return 1;
		}
	}

	return 0;
}

object *query_archetypes()
{
	archetypes -= ({ nil });

	return archetypes[..];
}

void set_archetypes(object *new_archs)
{
	int i;
	int sz;

	object *old_archs;
	object *check;

	archetypes -= ({ nil });
	new_archs -= ({ nil });
	check = new_archs - ({ archetypes });

	sz = sizeof(check);

	for (i = 0; i < sz; i++) {
		CHECKARG(check[i] <- "archetype", 1, "add_archetype");

		if (is_archetype_of(check[i])) {
			error("Circular reference");
		}
	}

	archetypes = new_archs;
}

void clear_archetypes()
{
	archetypes = ({ });
}

void add_archetype(object new_arch)
{
	CHECKARG(new_arch, 1, "add_archetype");
	CHECKARG(new_arch <- "archetype", 1, "add_archetype");

	if (is_archetype_of(new_arch)) {
		error("Circular reference");
	}

	archetypes -= ({ nil });
	archetypes += ({ new_arch });
}

void add_archetype_at(object new_arch, int position)
{
	CHECKARG(new_arch, 1, "add_archetype_at");
	CHECKARG(new_arch <- "archetype", 1, "add_archetype_at");

	CHECKARG(position >= -1, 2, "add_archetype_at");
	CHECKARG(position <= sizeof(archetypes), 2, "add_archetype_at");

	if (is_archetype_of(new_arch)) {
		error("Circular reference");
	}

	archetypes -= ({ nil });

	if (position == -1) {
		archetypes += ({ new_arch });
	} else {
		archetypes = archetypes[0 .. position - 1]
			+ ({ new_arch }) + archetypes[position ..];
	}
}

void del_archetype(object old_arch)
{
	archetypes -= ({ nil, old_arch });
}<commit_msg>Clean archetypes<commit_after>/*
 * This file is part of Kotaka, a mud library for DGD
 * http://github.com/shentino/kotaka
 *
 * Copyright (C) 2012-2013  <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <kotaka/checkarg.h>
#include <kotaka/paths.h>
#include <kotaka/privilege.h>

private object *archetypes;

static void create()
{
}

void clean_archetypes()
{
	if (!archetypes) {
		return;
	}

	archetypes -= ({ nil });

	if (!sizeof(archetypes)) {
		archetypes = nil;
	}
}

int is_archetype_of(object test)
{
	int index;
	int sz;
	object *arch;

	arch = test->query_archetypes();
	sz = sizeof(arch);

	if (sizeof(arch & ({ this_object() }))) {
		return 1;
	}

	for(index = 0; index < sz; index++) {
		if (is_archetype_of(arch[index])) {
			return 1;
		}
	}

	return 0;
}

object *query_archetypes()
{
	clean_archetypes();

	if (archetypes) {
		return archetypes[..];
	} else {
		return ({ });
	}
}

void set_archetypes(object *new_archs)
{
	int i;
	int sz;

	object *old_archs;
	object *check;

	check = new_archs - ({ archetypes, nil });

	sz = sizeof(check);

	for (i = 0; i < sz; i++) {
		CHECKARG(check[i] <- "archetype", 1, "add_archetype");

		if (is_archetype_of(check[i])) {
			error("Circular reference");
		}
	}

	archetypes = new_archs;

	clean_archetypes();
}

void clear_archetypes()
{
	archetypes = nil;
}

void add_archetype(object new_arch)
{
	CHECKARG(new_arch, 1, "add_archetype");
	CHECKARG(new_arch <- "archetype", 1, "add_archetype");

	if (is_archetype_of(new_arch)) {
		error("Circular reference");
	}

	clean_archetypes();

	archetypes += ({ new_arch });
}

void add_archetype_at(object new_arch, int position)
{
	CHECKARG(new_arch, 1, "add_archetype_at");
	CHECKARG(new_arch <- "archetype", 1, "add_archetype_at");

	CHECKARG(position >= -1, 2, "add_archetype_at");
	CHECKARG(position <= sizeof(archetypes), 2, "add_archetype_at");

	if (is_archetype_of(new_arch)) {
		error("Circular reference");
	}

	clean_archetypes();

	if (position == -1) {
		archetypes += ({ new_arch });
	} else {
		archetypes = archetypes[0 .. position - 1]
			+ ({ new_arch }) + archetypes[position ..];
	}
}

void del_archetype(object old_arch)
{
	archetypes -= ({ old_arch });

	clean_archetypes();
}
{'fraction_non_alphanumeric': 0.14324178782983307, 'fraction_numerical': 0.008975049362771496, 'mean_word_length': 3.9973094170403587, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '509137', 'n_tokens_mistral': 2160, 'n_tokens_neox': 2017, 'n_words': 549}