author | peter1138 |
Sun, 03 Aug 2008 17:35:08 +0000 | |
changeset 9834 | 7474149531c1 |
parent 9575 | 58d55b1a70c9 |
permissions | -rw-r--r-- |
9520
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
1 |
/* $Id$ */ |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
2 |
|
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
3 |
/** @file mem_func.hpp Functions related to memory operations. */ |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
4 |
|
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
5 |
#ifndef MEM_FUNC_HPP |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
6 |
#define MEM_FUNC_HPP |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
7 |
|
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
8 |
#include <string.h> |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
9 |
#include "math_func.hpp" |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
10 |
|
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
11 |
/** |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
12 |
* Type-safe version of memcpy(). |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
13 |
* |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
14 |
* @param destination Pointer to the destination buffer |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
15 |
* @param source Pointer to the source buffer |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
16 |
* @param num number of items to be copied. (!not number of bytes!) |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
17 |
*/ |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
18 |
template <typename T> |
9575
58d55b1a70c9
(svn r13606) -Codechange: use "static FORCEINLINE" where possible as default for core functions (big functions use just inline instead)
skidd13
parents:
9521
diff
changeset
|
19 |
static FORCEINLINE void MemCpyT(T *destination, const T *source, uint num = 1) |
9520
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
20 |
{ |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
21 |
memcpy(destination, source, num * sizeof(T)); |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
22 |
} |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
23 |
|
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
24 |
/** |
9521
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
25 |
* Type-safe version of memmove(). |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
26 |
* |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
27 |
* @param destination Pointer to the destination buffer |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
28 |
* @param source Pointer to the source buffer |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
29 |
* @param num number of items to be copied. (!not number of bytes!) |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
30 |
*/ |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
31 |
template <typename T> |
9575
58d55b1a70c9
(svn r13606) -Codechange: use "static FORCEINLINE" where possible as default for core functions (big functions use just inline instead)
skidd13
parents:
9521
diff
changeset
|
32 |
static FORCEINLINE void MemMoveT(T *destination, const T *source, uint num = 1) |
9521
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
33 |
{ |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
34 |
memmove(destination, source, num * sizeof(T)); |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
35 |
} |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
36 |
|
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
37 |
/** |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
38 |
* Type-safe version of memset(). |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
39 |
* |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
40 |
* @param ptr Pointer to the destination buffer |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
41 |
* @param value Value to be set |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
42 |
* @param num number of items to be set (!not number of bytes!) |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
43 |
*/ |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
44 |
template <typename T> |
9575
58d55b1a70c9
(svn r13606) -Codechange: use "static FORCEINLINE" where possible as default for core functions (big functions use just inline instead)
skidd13
parents:
9521
diff
changeset
|
45 |
static FORCEINLINE void MemSetT(T *ptr, int value, uint num = 1) |
9521
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
46 |
{ |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
47 |
memset(ptr, value, num * sizeof(T)); |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
48 |
} |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
49 |
|
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
50 |
/** |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
51 |
* Type-safe version of memcmp(). |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
52 |
* |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
53 |
* @param ptr1 Pointer to the first buffer |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
54 |
* @param ptr2 Pointer to the second buffer |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
55 |
* @param num Number of items to compare. (!not number of bytes!) |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
56 |
* @return an int value indicating the relationship between the content of the two buffers |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
57 |
*/ |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
58 |
template <typename T> |
9575
58d55b1a70c9
(svn r13606) -Codechange: use "static FORCEINLINE" where possible as default for core functions (big functions use just inline instead)
skidd13
parents:
9521
diff
changeset
|
59 |
static FORCEINLINE int MemCmpT(const T *ptr1, const T *ptr2, uint num = 1) |
9521
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
60 |
{ |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
61 |
return memcmp(ptr1, ptr2, num * sizeof(T)); |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
62 |
} |
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
63 |
|
5d01c4545f24
(svn r13517) -Add: remaining used typesafe versions of the mem* functions from <string.h>
skidd13
parents:
9520
diff
changeset
|
64 |
/** |
9520
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
65 |
* Type safe memory reverse operation. |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
66 |
* Reverse a block of memory in steps given by the |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
67 |
* type of the pointers. |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
68 |
* |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
69 |
* @param ptr1 Start-pointer to the block of memory. |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
70 |
* @param ptr2 End-pointer to the block of memory. |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
71 |
*/ |
9575
58d55b1a70c9
(svn r13606) -Codechange: use "static FORCEINLINE" where possible as default for core functions (big functions use just inline instead)
skidd13
parents:
9521
diff
changeset
|
72 |
template <typename T> |
58d55b1a70c9
(svn r13606) -Codechange: use "static FORCEINLINE" where possible as default for core functions (big functions use just inline instead)
skidd13
parents:
9521
diff
changeset
|
73 |
static FORCEINLINE void MemReverseT(T *ptr1, T *ptr2) |
9520
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
74 |
{ |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
75 |
assert(ptr1 != NULL && ptr2 != NULL); |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
76 |
assert(ptr1 < ptr2); |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
77 |
|
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
78 |
do { |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
79 |
Swap(*ptr1, *ptr2); |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
80 |
} while (++ptr1 < --ptr2); |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
81 |
} |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
82 |
|
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
83 |
/** |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
84 |
* Type safe memory reverse operation (overloaded) |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
85 |
* |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
86 |
* @param ptr Pointer to the block of memory. |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
87 |
* @param num The number of items we want to reverse. |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
88 |
*/ |
9575
58d55b1a70c9
(svn r13606) -Codechange: use "static FORCEINLINE" where possible as default for core functions (big functions use just inline instead)
skidd13
parents:
9521
diff
changeset
|
89 |
template <typename T> |
58d55b1a70c9
(svn r13606) -Codechange: use "static FORCEINLINE" where possible as default for core functions (big functions use just inline instead)
skidd13
parents:
9521
diff
changeset
|
90 |
static FORCEINLINE void MemReverseT(T *ptr, uint num) |
9520
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
91 |
{ |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
92 |
assert(ptr != NULL); |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
93 |
|
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
94 |
MemReverseT(ptr, ptr + (num - 1)); |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
95 |
} |
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
96 |
|
f08d9fc662a6
(svn r13516) -Codechange: Move MemCpyT to a fitting core header
skidd13
parents:
diff
changeset
|
97 |
#endif /* MEM_FUNC_HPP */ |