2005-10-05 17:56:11 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// The Loki Library
|
|
|
|
|
// Copyright (c) 2005 Peter K<>mmel
|
|
|
|
|
// Permission to use, copy, modify, distribute and sell this software for any
|
|
|
|
|
// purpose is hereby granted without fee, provided that the above copyright
|
|
|
|
|
// notice appear in all copies and that both that copyright notice and this
|
|
|
|
|
// permission notice appear in supporting documentation.
|
|
|
|
|
// The author makes no representations about the
|
|
|
|
|
// suitability of this software for any purpose. It is provided "as is"
|
|
|
|
|
// without express or implied warranty.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2006-10-17 20:02:15 +00:00
|
|
|
|
// $Id$
|
|
|
|
|
|
2005-10-05 17:56:11 +00:00
|
|
|
|
|
2006-01-05 00:23:44 +00:00
|
|
|
|
#include <loki/OrderedStatic.h>
|
2005-10-05 17:56:11 +00:00
|
|
|
|
#include <limits>
|
|
|
|
|
|
2006-03-27 16:09:57 +00:00
|
|
|
|
#ifdef min
|
|
|
|
|
#undef min
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef max
|
|
|
|
|
#undef max
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-10-05 17:56:11 +00:00
|
|
|
|
namespace Loki
|
|
|
|
|
{
|
2005-10-17 13:08:34 +00:00
|
|
|
|
namespace Private
|
|
|
|
|
{
|
2005-10-05 17:56:11 +00:00
|
|
|
|
|
2005-10-17 13:08:34 +00:00
|
|
|
|
OrderedStaticCreatorFunc::OrderedStaticCreatorFunc()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OrderedStaticCreatorFunc::~OrderedStaticCreatorFunc()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-05 17:56:11 +00:00
|
|
|
|
|
2005-10-17 13:08:34 +00:00
|
|
|
|
OrderedStaticManagerClass::OrderedStaticManagerClass() :
|
2006-01-18 17:21:31 +00:00
|
|
|
|
staticObjects_(),
|
2005-10-17 13:08:34 +00:00
|
|
|
|
max_longevity_(std::numeric_limits<unsigned int>::min()),
|
|
|
|
|
min_longevity_(std::numeric_limits<unsigned int>::max())
|
|
|
|
|
{
|
|
|
|
|
}
|
2005-10-05 17:56:11 +00:00
|
|
|
|
|
2005-10-17 13:08:34 +00:00
|
|
|
|
OrderedStaticManagerClass::~OrderedStaticManagerClass()
|
|
|
|
|
{
|
|
|
|
|
}
|
2005-10-05 17:56:11 +00:00
|
|
|
|
|
2005-10-17 13:08:34 +00:00
|
|
|
|
void OrderedStaticManagerClass::createObjects()
|
|
|
|
|
{
|
|
|
|
|
for(unsigned int longevity=max_longevity_; longevity>=min_longevity_; longevity--)
|
|
|
|
|
{
|
|
|
|
|
for(unsigned int i=0; i<staticObjects_.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
Data cur = staticObjects_.at(i);
|
|
|
|
|
if(cur.longevity==longevity)
|
|
|
|
|
( (*cur.object).*cur.creator )();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-10-05 17:56:11 +00:00
|
|
|
|
|
2005-10-17 13:08:34 +00:00
|
|
|
|
void OrderedStaticManagerClass::registerObject(unsigned int l, OrderedStaticCreatorFunc* o,Creator f)
|
|
|
|
|
{
|
|
|
|
|
staticObjects_.push_back(Data(l,o,f));
|
2005-10-05 17:56:11 +00:00
|
|
|
|
|
2005-10-17 13:08:34 +00:00
|
|
|
|
if(l>max_longevity_) max_longevity_=l;
|
|
|
|
|
if(l<min_longevity_) min_longevity_=l;
|
|
|
|
|
}
|
2005-10-05 17:56:11 +00:00
|
|
|
|
|
2005-10-17 13:08:34 +00:00
|
|
|
|
OrderedStaticManagerClass::Data::Data(unsigned int l, OrderedStaticCreatorFunc* o, Creator f)
|
2006-01-18 17:21:31 +00:00
|
|
|
|
: longevity(l), object(o), creator(f)
|
2005-10-17 13:08:34 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2005-10-05 17:56:11 +00:00
|
|
|
|
|
2005-10-17 13:08:34 +00:00
|
|
|
|
}//namespace Private
|
2005-10-05 17:56:11 +00:00
|
|
|
|
|
2006-10-17 20:05:42 +00:00
|
|
|
|
} // end namespace Loki
|
2005-10-05 17:56:11 +00:00
|
|
|
|
|