www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Re: serialization library - associative arrays ?

reply Daniel919 <Daniel919 web.de> writes:
 What it does not do/is missing:
 - exception safety / multithread safety
 - out-of-class/struct serialization methods (is it possible to check  
 whether a specific overload exists at compile time?)
 - static arrays need to be serialized with describe_staticarray (static  
 arrays can't be inout, so the general-purpose template method doesn't  
 work... is there a way around the problem?)
 - things I forgot right now

Hi, what about associative arrays ? serialization\basicarchive.d(100): static assert (0) is false, "describe called with unsupported type"
Dec 21 2006
next sibling parent reply "Christian Kamm" <kamm nospam.de> writes:
 Hi, what about associative arrays ?

They're not supported at the moment as I forgot about them. Hm, is there a way to check if a template parameter is an associative array and to get the key and value type without relying on .keys and .values? Cheers, Christian
Dec 21 2006
next sibling parent reply BCS <BCS pathlink.com> writes:
Christian Kamm wrote:
 Hi, what about associative arrays ?

They're not supported at the moment as I forgot about them. Hm, is there a way to check if a template parameter is an associative array and to get the key and value type without relying on .keys and ..values? Cheers, Christian

static if(is(A in B)) ??? IIRC in only works with AAs
Dec 21 2006
parent Lars Ivar Igesund <larsivar igesund.net> writes:
BCS wrote:

 Christian Kamm wrote:
 Hi, what about associative arrays ?

They're not supported at the moment as I forgot about them. Hm, is there a way to check if a template parameter is an associative array and to get the key and value type without relying on .keys and ..values? Cheers, Christian

static if(is(A in B)) ??? IIRC in only works with AAs

opIn is overloadable. -- Lars Ivar Igesund blog at http://larsivi.net DSource & #D: larsivi
Dec 21 2006
prev sibling parent reply "Christian Kamm" <kamm nospam.de> writes:
 Hm, is there a way to check if a template parameter is an associative =

 array and to get the key and value type without relying on .keys and  =

 .values?

What I'm planning on using is: static if( !is(T =3D=3D struct) && !is(T =3D=3D class) && is(typeof(T.keys) KEY =3D=3D KEY[]) && is(typeof(T.values) VALUE =3D=3D VALUE[]) ) { // static assert( is(T =3D=3D VALUE[KEY]) ); } It seems to work, but is rather clumsy. Christian
Dec 21 2006
parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Christian Kamm schrieb am 2006-12-21:
 Hm, is there a way to check if a template parameter is an associative  
 array and to get the key and value type without relying on .keys and  
 .values?

What I'm planning on using is: static if( !is(T == struct) && !is(T == class) && is(typeof(T.keys) KEY == KEY[]) && is(typeof(T.values) VALUE == VALUE[]) ) { // static assert( is(T == VALUE[KEY]) ); } It seems to work, but is rather clumsy.

static if(is(T == typeof(T.values[$])[typeof(T.keys[$])]){ // it is an AA, now do your KEY and VALUE magic } Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFiw7sLK5blCcjpWoRAgo/AJ9tHEUAyHIqMhfQoVpjn5KzflyDGACfVkat ee+l8Xs6TcF0ehosTuNmbcw= =k0XH -----END PGP SIGNATURE-----
Dec 21 2006
parent reply "Christian Kamm" <kamm nospam.de> writes:
 static if(is(T =3D=3D typeof(T.values[$])[typeof(T.keys[$])]){
 	// it is an AA, now do your KEY and VALUE magic
 }

Good idea! However, it doesn't compile for T =3D int, for example (unles= s = that was changed between 0.173 and 0.177): - no property 'keys' for type 'int' Why is T.values[$] allowed, though - and is the [$] neccessary? I've so = = far relied on typeof returning the type of the return value for function= s, = but couldn't find it in the spec. Maybe it would be best to use = is(T.values VALUE =3D=3D return)? Christian
Dec 21 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Christian Kamm schrieb am 2006-12-21:
 static if(is(T == typeof(T.values[$])[typeof(T.keys[$])]){
 	// it is an AA, now do your KEY and VALUE magic
 }

Good idea! However, it doesn't compile for T = int, for example (unless that was changed between 0.173 and 0.177): - no property 'keys' for type 'int'

Wrong order..., this should work: static if(is(typeof(T.values[0])[typeof(T.keys[0])] == T)){ // it is an AA, now do your KEY and VALUE magic }
 Why is T.values[$] allowed, though - and is the [$] neccessary?

purpose. Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFi5eGLK5blCcjpWoRAuezAJ9yI+lvn4loaEZX6LuSIZaynCmsQwCdEwOb eC87B4x3YHpqC9TgYuzInDw= =lhKg -----END PGP SIGNATURE-----
Dec 21 2006
prev sibling parent "Christian Kamm" <kamm nospam.de> writes:
 Hi, what about associative arrays ?

Added support for associative arrays: http://www.math.tu-berlin.de/~kamm/d/serialization.zip I only did a very small unittest for testing the new functionality, so please report further problems and bugs to kamm 'replace with at' math.tu-berlin.de instead of the newsgroup. I've also asked Brad for a project on dsource; once it's set up, further updates will go into the repository there. Christian
Dec 22 2006