]> git.tdb.fi Git - libs/gl.git/blob - source/tag.cpp
Make Tag directly comparable and use it as a key in relevant maps
[libs/gl.git] / source / tag.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007, 2010  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "tag.h"
9
10 namespace {
11
12 template<typename T>
13 inline unsigned hash(T begin, T end)
14 {
15         unsigned result=0;
16         for(T i=begin; (i!=end && *i); ++i)
17                 result=((result>>29)|(result<<5))^static_cast<unsigned char>(*i);
18         return result;
19 }
20
21 }
22
23 namespace Msp {
24 namespace GL {
25
26 Tag::Tag(const char *s):
27         id(s ? hash<const char *>(s, 0) : 0)
28 { }
29
30 Tag::Tag(const std::string &s):
31         id(hash(s.begin(), s.end()))
32 { }
33
34 } // namespace GL
35 } // namespace Msp