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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2