Wrapping C functions in Objective C proxy objects: naming convention?
Wrapping C functions in Objective C proxy objects: naming convention?
- Subject: Wrapping C functions in Objective C proxy objects: naming convention?
- From: "Austin Ziegler" <email@hidden>
- Date: Thu, 20 Nov 2008 00:27:22 -0500
For a project that I'm working on, I have a need to write a code
generator that will wrap certain kinds of C functions as Objective C
messages on an Objective C proxy. Because I don't ultimately control
the input, the parameters on the C functions may be poorly named. I'm
looking for advice on how one might make useful object message names
from C functions.
The format of the functions in question is essentially like this[1]:
int ns__add(double a, double b, double *result);
int ns__sub(double a, double b, double *result);
int ns__mul(double a, double b, double *result);
int ns__div(double a, double b, double *result);
int ns__pow(double a, double b, double *result);
The int return is a status code; the result of the operation is in
double* result. If there's an error in the operation. (The status code
may be ignorable, in which case part of my following question is
answered; I'm still researching this part. I suspect that it is best
not ignored.)
Anyway, the problem is how I should convert this function with poorly
named parameters into a proxy object and messages?
The options that I've come up with (expressed in terms of use) follow.
They're all expressed in terms of an object ns__CalcProxy:
ns__CalcProxy calc = [[ns__CalcProxy alloc] init];
double a, b, result;
int status;
result = [calc addDoubleA:a withDoubleB:b]; // #1
result = [calc addDoubleA:a withDoubleB:b status:&status]; // #2
status = [calc addDoubleA:a withDoubleB:b returning:&result]; // #3
The examples given here are simple; the items being returned may in
fact be pretty complex (and I'm planning on making it so that
structured parameters and return values may be passed in Objective C
proxies themselves).
I really don't like the "addDoubleA:withDoubleB:" name, to be honest,
but what am I supposed to do with:
struct ns1__ludcmpResponse {matrix *a; ivector *i; xsd__double d;};
int ns1__ludcmp(matrix *a, struct ns1__ludcmpResponse** result);
Like I said; I don't really have any control over the names of the
parameters, more's the pity.
-austin
[1] Actually, they're more like this:
int soap_call_ns__add(struct soap *soap, const char *soap_endpoint,
const char *soap_action, double a, double b, double *result);
But there's enough information in there for me to extract the former
to use as a proxy function.
--
Austin Ziegler * email@hidden * http://www.halostatue.ca/
* email@hidden * http://www.halostatue.ca/feed/
* email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden