I'm currently working on a C++ header for encoding and decoding text. To be exact: UTF-8, UTF-16, UCS-2 and UTF-32. But I've come to a point where my C++ knowledge won't get me any further:
I'd like to use an abstract class for decoding and encoding, while creating base classes for each codec. Then, if using any function related to encoding or decoding, the dev should be able to just pass a custom data type to the function.
The problem is that I don't have any clue how to actually do this. After all, you can't pass a static class as a parameter. But I don't want to hardcode anything either; the dev should also be able to add any codec without much trouble and without modifying my header.
Also, it should be as easy as possible. The code would look something like this:
namespace Encoding {
class Encoder {
public:
virtual std::string Encode(std::string sOriginal) = 0;
};
// Derived classes like UTF8 and UCS2 here
}
void OutputEncoded(std::string s, Encoder enc) {
std::cout << enc.Encode(s);
}
int main() {
OutputEncoded("Hellö Wörld!", Encoding::UTF8);
}
Any idea how to do this? Maybe a way without creating an object but with just the static methods? Or do I have to use an object with a pointer?