#ifndef SNAPPER_SNAPPER_TMPL_H
#define SNAPPER_SNAPPER_TMPL_H
-#include <functional>
+
#include <ostream>
#include <fstream>
#include <sstream>
#include "snapper/AppUtil.h"
+
namespace snapper
{
using std::string;
return num_str.str();
}
+
template<class Num> string hexString(Num number)
{
static_assert(std::is_integral<Num>::value, "not integral");
return num_str.str();
}
+
template<class Value> void operator>>(const string& d, Value& v)
{
std::istringstream Data(d);
Data >> v;
}
+
template<class Value> std::ostream& operator<<( std::ostream& s, const std::list<Value>& l )
{
s << "<";
return( s );
}
+
template<class F, class S> std::ostream& operator<<( std::ostream& s, const std::pair<F,S>& p )
{
s << "[" << p.first << ":" << p.second << "]";
return( s );
}
+
template<class Key, class Value> std::ostream& operator<<( std::ostream& s, const std::map<Key,Value>& m )
{
s << "<";
}
- template <typename Type>
- void logDiff(std::ostream& log, const char* text, const Type& lhs, const Type& rhs)
- {
- static_assert(!std::is_enum<Type>::value, "is enum");
-
- if (lhs != rhs)
- log << " " << text << ":" << lhs << "-->" << rhs;
- }
-
- template <typename Type>
- void logDiffHex(std::ostream& log, const char* text, const Type& lhs, const Type& rhs)
- {
- static_assert(std::is_integral<Type>::value, "not integral");
-
- if (lhs != rhs)
- log << " " << text << ":" << std::hex << lhs << "-->" << rhs << std::dec;
- }
-
- template <typename Type>
- void logDiffEnum(std::ostream& log, const char* text, const Type& lhs, const Type& rhs)
- {
- static_assert(std::is_enum<Type>::value, "not enum");
-
- if (lhs != rhs)
- log << " " << text << ":" << toString(lhs) << "-->" << toString(rhs);
- }
-
- inline
- void logDiff(std::ostream& log, const char* text, bool lhs, bool rhs)
- {
- if (lhs != rhs)
- {
- if (rhs)
- log << " -->" << text;
- else
- log << " " << text << "-->";
- }
- }
-
-
- template<class Type>
- struct deref_less : public std::binary_function<const Type*, const Type*, bool>
- {
- bool operator()(const Type* x, const Type* y) const { return *x < *y; }
- };
-
-
- template<class Type>
- struct deref_equal_to : public std::binary_function<const Type*, const Type*, bool>
- {
- bool operator()(const Type* x, const Type* y) const { return *x == *y; }
- };
-
-
- template <class Type>
- void pointerIntoSortedList(list<Type*>& l, Type* e)
- {
- l.insert(lower_bound(l.begin(), l.end(), e, deref_less<Type>()), e);
- }
-
-
- template <class Type>
- void clearPointerList(list<Type*>& l)
- {
- for (typename list<Type*>::iterator i = l.begin(); i != l.end(); ++i)
- delete *i;
- l.clear();
- }
-
-
template <typename ListType, typename Type>
bool contains(const ListType& l, const Type& value)
{
}
- template<typename Map, typename Key, typename Value>
- typename Map::iterator mapInsertOrReplace(Map& m, const Key& k, const Value& v)
- {
- typename Map::iterator pos = m.lower_bound(k);
- if (pos != m.end() && !typename Map::key_compare()(k, pos->first))
- pos->second = v;
- else
- pos = m.insert(pos, typename Map::value_type(k, v));
- return pos;
- }
-
- template<typename List, typename Value>
- typename List::const_iterator addIfNotThere(List& l, const Value& v)
- {
- typename List::const_iterator pos = find( l.begin(), l.end(), v );
- if (pos == l.end() )
- pos = l.insert(l.end(), v);
- return pos;
- }
-
-
template <class T, unsigned int sz>
inline unsigned int lengthof(T (&)[sz]) { return sz; }