The main things that I am doing re-factoring is:
- Working through consistent naming.
- Wrapping most the core foundation functions as methods.
typedef const struct __CFData * CFDataRef;What ACS did was to then define the anonymous __CFData and add methods to it. So to add a method that would wrap CFDataGetLength it would did something like this:
typedef struct __CFData * CFMutableDataRef;
struct __CFDataand then defined an implementation for GetLength in terms of CFDataGetLength
{
CFIndex GetLength() const;
};
inline CFIndex __CFData::GetLength() constWhen I started work on the Cello project I actively resisted this in favor of calling (typically) core foundation directly. What I found was that it made life a lot easier if I wrapped all the 'create' or 'copy' functions so that they returned boost::intrusive_ptr wrapped CF types. I did this as I used boost::intrusive_ptr to take care of all the ownership/ownercounting issues. When working on the Sound part of Cello I 'rediscovered' this ACS style wrapping, partly because it just made the code easier to read.
{
return CFDataGetLength(this);
}
It means that instead of calling:
int length = CFDataGetLength(myData);You write:
int length = myData->GetLength();If you are dealing with boost::intrusive_ptr it eleminates a lot of 'get' calls so instead of
int length = CFDataGetLength(myData.get());You write:
int length = myData->GetLength();The other thing that comes into play is that I have had to wrap small amounts of Objective-C so that it can be used in C++. I have opted to keep Objective C out of the general C++ not just to properly isolate the complete madness of two different incompatible types exception handling but also to keep things simpler. It is generally natural to express these as C++ methods
No comments:
Post a Comment