www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - TypeInfo manipulation

reply "Zhenya" <zheny list.ru> writes:
Hi!
Tell me please,are any TypeInfo/typeid/classinfo manipulations 
possible?
For example I need a struct that overload typeid, or something 
like that?

Some time ago I tried to write some smart pointer that overlad 
classinfo property  in accordance with the real type of hold 
object,but I failed to do this becouse of
not having possibility to declar static and non-static version of 
the one function.Maybe there are better ways to do this?
Oct 25 2012
next sibling parent reply "Zhenya" <zheny list.ru> writes:
On Thursday, 25 October 2012 at 15:05:05 UTC, Zhenya wrote:
 Hi!
 Tell me please,are any TypeInfo/typeid/classinfo manipulations 
 possible?
 For example I need a struct that overload typeid, or something 
 like that?

 Some time ago I tried to write some smart pointer that overlad 
 classinfo property  in accordance with the real type of hold 
 object,but I failed to do this becouse of
 not having possibility to declar static and non-static version 
 of the one function.Maybe there are better ways to do this?
Or maybe there are a possibility to parametrize class by TypeInfo?
Oct 26 2012
next sibling parent "Zhenya" <zheny list.ru> writes:
On Friday, 26 October 2012 at 19:57:14 UTC, Zhenya wrote:
 On Thursday, 25 October 2012 at 15:05:05 UTC, Zhenya wrote:
 Hi!
 Tell me please,are any TypeInfo/typeid/classinfo manipulations 
 possible?
 For example I need a struct that overload typeid, or something 
 like that?

 Some time ago I tried to write some smart pointer that overlad 
 classinfo property  in accordance with the real type of hold 
 object,but I failed to do this becouse of
 not having possibility to declar static and non-static version 
 of the one function.Maybe there are better ways to do this?
Or maybe there are a possibility to parametrize class by TypeInfo?
Is my question is so meaningless, that no one even say why? :(
Oct 27 2012
prev sibling parent reply "Maxim Fomin" <maxim maxim-fomin.ru> writes:
On Friday, 26 October 2012 at 19:57:14 UTC, Zhenya wrote:
 On Thursday, 25 October 2012 at 15:05:05 UTC, Zhenya wrote:
 Hi!
 Tell me please,are any TypeInfo/typeid/classinfo manipulations 
 possible?
 For example I need a struct that overload typeid, or something 
 like that?

 Some time ago I tried to write some smart pointer that overlad 
 classinfo property  in accordance with the real type of hold 
 object,but I failed to do this becouse of
 not having possibility to declar static and non-static version 
 of the one function.Maybe there are better ways to do this?
Or maybe there are a possibility to parametrize class by TypeInfo?
What do you mean: "to parametrize class by Typeinfo"? class A { } A!TypeInfo var; If you mean this, than how it can help?
Oct 27 2012
parent reply "Zhenya" <zheny list.ru> writes:
 What do you mean: "to parametrize class by Typeinfo"?

 class A { }
 A!TypeInfo var;

 If you mean this, than how it can help?
It would be well if I could create object that inherits class with this typeinfo.
Oct 27 2012
parent "Zhenya" <zheny list.ru> writes:
I have double dispatcher:

template Dispatcher(R)
{
	R execute(Left,Right)(R delegate(Left,Right) f,Object 
left,Object right)
	{
		return f(cast(Left)left,cast(Right)right);
	}
	struct Dispatcher
	{
		private R 
delegate(Object,Object)[Tuple!(TypeInfo_Class,TypeInfo_Class)] 
m_callbacks;
		void add(Left,Right)(R delegate(Left,Right) f)
		{
			m_callbacks[tuple(Left.classinfo,Right.classinfo)] = (Object 
l,Object r){return execute!(Left,Right)(f,l,r);};
		}
		void remove(Left,Right)()
		{
			m_callbacks.remove(tuple(Left.classinfo,Right.classinfo));
		}
		R opCall(Object l,Object r)
		{
			R delegate(Object,Object)* callback = 
tuple(l.classinfo,r.classinfo) in m_callbacks;
			return (*callback)(l,r);
		}
	}
}

And I have some class ierarhy:

class GameObject
{
}

class Foo : GameObject
{
}

class Bar : GameObject
{
}

problem is to create some wrapper to this classes

struct GameHandle(Type)

and this code work


void main()
{
	Dispatcher!void d;
	d.add!(GameHandle!Foo,GameHandle!Bar)((GameHandle!Foo,GameHandle!Bar){writeln("haha");});
	GameHandle!GameObject a;a.m_hold = new Foo;
	GameHandle!GameObject b;b.m_hold = new Bar;
	d(a,c);
	readln();
}
Oct 27 2012
prev sibling parent "Maxim Fomin" <maxim maxim-fomin.ru> writes:
On Thursday, 25 October 2012 at 15:05:05 UTC, Zhenya wrote:
 Hi!
 Tell me please,are any TypeInfo/typeid/classinfo manipulations 
 possible?
 For example I need a struct that overload typeid, or something 
 like that?
It is impossible to overload typeid typeinfo.
 Some time ago I tried to write some smart pointer that overlad 
 classinfo property  in accordance with the real type of hold 
 object,but I failed to do this becouse of
 not having possibility to declar static and non-static version 
 of the one function.Maybe there are better ways to do this?
I can barely understand what exactly you were doing. If you post some code example it will probably help to find solution.
Oct 27 2012