![]() |
Home · All Classes · alphabetical Classes List · Modules · Functions · |
Application code generally doesn't have to be concerned about hiding its implementation details, but when writing library code it is important to maintain a constant interface, both source and binary. Maintaining a constant source interface is easy enough, but keeping the binary interface constant means moving implementation details into a private class. The PIMPL, or d-pointer, idiom is a common method of implementing this separation. QxtPimpl offers a convenient way to connect the public and private sides of your class.
class MyTestPrivate;
private: QXT_DECLARE_PRIVATE(MyTest);
Additionally, you must include the QXT_INIT_PRIVATE macro in the public class's constructor. Continuing with the MyTest example, your constructor might look like this:
MyTest::MyTest() { // initialization QXT_INIT_PRIVATE(MyTest); }
To define the private class, inherit from the template QxtPrivate class, and include the QXT_DECLARE_PUBLIC macro in its public section. The template parameter should be the name of the public class. For example:
class MyTestPrivate : public QxtPrivate<MyTest> { public: MyTestPrivate(); QXT_DECLARE_PUBLIC(MyTest); };
For example, assume that MyTest has methods named getFoobar and doBaz(), and MyTestPrivate has a member named foobar and a method named doQuux(). The code might resemble this example:
int MyTest::getFoobar() { return qxt_d().foobar; } void MyTestPrivate::doQuux() { qxt_p().doBaz(foobar); }
Declares that a public class has a related private class.
This shuold be put in the private section of the public class. The parameter is the name of the public class.
Declares that a private class has a related public class.
This may be put anywhere in the declaration of the private class. The parameter is the name of the public class.
Initializes resources owned by the private class.
This should be called from the public class's constructor, before qxt_d() is used for the first time. The parameter is the name of the public class.
Returns a reference to the private class.
This function is only available in a class using QXT_DECLARE_PRIVATE.
Returns a reference to the public class.
This function is only available in a class using QXT_DECLARE_PUBLIC.
(c) 2007A.Picciani and A.Higerd LGPL | libqxt 0.2 |