(file) Return to arraytraits.h CVS log (file) (dir) Up to [OMI] / omi / micxx

 1 mike  1.1 /*
 2           **==============================================================================
 3           **
 4           ** Open Management Infrastructure (OMI)
 5           **
 6           ** Copyright (c) Microsoft Corporation
 7           ** 
 8           ** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
 9           ** use this file except in compliance with the License. You may obtain a copy 
10           ** of the License at 
11           **
12           **     http://www.apache.org/licenses/LICENSE-2.0 
13           **
14           ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15           ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
16           ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
17           ** MERCHANTABLITY OR NON-INFRINGEMENT. 
18           **
19           ** See the Apache 2 License for the specific language governing permissions 
20           ** and limitations under the License.
21           **
22 mike  1.1 **==============================================================================
23           */
24           
25           #ifndef _micxx_arraytraits_h
26           #define _micxx_arraytraits_h
27           
28           #include <new>
29           #include "atomic.h"
30           #include "memory.h"
31           
32           MI_BEGIN_NAMESPACE
33           
34           struct ArrayTraits
35           {
36               /* The size in bytes of an array element. */
37               size_t size;
38           
39               /* Implements the placement copy construction operation for this type */
40               void (*copy_ctor)(void* raw, const void* obj, MI_Uint32 numElements);
41           
42               /* Implements the dtoror for this type */
43 mike  1.1     void (*dtor)(void* obj, MI_Uint32 numElements);
44           };
45           
46           template<class TYPE>
47           void __Construct(void* dest_, const void* src_, MI_Uint32 size)
48           {
49               TYPE* dest = (TYPE*)dest_;
50               const TYPE* src = (const TYPE*)src_;
51           
52               while(size--)
53                   new(dest++) TYPE(*src++);
54           }
55           
56           template<class TYPE>
57           void __Destruct(void* data_, MI_Uint32 size)
58           {
59               TYPE* data = (TYPE*)data_;
60           
61               while (size--)
62                   (data++)->~TYPE();
63           }
64 mike  1.1 
65           template<class TYPE>
66           inline const ArrayTraits* GetArrayTraits()
67           {
68               static const ArrayTraits traits = 
69               { 
70                   sizeof(TYPE), 
71                   __Construct<TYPE>, 
72                   __Destruct<TYPE> 
73               };
74               return &traits;
75           }
76           
77           MI_END_NAMESPACE
78           
79           #endif /* _micxx_arraytraits_h */

ViewCVS 0.9.2