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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2