Thread overview
#define trouble
Nov 27, 2012
dnewbie
Nov 27, 2012
Ali Çehreli
Nov 27, 2012
dnewbie
November 27, 2012
I have the following C struct from ldap.h

typedef struct ldapmod {
	int	mod_op;
	char *mod_type;
	union mod_vals_u {
		char **modv_strvals;
		struct berval **modv_bvals;
	} mod_vals;
#define mod_values	mod_vals.modv_strvals
#define mod_bvalues	mod_vals.modv_bvals
} LDAPMod;

It is used like this:
LDAPMod title;
title.mod_values = x;

I wonder how can I write the line 'title.mod_values = x;' in D.
Currently I do like this:
	
struct ldapmod {
	int	mod_op;
	char* mod_type;
	union mod_vals_u {
		char**  modv_strvals;
		berval** modv_bvals;
	}
	mod_vals_u mod_vals;
}
alias ldapmod LDAPMod;

LDAPMod title;
title.mod_vals.modv_strvals = x;


November 27, 2012
On 11/26/2012 10:05 PM, dnewbie wrote:
> I have the following C struct from ldap.h
>
> typedef struct ldapmod {
> int mod_op;
> char *mod_type;
> union mod_vals_u {
> char **modv_strvals;
> struct berval **modv_bvals;
> } mod_vals;
> #define mod_values mod_vals.modv_strvals
> #define mod_bvalues mod_vals.modv_bvals
> } LDAPMod;
>
> It is used like this:
> LDAPMod title;
> title.mod_values = x;
>
> I wonder how can I write the line 'title.mod_values = x;' in D.
> Currently I do like this:
>
> struct ldapmod {
> int mod_op;
> char* mod_type;
> union mod_vals_u {
> char** modv_strvals;
> berval** modv_bvals;
> }
> mod_vals_u mod_vals;
> }
> alias ldapmod LDAPMod;
>
> LDAPMod title;
> title.mod_vals.modv_strvals = x;
>
>

A pair of @property functions would work, one of which may be unnecessary:

alias int berval;

struct ldapmod {
    int    mod_op;
    char* mod_type;
    union mod_vals_u {
        char**  modv_strvals;
        berval** modv_bvals;
    }
    mod_vals_u mod_vals;

    char** mod_values() @property
    {
        return mod_vals.modv_strvals;
    }

    void mod_values(char** value) @property
    {
        mod_vals.modv_strvals = value;
    }

    // similarly for mod_bvalues...
}
alias ldapmod LDAPMod;

void main()
{
    LDAPMod title;
    char** x;
    // title.mod_vals.modv_strvals = x;
    title.mod_values = x;
}


Ali
November 27, 2012
On Tuesday, 27 November 2012 at 06:27:49 UTC, Ali Çehreli wrote:
> On 11/26/2012 10:05 PM, dnewbie wrote:
>> I have the following C struct from ldap.h
>>
>> typedef struct ldapmod {
>> int mod_op;
>> char *mod_type;
>> union mod_vals_u {
>> char **modv_strvals;
>> struct berval **modv_bvals;
>> } mod_vals;
>> #define mod_values mod_vals.modv_strvals
>> #define mod_bvalues mod_vals.modv_bvals
>> } LDAPMod;
>>
>> It is used like this:
>> LDAPMod title;
>> title.mod_values = x;
>>
>> I wonder how can I write the line 'title.mod_values = x;' in D.
>> Currently I do like this:
>>
>> struct ldapmod {
>> int mod_op;
>> char* mod_type;
>> union mod_vals_u {
>> char** modv_strvals;
>> berval** modv_bvals;
>> }
>> mod_vals_u mod_vals;
>> }
>> alias ldapmod LDAPMod;
>>
>> LDAPMod title;
>> title.mod_vals.modv_strvals = x;
>>
>>
>
> A pair of @property functions would work, one of which may be unnecessary:
>
> alias int berval;
>
> struct ldapmod {
>     int    mod_op;
>     char* mod_type;
>     union mod_vals_u {
>         char**  modv_strvals;
>         berval** modv_bvals;
>     }
>     mod_vals_u mod_vals;
>
>     char** mod_values() @property
>     {
>         return mod_vals.modv_strvals;
>     }
>
>     void mod_values(char** value) @property
>     {
>         mod_vals.modv_strvals = value;
>     }
>
>     // similarly for mod_bvalues...
> }
> alias ldapmod LDAPMod;
>
> void main()
> {
>     LDAPMod title;
>     char** x;
>     // title.mod_vals.modv_strvals = x;
>     title.mod_values = x;
> }
>
>
> Ali


Perfect! Thank you.