Project

General

Profile

Bug #427

Standardize factories according to the implementation of ImageFactory

Added by Andreas Huggel over 16 years ago. Updated almost 13 years ago.

Status:
Closed
Priority:
Normal
Category:
miscellaneous
Start date:
Due date:
% Done:

0%

Estimated time:

Description

Various implementations of factories are currently used in Exiv2.
The ImageFactory implementation by Brad seems to be the most advanced.
Other existing factories (in particular MakerNoteFactory) should be changed accordingly.

Additional information:

Extract from private conversation with Brad, 05-Dec-04:

Since this factory is going to be the one that every app uses, the more

user-friendly it is, the better. In that sense, if we don't need the
instance() method, then that would be an improvement.

Ok I found a solution I like that should also work for Makernotes and other
factories if you want me to change them. The nice thing is that it shifts
some burden from library users to library creators.

Two unrelated benefits for users: Removes the need for instance(). More
importantly, no longer have to include mn.cpp in their projects. I am fairly
certain people will forget that since most libraries don't require compiling
in source files (it's also harder to obtain on a win32 machine).

Works like this:
Factory is all static, but to ensure order of initialization all static
methods first call a private init() method that just does this.

void ImageFactory::init()
    {
if (0 == registry_) {
registry_ = new Registry;
}
}

Image subclasses have a public "Register" struct like Makernotes do now. But
they also have a static "global" instance of that struct declared in their
header files (inside Exiv2 namespace, but still global). Static globals have
internal linkage so there are no conflicts between multiple compilation
units that include the headers.

Then we just have to be sure to #include each of the headers that do
registering somewhere that ensures the static globals get initialized. It's
a little weird, but the easiest solution is to #include the Image headers in
image.cpp and Makernotes in exif.cpp (since we know those modules will be
used).

-Brad

Note by ahu: For the pedantic, the includes could be generated, so that image.cpp includes a generated file img.hpp which just includes all Image headers.

History

Also available in: Atom PDF