All pastes #539684 Raw Edit

spam

public cpp v1 · immutable
·published 2007-06-05 09:29 UTC
rendered paste body
#include "RegistryAccess.h"#include "Class.h"#include "ClassBuilder.h"#include "GetType.h"#include "BuiltinTypes.h"#include "Reference.h"//----------------------------------------------------------------------------------------#include <iostream>#include <assert.h>using namespace std;struct Servant0{	int N;	Servant0()	{		N = 42;	}	static void Register(Registry &R)	{		ClassBuilder<Servant0>(R, "Servant0")			(&Servant0::Method0, "Method0")			(&Servant0::Method1, "Method1")			;	}	void Method0()	{	}	void Method1(int N)	{	}};struct Servant1 : ServerBase{	static void Register(Registry &R)	{		ClassBuilder<Servant1>(R, "Servant1")			(&Servant1::foo, "foo")			(&Servant1::bar, "bar")			;	}	void foo(int N, String S)	{		cout << "Servant1::foo: ";		while (N-- > 0) cout << S;		cout << endl;	}	void bar(String S, Servant0 Q)	{		cout << "Servant1::bar: S=" << S << ", Q.N=" << Q.N << endl;	}};namespace Type{	template <>	struct Traits<Servant0> : MakeTraits<Servant0, 1000> { };	template <>	struct Traits<Servant1> : MakeTraits<Servant1, 1001> { };}#include <fstream>			 int main(){	Registry R;	Servant0::Register(R);	Servant1::Register(R);	Pointer<Servant0> S0 = R.New<Servant0>();	Pointer<Servant1> S1 = R.New<Servant1>();		Object Q0 = S0;// GCC WTF?	Reference<Servant0> V0 = Q0;	Pointer<int> N = R.New<int>(3);	Pointer<String> S = R.New<String>("Hello ");		Stack args;	args.PushBack(S0);	args.PushBack(R.New<String>("World"));	args.PushBack(S);	args.PushBack(N);	ClassBase *K = R.GetClassBase(Type::Traits<Servant1>::TypeNumber);	K->GetMethod("foo").Invoke(&*S1, args);	K->GetMethod("bar").Invoke(&*S1, args);		cout << "\n------\n";		fstream file("/tmp/types.xml", ios::out);	String classes = R.WriteClassesXML();	file << classes;	cout << classes;	}//EOF