2323#ifndef SNAPPER_SNAPPER_TMPL_H
2424#define SNAPPER_SNAPPER_TMPL_H
2525
26- # include < functional >
26+
2727#include < ostream>
2828#include < fstream>
2929#include < sstream>
3232
3333#include " snapper/AppUtil.h"
3434
35+
3536namespace snapper
3637{
3738 using std::string;
@@ -47,6 +48,7 @@ namespace snapper
4748 return num_str.str ();
4849 }
4950
51+
5052 template <class Num > string hexString (Num number)
5153 {
5254 static_assert (std::is_integral<Num>::value, " not integral" );
@@ -57,13 +59,15 @@ namespace snapper
5759 return num_str.str ();
5860 }
5961
62+
6063 template <class Value > void operator >>(const string& d, Value& v)
6164 {
6265 std::istringstream Data (d);
6366 classic (Data);
6467 Data >> v;
6568 }
6669
70+
6771 template <class Value > std::ostream& operator <<( std::ostream& s, const std::list<Value>& l )
6872 {
6973 s << " <" ;
@@ -77,12 +81,14 @@ namespace snapper
7781 return ( s );
7882 }
7983
84+
8085 template <class F , class S > std::ostream& operator <<( std::ostream& s, const std::pair<F,S>& p )
8186 {
8287 s << " [" << p.first << " :" << p.second << " ]" ;
8388 return ( s );
8489 }
8590
91+
8692 template <class Key , class Value > std::ostream& operator <<( std::ostream& s, const std::map<Key,Value>& m )
8793 {
8894 s << " <" ;
@@ -97,76 +103,6 @@ namespace snapper
97103 }
98104
99105
100- template <typename Type>
101- void logDiff (std::ostream& log, const char * text, const Type& lhs, const Type& rhs)
102- {
103- static_assert (!std::is_enum<Type>::value, " is enum" );
104-
105- if (lhs != rhs)
106- log << " " << text << " :" << lhs << " -->" << rhs;
107- }
108-
109- template <typename Type>
110- void logDiffHex (std::ostream& log, const char * text, const Type& lhs, const Type& rhs)
111- {
112- static_assert (std::is_integral<Type>::value, " not integral" );
113-
114- if (lhs != rhs)
115- log << " " << text << " :" << std::hex << lhs << " -->" << rhs << std::dec;
116- }
117-
118- template <typename Type>
119- void logDiffEnum (std::ostream& log, const char * text, const Type& lhs, const Type& rhs)
120- {
121- static_assert (std::is_enum<Type>::value, " not enum" );
122-
123- if (lhs != rhs)
124- log << " " << text << " :" << toString (lhs) << " -->" << toString (rhs);
125- }
126-
127- inline
128- void logDiff (std::ostream& log, const char * text, bool lhs, bool rhs)
129- {
130- if (lhs != rhs)
131- {
132- if (rhs)
133- log << " -->" << text;
134- else
135- log << " " << text << " -->" ;
136- }
137- }
138-
139-
140- template <class Type >
141- struct deref_less : public std ::binary_function<const Type*, const Type*, bool >
142- {
143- bool operator ()(const Type* x, const Type* y) const { return *x < *y; }
144- };
145-
146-
147- template <class Type >
148- struct deref_equal_to : public std ::binary_function<const Type*, const Type*, bool >
149- {
150- bool operator ()(const Type* x, const Type* y) const { return *x == *y; }
151- };
152-
153-
154- template <class Type >
155- void pointerIntoSortedList (list<Type*>& l, Type* e)
156- {
157- l.insert (lower_bound (l.begin (), l.end (), e, deref_less<Type>()), e);
158- }
159-
160-
161- template <class Type >
162- void clearPointerList (list<Type*>& l)
163- {
164- for (typename list<Type*>::iterator i = l.begin (); i != l.end (); ++i)
165- delete *i;
166- l.clear ();
167- }
168-
169-
170106 template <typename ListType, typename Type>
171107 bool contains (const ListType& l, const Type& value)
172108 {
@@ -181,27 +117,6 @@ namespace snapper
181117 }
182118
183119
184- template <typename Map, typename Key, typename Value>
185- typename Map::iterator mapInsertOrReplace (Map& m, const Key& k, const Value& v)
186- {
187- typename Map::iterator pos = m.lower_bound (k);
188- if (pos != m.end () && !typename Map::key_compare ()(k, pos->first ))
189- pos->second = v;
190- else
191- pos = m.insert (pos, typename Map::value_type (k, v));
192- return pos;
193- }
194-
195- template <typename List, typename Value>
196- typename List::const_iterator addIfNotThere (List& l, const Value& v)
197- {
198- typename List::const_iterator pos = find ( l.begin (), l.end (), v );
199- if (pos == l.end () )
200- pos = l.insert (l.end (), v);
201- return pos;
202- }
203-
204-
205120 template <class T , unsigned int sz>
206121 inline unsigned int lengthof (T (&)[sz]) { return sz; }
207122
0 commit comments