[geos-devel] Question about geos::io::Unload::Release()
strk at refractions.net
strk at refractions.net
Mon Mar 13 06:05:32 EST 2006
On Sun, Mar 12, 2006 at 12:45:31PM +0100, Mateusz Å?oskot wrote:
> strk at refractions.net wrote:
> >static lifetime should be ok. I dunno if it's used by client code,
> >anyway it might be useful to have a 'default' factory to use instead
> >of having to construct (and maintain alive) a custom one. I'd move
> >access to it to GeometryFactory::defaultInstance()
>
> I see the idea behind default factory.
> So, I'd make it a singleton, constructed on first request of its
> instance. As I understand defaultInstance() is sucha a solution.
> The only problem is to properly define Singleton class.
>
> Here is some simple proposal:
... mmm .. simple ? :)
How about:
class PrecisionModel {
public:
.....
const PrecisionModel* defaultInstance() {
static PrecisionModel defInstance(PrecisionModel::defaultInstance());
return &defInstance;
}
};
class GeometryFactory {
public:
.....
const GeometryFactory* defaultInstance() {
static GeometryFactory defInstance(PrecisionModel::defaultInstance());
return &defInstance;
}
};
--strk;
>
> template<class T>
> class Singleton
> {
> private:
>
> class InstancePtr
> {
> public:
> InstancePtr() : m_ptr(0) {}
> ~InstancePtr() { delete m_ptr; }
>
> T* Get()
> {
> return m_ptr;
> }
>
> void Set(T* p)
> {
> if(p!= 0)
> {
> if (m_ptr != 0)
> {
> delete m_ptr;
> }
> m_ptr = p;
> }
> }
>
> private:
>
> T* m_ptr;
> };
>
> static InstancePtr m_instptr;
>
> Singleton();
>
> Singleton(const Singleton&);
>
> Singleton& operator=(const Singleton&);
>
> public:
>
> static T* Instance()
> {
> if(m_instptr.Get() == 0)
> {
> m_instptr.Set(new T());
> }
> return m_instptr.Get();
> }
> };
>
> But it may be better defined using smart pointers as well.
>
> Cheers
> --
> Mateusz Åoskot
> http://mateusz.loskot.net
> _______________________________________________
> geos-devel mailing list
> geos-devel at geos.refractions.net
> http://geos.refractions.net/mailman/listinfo/geos-devel
--
----------------------------------------------------------------------
State-collected Geographic Data is public property !
Reject the INSPIRE directive.
Sign the petition: http://petition.publicgeodata.org
More information about the geos-devel
mailing list