#include "object-type.h" int ObjectType_Create(ObjectType* self, StringView name, ObjectType* supertype, size_t attribute_count_guess, allocator_t* allocator) { struct HashMapConfig config = HashMap_DefaultConfig(); config.allocator = allocator; int hashmap_code = HashMap_Create(&self->attributes, &config, attribute_count_guess * (1 / config.load_factor) + 1); if (hashmap_code) { return hashmap_code; } self->name = name; self->reference_count = 0; supertype->reference_count++; return EXIT_SUCCESS; } void ObjectType_Destroy(ObjectType* self) { self->supertype->reference_count--; // TODO: Emit a warning when there are still references? HashMap_Destroy(&self->attributes); } int ObjectType_DefineObjectAttribute(ObjectType* self, ObjectType* attribute_type, StringView attribute_name) { ObjectTypeAttribute attribute = { .name = attribute_name, VALUETYPE_OBJECT, attribute_type, HashMap_Size(&self->attributes), }; return HashMap_Put(&self->attributes, attribute_name.source, attribute_name.length, &attribute); } int ObjectType_DefinePrimitiveAttribute(ObjectType* self, enum ValueType attribute_type, StringView attribute_name) { ObjectTypeAttribute attribute = { .name = attribute_name, attribute_type, NULL, HashMap_Size(&self->attributes), }; return HashMap_Put(&self->attributes, attribute_name.source, attribute_name.length, &attribute); } size_t ObjectType_GetAttributeCount(ObjectType* self) { return HashMap_Size(&self->attributes); }