]> git.cworth.org Git - vogl/blob - src/extlib/loki/src/OrderedStatic.cpp
Initial vogl checkin
[vogl] / src / extlib / loki / src / OrderedStatic.cpp
1 ////////////////////////////////////////////////////////////////////////////////
2 // The Loki Library
3 // Copyright (c) 2005 Peter Kümmel
4 // Permission to use, copy, modify, distribute and sell this software for any
5 //     purpose is hereby granted without fee, provided that the above copyright
6 //     notice appear in all copies and that both that copyright notice and this
7 //     permission notice appear in supporting documentation.
8 // The author makes no representations about the
9 //     suitability of this software for any purpose. It is provided "as is"
10 //     without express or implied warranty.
11 ////////////////////////////////////////////////////////////////////////////////
12
13 // $Id: OrderedStatic.cpp 756 2006-10-17 20:05:42Z syntheticpp $
14
15
16 #include <loki/OrderedStatic.h>
17 #include <limits>
18
19 #ifdef min
20 #undef min
21 #endif
22
23 #ifdef max
24 #undef max
25 #endif
26
27 namespace Loki
28 {
29 namespace Private
30 {
31
32 OrderedStaticCreatorFunc::OrderedStaticCreatorFunc()
33 {
34 }
35
36 OrderedStaticCreatorFunc::~OrderedStaticCreatorFunc()
37 {
38 }
39
40
41 OrderedStaticManagerClass::OrderedStaticManagerClass() :
42         staticObjects_(),
43         max_longevity_(std::numeric_limits<unsigned int>::min()),
44         min_longevity_(std::numeric_limits<unsigned int>::max())
45 {
46 }
47
48 OrderedStaticManagerClass::~OrderedStaticManagerClass()
49 {
50 }
51
52 void OrderedStaticManagerClass::createObjects()
53 {
54         for(unsigned int longevity=max_longevity_; longevity>=min_longevity_; longevity--)
55         {
56                 for(unsigned int i=0; i<staticObjects_.size(); i++)
57                 {
58                         Data cur = staticObjects_.at(i);
59                         if(cur.longevity==longevity)
60                                 ( (*cur.object).*cur.creator )();
61                 }
62         }
63 }
64
65 void OrderedStaticManagerClass::registerObject(unsigned int l, OrderedStaticCreatorFunc *o,Creator f)
66 {
67         staticObjects_.push_back(Data(l,o,f));
68
69         if(l>max_longevity_) max_longevity_=l;
70         if(l<min_longevity_) min_longevity_=l;
71 }
72
73 OrderedStaticManagerClass::Data::Data(unsigned int l, OrderedStaticCreatorFunc *o, Creator f)
74         : longevity(l), object(o), creator(f)
75 {
76 }
77
78 }//namespace Private
79
80 } // end namespace Loki
81