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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2