Libs, headers and external libs.

Started by
3 comments, last by CableGuy 15 years, 8 months ago
Hi. I have created a library to use FreeType and I have a problem:

class FontResource
{
	friend class Renderer;
public:
	FontResource();
	
	bool Load(const string &name);		
	bool Load(const string &name,int size);	
private:
	bool AddChar(char c);
	vector<Glyph> glyph;
	FontPage *page;
	FT_Face face;
	int size;
};

As you can see I need to store FT_Face which is part of FreeType, which forces the users of my code also to include the FreeType headers. One way around it that I came up with is to store a void* and cast it in the source but that's too much hacky... Any ideas how to sort this out? Thanks.
Advertisement
If I wasn't clear enough just say so...
Pimpl.

Basic idea is, using a different example:

lib.h
class Texture{private:    class Imp; Imp *i; // forward declaration, can only use pointers and referencespublic:    Texture();    ~Texture();};


lib.cpp
#include <d3d9.h>class Texture::Imp{public:    Imp() : Ptr(0) { }    ~Imp(){ if(Ptr) Ptr->Release(); }    IDirect3DTexture9 *Ptr;}Texture::Texture(){    i=new Imp(); i->Ptr=CreateTextureSomehow();}Texture::~Texture(){    delete i;}


This way, users including lib.h do not need to include, or even be aware of, d3d9.h or have any of its symbols dumped into global scope. Indeed you could change the implementation to use OpenGL and you would only have to recompile the library file and relink the project that uses it.

The link at the top will explain in far more detail.
Or you can use a pointer to an FT_Face. You don't need to include the FreeType header for that, but you do need to do some extra memory management for it.
Thanks.

This topic is closed to new replies.

Advertisement