(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 krisbash 1.3 #include "linkage.h"
32 mike     1.1 
33              MI_BEGIN_NAMESPACE
34              
35              struct ArrayTraits
36              {
37                  /* The size in bytes of an array element. */
38                  size_t size;
39              
40                  /* Implements the placement copy construction operation for this type */
41                  void (*copy_ctor)(void* raw, const void* obj, MI_Uint32 numElements);
42              
43                  /* Implements the dtoror for this type */
44                  void (*dtor)(void* obj, MI_Uint32 numElements);
45              };
46              
47              template<class TYPE>
48              void __Construct(void* dest_, const void* src_, MI_Uint32 size)
49              {
50                  TYPE* dest = (TYPE*)dest_;
51                  const TYPE* src = (const TYPE*)src_;
52              
53 mike     1.1     while(size--)
54                      new(dest++) TYPE(*src++);
55              }
56              
57              template<class TYPE>
58              void __Destruct(void* data_, MI_Uint32 size)
59              {
60                  TYPE* data = (TYPE*)data_;
61              
62                  while (size--)
63                      (data++)->~TYPE();
64              }
65              
66              template<class TYPE>
67              inline const ArrayTraits* GetArrayTraits()
68              {
69                  static const ArrayTraits traits = 
70                  { 
71                      sizeof(TYPE), 
72                      __Construct<TYPE>, 
73                      __Destruct<TYPE> 
74 mike     1.1     };
75                  return &traits;
76              }
77              
78              MI_END_NAMESPACE
79              
80              #endif /* _micxx_arraytraits_h */

ViewCVS 0.9.2