(file) Return to Memory.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2