1 karl 1.18 //%2005////////////////////////////////////////////////////////////////////////
|
2 mike 1.8 //
|
3 karl 1.17 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.16 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.17 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.18 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 mike 1.8 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
13 kumpf 1.14 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
16 mike 1.8 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
18 //
|
19 kumpf 1.14 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
20 mike 1.8 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
22 kumpf 1.14 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
25 mike 1.8 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Mike Brasher (mbrasher@bmc.com)
31 //
32 // Modified By:
33 //
34 //%/////////////////////////////////////////////////////////////////////////////
35
36 ////////////////////////////////////////////////////////////////////////////////
37 //
38 // Memory.h
39 //
|
40 kumpf 1.13 // This file contains assorted memory-oriented routines:
|
41 mike 1.8 //
|
42 kumpf 1.13 // Zeros(): fills memory with zeros.
43 // Destroy(): destructs multiple objects in contiguous memory.
44 // CopyToRaw(): copies multiple objects to raw memory.
45 // InitializeRaw(): default constructs mulitple object over raw memory.
|
46 mike 1.8 //
|
47 kumpf 1.13 // Each of these is a template but specializations are provide for
48 // efficiency (which in some cases removes uncessary loops).
|
49 mike 1.8 //
50 ////////////////////////////////////////////////////////////////////////////////
51
52 #ifndef Pegasus_Memory_h
53 #define Pegasus_Memory_h
54
|
55 keith.petley 1.15 #include <string>
|
56 mike 1.8 #include <Pegasus/Common/Config.h>
57 #include <Pegasus/Common/CIMType.h>
58 #include <Pegasus/Common/Char16.h>
59
60 PEGASUS_NAMESPACE_BEGIN
61
62 template<class T>
63 inline void Zeros(T* items, Uint32 size)
64 {
65 memset(items, 0, sizeof(T) * size);
66 }
67
68 template<class T>
69 inline void Destroy(T* items, Uint32 size)
70 {
71 while (size--)
|
72 kumpf 1.13 items++->~T();
|
73 mike 1.8 }
74
|
75 kumpf 1.13 template<class T>
76 inline void CopyToRaw(T* to, const T* from, Uint32 size)
|
77 mike 1.8 {
78 while (size--)
|
79 mike 1.9 {
|
80 kumpf 1.13 // The following fails on TRU64:
81 // new(to++) T(*from++);
82 // Probably a compiler error so I changed it to this:
83 // Mike Brasher
84
85 new(to) T(*from);
86 to++;
87 from++;
|
88 mike 1.9 }
|
89 mike 1.8 }
90
91 inline void CopyToRaw(Boolean* to, const Boolean* from, Uint32 size)
92 {
93 memcpy(to, from, sizeof(Boolean) * size);
94 }
95
96 inline void CopyToRaw(Uint8* to, const Uint8* from, Uint32 size)
97 {
98 memcpy(to, from, sizeof(Uint8) * size);
99 }
100
101 inline void CopyToRaw(Sint8* to, const Sint8* from, Uint32 size)
102 {
103 memcpy(to, from, sizeof(Sint8) * size);
104 }
105
106 inline void CopyToRaw(Uint16* to, const Uint16* from, Uint32 size)
107 {
108 memcpy(to, from, sizeof(Uint16) * size);
109 }
110 mike 1.8
111 inline void CopyToRaw(Sint16* to, const Sint16* from, Uint32 size)
112 {
113 memcpy(to, from, sizeof(Sint16) * size);
114 }
115
116 inline void CopyToRaw(Uint32* to, const Uint32* from, Uint32 size)
117 {
118 memcpy(to, from, sizeof(Uint32) * size);
119 }
120
121 inline void CopyToRaw(Sint32* to, const Sint32* from, Uint32 size)
122 {
123 memcpy(to, from, sizeof(Sint32) * size);
124 }
125
126 inline void CopyToRaw(Uint64* to, const Uint64* from, Uint32 size)
127 {
128 memcpy(to, from, sizeof(Uint64) * size);
129 }
130
131 mike 1.8 inline void CopyToRaw(Sint64* to, const Sint64* from, Uint32 size)
132 {
133 memcpy(to, from, sizeof(Sint64) * size);
134 }
135
136 inline void CopyToRaw(Real32* to, const Real32* from, Uint32 size)
137 {
138 memcpy(to, from, sizeof(Real32) * size);
139 }
140
141 inline void CopyToRaw(Real64* to, const Real64* from, Uint32 size)
142 {
143 memcpy(to, from, sizeof(Real64) * size);
144 }
145
146 inline void CopyToRaw(Char16* to, const Char16* from, Uint32 size)
147 {
148 memcpy(to, from, sizeof(Char16) * size);
149 }
150
151 template<class T>
152 mike 1.8 inline void InitializeRaw(T* items, Uint32 size)
153 {
154 while (size--)
|
155 kumpf 1.11 {
|
156 kumpf 1.13 new(items) T();
157 items++;
|
158 kumpf 1.11 }
|
159 mike 1.8 }
160
161 #define PEGASUS_MEMORY_FUNCTIONS(T) \
162 inline void Destroy(T*, Uint32) { } \
163 inline void InitializeRaw(T* items, Uint32 size) { Zeros(items, size); }
164
165 PEGASUS_MEMORY_FUNCTIONS(char*)
166 PEGASUS_MEMORY_FUNCTIONS(const char*)
167 PEGASUS_MEMORY_FUNCTIONS(Boolean)
168 PEGASUS_MEMORY_FUNCTIONS(Uint8)
169 PEGASUS_MEMORY_FUNCTIONS(Sint8)
170 PEGASUS_MEMORY_FUNCTIONS(Uint16)
171 PEGASUS_MEMORY_FUNCTIONS(Sint16)
172 PEGASUS_MEMORY_FUNCTIONS(Uint32)
173 PEGASUS_MEMORY_FUNCTIONS(Sint32)
174 PEGASUS_MEMORY_FUNCTIONS(Uint64)
175 PEGASUS_MEMORY_FUNCTIONS(Sint64)
176 PEGASUS_MEMORY_FUNCTIONS(Real32)
177 PEGASUS_MEMORY_FUNCTIONS(Real64)
178 PEGASUS_MEMORY_FUNCTIONS(Char16)
179
180 mike 1.8 PEGASUS_NAMESPACE_END
181
182 #endif /* Pegasus_Memory_h */
|