HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_LabeledCapacity.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_LabeledCapacity.h (UT Library, C++)
7  *
8  * COMMENTS:
9  * UT_LabeledCapacity has utilities to efficiently store the capacity of
10  * a data buffer along with a label that indicates whether the capacity is
11  * owned or external.
12  *
13  * This code is used in the implementation of UT_Array.h.
14  * It has been put in its own header to prevent the
15  * UT_Array.h header from getting too cluttered.
16  */
17 
18 #ifndef __UT_LABELED_CAPACITY_H_INCLUDED__
19 #define __UT_LABELED_CAPACITY_H_INCLUDED__
20 
21 #include <type_traits>
22 
23 using UT_LabeledCapacityRep = std::make_unsigned_t< exint >;
24 
27 
29 {
30 public:
31 
32 private:
34 
35  constexpr explicit UT_LabeledCapacity( const UT_LabeledCapacityRep rep ) noexcept :
36  myRep( rep )
37  {
38  }
39 
40  friend constexpr UT_LabeledCapacity ownedLabeledCapacity( const exint capacity ) noexcept;
41  friend constexpr UT_LabeledCapacity externalLabeledCapacity( const exint capacity ) noexcept;
42  friend constexpr exint capacityValue( const UT_LabeledCapacity& a ) noexcept;
43 };
44 
45 constexpr UT_LabeledCapacity ownedLabeledCapacity( const exint capacity ) noexcept
46 {
47  UT_ASSERT_P( capacity >= 0 );
48  UT_ASSERT_P( ( capacity & LABELED_CAPACITY_MASK_VALUE ) == capacity );
49 
50  // Don't set the external bit:
51  return UT_LabeledCapacity( capacity );
52 }
53 
54 constexpr UT_LabeledCapacity externalLabeledCapacity( const exint capacity ) noexcept
55 {
56  UT_ASSERT_P( capacity >= 0 );
57  UT_ASSERT_P( ( capacity & LABELED_CAPACITY_MASK_VALUE ) == capacity );
58 
59  // Set the external bit:
61 };
62 
63 constexpr exint capacityValue( const UT_LabeledCapacity& a ) noexcept
64 {
65  return a.myRep & LABELED_CAPACITY_MASK_VALUE;
66 }
67 
68 #endif
std::make_unsigned_t< exint > UT_LabeledCapacityRep
int64 exint
Definition: SYS_Types.h:125
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
constexpr UT_LabeledCapacityRep LABELED_CAPACITY_MASK_VALUE
friend constexpr exint capacityValue(const UT_LabeledCapacity &a) noexcept
constexpr UT_LabeledCapacityRep LABELED_CAPACITY_FLAG_EXTERNAL
constexpr UT_LabeledCapacity ownedLabeledCapacity(const exint capacity) noexcept
constexpr UT_LabeledCapacity externalLabeledCapacity(const exint capacity) noexcept
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
friend constexpr UT_LabeledCapacity externalLabeledCapacity(const exint capacity) noexcept
constexpr exint capacityValue(const UT_LabeledCapacity &a) noexcept
friend constexpr UT_LabeledCapacity ownedLabeledCapacity(const exint capacity) noexcept