tdf#74702 1/2

Adrien Ollier adr.ollier at
Sat Jul 6 17:59:11 UTC 2019

Hello Community,

I am writing this very important e-mail because I need the collaboration of each of you.

I am working on bug #74072<> whose aim is to remove the OutDevType enumeration. OutDevType was introduced to know the real type of an OutputDevice<> at any moment because some functions need the real type of the OutputDevice.

But using this enum is not the good way for doing that. So far, I could quite easily correct this in the OutputDevice's functions by introducing virtual methods. There are still a few OutputDevice's methods that use OutDevType (through GetOutDevType()) but the big majority of remaining functions take an OutputDevice as argument and virtual functions can't help.
The only good way for not using OutDevType can be summarized in this simple sentence:
"If a function needs to know the real type of an object, keep the real type of the object."

Suppose we have the following hierarchy of classes:

class A {/* ... */};
class B : public A {/* ... */};
class C : public A {/* ... */};

And suppose we have the following function:

int g(A* pA);

But g behaves differently according to pA is a A*, a B* or a C*. Instead of introducing an enum to know if pA is a A*, a B* or a C*, the good solution is to have three functions:

int g(A* pA);
int g(B* pB);
int g(C* pC);

This requires to keep the real type of the variable object before calling g.
So we must NOT write this:
A* myVar = new B{};
g(myVar); // calls g(A*)

Instead, we MUST write:
B* myVar = new B{};
g(myVar); // calls g(B*)

But if g() is called by a function f(), f() also requires to keep the real type of the variable. And if f() is called by e(), e() also needs to keep the real type of myVar. And can continue until the first function a() which calls g() by waterfall effect.

If g(B*) and g(C*) have common code, it is not difficul to create a function that factorizes the common code, and to call this function in g(B*) and g(C*).

Using several versions of a function makes its content clean and clear. At any moment we know what kind of variable we are handling. And the choice of a function is made at compile time by the compiler so at runtime it is faster.
The consequence is it multiplies the number of functions. That is the price for clarity and efficiency.

Now what I would like you to do is:
If any of you still use GetOutDevType(), stop using GetOutDev() and any OUTDEV_* value of OutDevType because I work to eliminate them.

I'll continue my message in another e-mail to make this one not too long.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the LibreOffice mailing list