20090731

Core Foundation meets C++

I am tired of dealing with Core Foundation ornerinesses in a program primarily written in C++, so I decided to write a library of RAII wrappers for Core Foundation classes I use commonly.

My first problem was that I didn't really understand about overloading assignment operators, but I think I've figured them out now.

The next concern is that for many types, there are mutable and immutable version, which differ only by a const in their typedef to the opaque underlying type. My first thought was to implement, for example, CFMutableArrayRef and CFArrayRef wrappers separately.

My next thought was to set up some kind of inheritance.
Inheritance fails, however. If we want to say that the wrapper for the immutable inherits from the mutable, and makes some member functions/operators private, then we'll run into the problem that an instance of a derived class must be able to function as an object of the base class, and a derived class wrapping an immutable object cannot act the same as a base object that is mutable.

Third try: Make the private data member mutable, but provide a const "conversion operator" that will make it act like it's immutable. This seems like the best option so far.

I am planning to make the library available once it's usable. I am still deciding on the licensing system I wish to use, but I think I am leaning toward BSD-style, or maybe Creative Commons.

1 comment:

  1. Maybe the string was in fact Latin1 (0-255), not ASCII (0-127), and since Latin1 is not valid UTF8, the decoding from UTF8 failed on first Latin1 character. Are you sure there is no copyright sign or euro sign or whatever in the string? Or if the characters are truly random, are you making sure they are ASCII, i.e. 0-127 only (setting the highest char bit to 0)? Just a thought. (maybe try with kCFStringEncodingISOLatin1 to see if this one does not fail, then it would be as I said).

    ReplyDelete