Date: prev next · Thread: first prev next last
2019 Archives by date, by thread · List index


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<https://bugs.documentfoundation.org/show_bug.cgi?id=74702> whose aim is 
to remove the OutDevType enumeration. OutDevType was introduced to know the real type of an 
OutputDevice<https://docs.libreoffice.org/vcl/html/classOutputDevice.html> 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.

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.