I'm trying to create an object which de facto is analogue of Python's list
object. In my code I have the following classes: object_type
, type_type
, none_type
, bool_type
, int_type
, float_type
, bytes_type
, where object_type
is abstract class.
Abstract class has some virtual functions like type_type __type__(void)
, bytes_type __name__(void)
, bytes_type __repr__(void)
, bool_type __bool__(void)
, int_type __int__(void)
, float_type __float__(void)
, bytes_type __bytes__(void)
.
type_type
class has following constructor: type_type(object_type*)
; during construction pointer to source object is stored to object_type* type_type::__cdata__
and is used when user wants to compare two types using type_type::__eq__(const type_type&)
function (this function uses typeid
as you might have been guessed).
I need to create list_type
object, which can store any object which is based on object_type
. It must have __get__(const int_type&)
function to get an element and __set__(const int_type&, object_type*)
function to set an element. All objects are stored inside std::vector<object_type*> __cdata__
.
How can I force list_type::__get__(const int_type&)
to return correct object? Let's imagine we have list_type
, which contains three elements: [bytes_type object0, int_type object1, float_type object3]
. Using list_type::__get__(0)
should return bytes_type object0
. Probably function type_type object_type::__type__()
can be useful.
There is a diffictulty that user can create a new object_type
based type during execution (all what I've described is used to create a new toy-language). However all types are based on object_type
and has its virtual functions.
Do you have any ideas? I'd be glad to meet your advice.
P.S. git repository: https://github.com/ghostmansd/quirinus