summaryrefslogtreecommitdiffhomepage
path: root/SixenseSDK/include/sixense_utils/sixense_utils_string.hpp
blob: 31ee7c617d7dc1025cc656840fbf6435cd696c01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 *
 * SIXENSE CONFIDENTIAL
 *
 * Copyright (C) 2011 Sixense Entertainment Inc.
 * All Rights Reserved
 *
 */

#ifndef SIXENSE_UTILS_STRING_HPP
#define SIXENSE_UTILS_STRING_HPP

SIXENSE_UTILS_EXPORT void* sixense_utils_alloc(size_t);
SIXENSE_UTILS_EXPORT void sixense_utils_free(void*); 

#include <string>
#include <cstddef>

template<class MY_TYPE>
class sixense_utils_allocator
{
public:
	typedef size_t              size_type;
	typedef ptrdiff_t   difference_type;
	typedef MY_TYPE*    pointer;
	typedef const MY_TYPE*      const_pointer;
	typedef MY_TYPE&    reference;
	typedef const MY_TYPE&      const_reference;
	typedef MY_TYPE             value_type;

	sixense_utils_allocator () {}
	template <class U> sixense_utils_allocator(const sixense_utils_allocator<U>&) {}
	template <class U> struct rebind { typedef sixense_utils_allocator<U> other; };

	pointer allocate(size_type n, std::allocator<void>::const_pointer hint = 0)
	{
		return reinterpret_cast<pointer>(sixense_utils_alloc(n * sizeof(MY_TYPE)));
	}
	void construct(pointer p, const_reference val)
	{
		::new(p) MY_TYPE(val);
	}
	void destroy(pointer p)
	{
		p->~MY_TYPE();
	}
	void deallocate(pointer p, size_type n)
	{
		sixense_utils_free(p);
	}
	size_type max_size() const throw()
	{
		return ~size_type(0);
	}
};

template<class MY_TYPE>
bool operator==(const sixense_utils_allocator<MY_TYPE>& left, const sixense_utils_allocator<MY_TYPE>& right) throw()
{
	return true;
}

template<class MY_TYPE>
bool operator!=(const sixense_utils_allocator<MY_TYPE>& left, const sixense_utils_allocator<MY_TYPE>& right) throw()
{
	return false;
}

namespace sixenseUtils {

	typedef std::basic_string< char, std::char_traits<char>, sixense_utils_allocator<char> > sixense_utils_string;

}


#endif