Revision | 2bf97f796b0e2d8e3bac479965a76f72bcbc0eee (tree) |
---|---|
Time | 2007-02-19 20:39:56 |
Author | exeal |
Commiter | exeal |
(empty log message)
@@ -9,6 +9,7 @@ | ||
9 | 9 | #define ASCENSION_INTERNAL_HPP |
10 | 10 | #include "common.hpp" |
11 | 11 | #include <list> |
12 | +#include <stdexcept> | |
12 | 13 | #include <algorithm> |
13 | 14 | #include "../../manah/object.hpp" |
14 | 15 |
@@ -24,17 +25,12 @@ | ||
24 | 25 | template<int v> struct Int2Type {enum{value = v};}; |
25 | 26 | |
26 | 27 | /// Generates signed numeral types. |
27 | - template<class T> class ToSigned { | |
28 | - private: | |
29 | - template<class U> struct X; | |
30 | - template<> struct X<unsigned char> {typedef char Result;}; | |
31 | - template<> struct X<unsigned short> {typedef short Result;}; | |
32 | - template<> struct X<unsigned int> {typedef int Result;}; | |
33 | - template<> struct X<unsigned long> {typedef long Result;}; | |
34 | - template<> struct X<unsigned __int64> {typedef __int64 Result;}; | |
35 | - public: | |
36 | - typedef typename X<T>::Result Result; | |
37 | - }; | |
28 | + template<typename T> struct ToSigned; | |
29 | + template<> struct ToSigned<unsigned char> {typedef char Result;}; | |
30 | + template<> struct ToSigned<unsigned short> {typedef short Result;}; | |
31 | + template<> struct ToSigned<unsigned int> {typedef int Result;}; | |
32 | + template<> struct ToSigned<unsigned long> {typedef long Result;}; | |
33 | +// template<> struct ToSigned<unsigned __int64> {typedef __int64 Result;}; | |
38 | 34 | |
39 | 35 | /** |
40 | 36 | * Searches upper or lower bound. |
@@ -99,39 +95,30 @@ | ||
99 | 95 | listeners_.push_back(&listener); |
100 | 96 | } |
101 | 97 | void remove(Listener& listener) { |
102 | - const std::list<Listener*>::iterator i = std::find(listeners_.begin(), listeners_.end(), &listener); | |
98 | + const Iterator i = std::find(listeners_.begin(), listeners_.end(), &listener); | |
103 | 99 | if(i == listeners_.end()) throw std::invalid_argument("The listener is not registered."); |
104 | 100 | listeners_.erase(i); |
105 | 101 | } |
106 | 102 | void clear() throw() {listeners_.clear();} |
107 | 103 | bool isEmpty() const throw() {return listeners_.empty();} |
108 | 104 | void notify(void(Listener::*method)()) {std::for_each(listeners_.begin(), listeners_.end(), mem_fun(method));} |
109 | - template<class Argument> void notify(void(Listener::*method)(Argument), Argument argument) { | |
110 | - for(std::list<Listener*>::iterator i = listeners_.begin(); i != listeners_.end(); ++i) | |
111 | - ((*i)->*method)(argument); | |
112 | - } | |
113 | - template<class Arg1, class Arg2> | |
105 | + template<typename Argument> void notify(void(Listener::*method)(Argument), Argument argument) { | |
106 | + for(Iterator i = listeners_.begin(); i != listeners_.end(); ++i) ((*i)->*method)(argument); } | |
107 | + template<typename Arg1, typename Arg2> | |
114 | 108 | void notify(void(Listener::*method)(Arg1, Arg2), Arg1 arg1, Arg2 arg2) { |
115 | - for(std::list<Listener*>::iterator i = listeners_.begin(); i != listeners_.end(); ++i) | |
116 | - ((*i)->*method)(arg1, arg2); | |
117 | - } | |
118 | - template<class Arg1, class Arg2, class Arg3> | |
109 | + for(Iterator i = listeners_.begin(); i != listeners_.end(); ++i) ((*i)->*method)(arg1, arg2);} | |
110 | + template<typename Arg1, typename Arg2, typename Arg3> | |
119 | 111 | void notify(void(Listener::*method)(Arg1, Arg2, Arg3), Arg1 arg1, Arg2 arg2, Arg3 arg3) { |
120 | - for(std::list<Listener*>::iterator i = listeners_.begin(); i != listeners_.end(); ++i) | |
121 | - ((*i)->*method)(arg1, arg2, arg3); | |
122 | - } | |
123 | - template<class Arg1, class Arg2, class Arg3, class Arg4> | |
112 | + for(Iterator i = listeners_.begin(); i != listeners_.end(); ++i) ((*i)->*method)(arg1, arg2, arg3);} | |
113 | + template<typename Arg1, typename Arg2, typename Arg3, typename Arg4> | |
124 | 114 | void notify(void(Listener::*method)(Arg1, Arg2, Arg3, Arg4), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4) { |
125 | - for(std::list<Listener*>::iterator i = listeners_.begin(); i != listeners_.end(); ++i) | |
126 | - ((*i)->*method)(arg1, arg2, arg3, arg4); | |
127 | - } | |
115 | + for(Iterator i = listeners_.begin(); i != listeners_.end(); ++i) ((*i)->*method)(arg1, arg2, arg3, arg4);} | |
128 | 116 | template<class Arg1, class Arg2, class Arg3, class Arg4, class Arg5> |
129 | 117 | void notify(void(Listener::*method)(Arg1, Arg2, Arg3, Arg4, Arg5), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5) { |
130 | - for(std::list<Listener*>::iterator i = listeners_.begin(); i != listeners_.end(); ++i) | |
131 | - ((*i)->*method)(arg1, arg2, arg3, arg4, arg5); | |
132 | - } | |
118 | + for(Iterator i = listeners_.begin(); i != listeners_.end(); ++i) ((*i)->*method)(arg1, arg2, arg3, arg4, arg5);} | |
133 | 119 | private: |
134 | 120 | std::list<Listener*> listeners_; |
121 | + typedef std::list<Listener*> Iterator; | |
135 | 122 | }; |
136 | 123 | |
137 | 124 | #ifdef _WINDOWS_ |
@@ -165,10 +152,13 @@ | ||
165 | 152 | #define ASCENSION_END_SHARED_LIB_ENTRIES() \ |
166 | 153 | }; |
167 | 154 | |
168 | - template<class T> void alert(const T& t) { | |
155 | + template<typename T> void alert(const T& t) { | |
169 | 156 | OutputStringStream s; |
170 | 157 | s << t; |
158 | +#ifdef _WINDOWS_ | |
171 | 159 | ::MessageBoxW(0, s.str().c_str(), L"alert", MB_OK); |
160 | +#else | |
161 | +#endif | |
172 | 162 | } |
173 | 163 | |
174 | 164 | } // namespace internal |