OrderedStatic.cpp

00001 
00002 // The Loki Library
00003 // Copyright (c) 2005 Peter Kümmel
00004 // Permission to use, copy, modify, distribute and sell this software for any 
00005 //     purpose is hereby granted without fee, provided that the above copyright 
00006 //     notice appear in all copies and that both that copyright notice and this 
00007 //     permission notice appear in supporting documentation.
00008 // The author makes no representations about the 
00009 //     suitability of this software for any purpose. It is provided "as is" 
00010 //     without express or implied warranty.
00012 
00013 // $Id: OrderedStatic.cpp 756 2006-10-17 20:05:42Z syntheticpp $
00014 
00015 
00016 #include <loki/OrderedStatic.h>
00017 #include <limits>
00018 
00019 #ifdef min 
00020 #undef min 
00021 #endif
00022  
00023 #ifdef max 
00024 #undef max 
00025 #endif 
00026 
00027 namespace Loki
00028 {
00029     namespace Private
00030     {
00031 
00032         OrderedStaticCreatorFunc::OrderedStaticCreatorFunc()
00033         {
00034         }
00035         
00036         OrderedStaticCreatorFunc::~OrderedStaticCreatorFunc()
00037         {
00038         }
00039     
00040 
00041         OrderedStaticManagerClass::OrderedStaticManagerClass() :
00042                     staticObjects_(),
00043                     max_longevity_(std::numeric_limits<unsigned int>::min()),
00044                     min_longevity_(std::numeric_limits<unsigned int>::max())
00045         {
00046         }
00047 
00048         OrderedStaticManagerClass::~OrderedStaticManagerClass()
00049         {
00050         }
00051 
00052         void OrderedStaticManagerClass::createObjects()
00053         {
00054             for(unsigned int longevity=max_longevity_; longevity>=min_longevity_; longevity--)
00055             {
00056                 for(unsigned int i=0; i<staticObjects_.size(); i++)
00057                 {
00058                     Data cur = staticObjects_.at(i);
00059                     if(cur.longevity==longevity)
00060                         ( (*cur.object).*cur.creator )();
00061                 }
00062             }
00063         }
00064 
00065         void OrderedStaticManagerClass::registerObject(unsigned int l, OrderedStaticCreatorFunc* o,Creator f)
00066         {
00067             staticObjects_.push_back(Data(l,o,f));
00068 
00069             if(l>max_longevity_) max_longevity_=l;
00070             if(l<min_longevity_) min_longevity_=l;
00071         }
00072 
00073         OrderedStaticManagerClass::Data::Data(unsigned int l, OrderedStaticCreatorFunc* o, Creator f)
00074             : longevity(l), object(o), creator(f)
00075         {
00076         }
00077 
00078     }//namespace Private
00079 
00080 } // end namespace Loki
00081 

Generated on Sun Feb 25 16:52:26 2007 for Loki by  doxygen 1.5.1-p1