Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
koldo is currently offline  koldo
Messages: 3357
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 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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 #29503 is a reply to message #29497] Mon, 25 October 2010 08:37 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
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? Smile

BTW, the case described above is a bug of the library - it should have add "GridCtrl" in its 'uses'.

Mirek

[Updated on: Mon, 25 October 2010 08:39]

Report message to a moderator

Re: How to know if a package is loaded [message #29506 is a reply to message #29503] Mon, 25 October 2010 10:00 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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? Smile

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 Very Happy

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 Smile ).

Honza
Re: How to know if a package is loaded [message #29507 is a reply to message #29506] Mon, 25 October 2010 12:18 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Yes, thank you Honza

In addition we try to link the minimum number of libraries possible. If in a project it is not necessary to use GridCtrl, I prefer not to link GridCtrl and the part of the library that interacts with it.


Best regards
Iñaki
Re: How to know if a package is loaded [message #29528 is a reply to message #29507] Wed, 27 October 2010 08:12 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, while not completely ideal, sometimes you can achieve this (or something quite related) using function pointers.

We are already doing this for Painter <-> Draw, PdfDraw <-> Report, Painter <-> Report.

Also, Image format somewhat represent this case...
Re: How to know if a package is loaded [message #29536 is a reply to message #29528] Wed, 27 October 2010 16:33 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Mirek

It is true but not useful as in those cases the packages contain subclasses and register themselves in any way when loaded, like RegisterPaintingFns__ with Draw and StreamRaster::Register with Raster Smile.


Best regards
Iñaki
Re: How to know if a package is loaded [message #29538 is a reply to message #29536] Wed, 27 October 2010 19:34 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Wed, 27 October 2010 10:33

Hello Mirek

It is true but not useful as in those cases the packages contain subclasses and register themselves in any way when loaded, like RegisterPaintingFns__ with Draw and StreamRaster::Register with Raster Smile.


Suggest and implement solution to the problem then Smile

I suspect it would not be that easy I am afraid... And it would perhaps make U++ even more dependent on theide building scheme.
Re: How to know if a package is loaded [message #29541 is a reply to message #29538] Wed, 27 October 2010 22:43 Go to previous message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Mirek

You are right. You have convinced me with this:
And it would perhaps make U++ even more dependent on theide building scheme.

That is a bad feature... forget about it Smile.


Best regards
Iñaki
Previous Topic: RichPickToValue PROPOSAL
Next Topic: First use of SetVppLogName will call sOpenVppLog twice
Goto Forum:
  


Current Time: Sun Apr 28 01:59:40 CEST 2024

Total time taken to generate the page: 3.07360 seconds