|
|
Home » U++ Library support » U++ Core » How to know if a package is loaded
How to know if a package is loaded [message #29497] |
Sun, 24 October 2010 22:17 |
|
koldo
Messages: 3361 Registered: August 2008
|
Senior Veteran |
|
|
Hello all
A simple question: How a cpp source can know if a package is loaded?
Imagine a general purpose library that includes some feature for GridCtrl package. If the programmer uses this package but s/he does not include GridCtrl, there will be a linking error.
Of course it is possible to use flags in the main package configuration but, is there another cleaner way?
Best regards
Iñaki
|
|
|
Re: How to know if a package is loaded [message #29501 is a reply to message #29497] |
Mon, 25 October 2010 08:27 |
|
koldo wrote on Sun, 24 October 2010 22:17 | Hello all
A simple question: How a cpp source can know if a package is loaded?
Imagine a general purpose library that includes some feature for GridCtrl package. If the programmer uses this package but s/he does not include GridCtrl, there will be a linking error.
Of course it is possible to use flags in the main package configuration but, is there another cleaner way?
|
Hi Koldo,
I'm afraid there is no direct and reliable way.
The closest you can do is probably convert the feature into template. If the user doesn't use the necessary package he shouldn't instantiate the template and everything should link just fine.
BTW: Adding this to theide would be great, I hit this issue few times too. And it should be quite simple to code, just extend the Accept field in .upp files/package manager. Let's say adding GridCtrl to Accept would cause flagGridCtrl macro to be defined if the package is used in the current project. The only problem I see is that packages using this could cause trouble with older versions of theide. But probably nothing too serious, it would just omit the extending features. Do you think I should try to implement it?
Best regards,
Honza
|
|
|
|
Re: How to know if a package is loaded [message #29506 is a reply to message #29503] |
Mon, 25 October 2010 10:00 |
|
luzr wrote on Mon, 25 October 2010 08:37 |
koldo wrote on Sun, 24 October 2010 16:17 | How a cpp source can know if a package is loaded?
Imagine a general purpose library that includes some feature for GridCtrl package. If the programmer uses this package but s/he does not include GridCtrl, there will be a linking error.
|
Does not it give a nice and simple answer?
BTW, the case described above is a bug of the library - it should have add "GridCtrl" in its 'uses'.
Mirek
|
We can try to ask once more, being nicer this time
Anyway I think what Koldo meant (and me too) is that sometimes it is better to make some extension voluntary. GridCtrl is not the best example, but imagine you would like to provide some extension of the stuff in MySql package - then adding it into your package would make the whole thing unusable on computers which don't have the mysql library installed. But if you could detect if the MySql is already used, than it would be safe to use it. Otherwise, you would just #ifdef out the MySql related parts and everyone would be happy (especially linker ).
Honza
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Sat May 11 13:01:40 CEST 2024
Total time taken to generate the page: 0.02930 seconds
|
|
|