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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2