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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2