HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_AttribValueLookupTable.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: GU_AttribValueLookupTable.h (GU Library, C++)
7  *
8  * COMMENTS: File accompanying GU_Detail.h, so that it doesn't need to include UT_StringMap.h or UT_Map.h
9  *
10  */
11 
12 #pragma once
13 
14 #ifndef __GU_AttribValueLookupTable_h__
15 #define __GU_AttribValueLookupTable_h__
16 
17 #include "GU_Detail.h"
18 
19 #include <UT/UT_IntArray.h>
20 #include <UT/UT_Map.h>
21 #include <UT/UT_StringArray.h>
22 #include <UT/UT_StringMap.h>
23 
25 {
26 public:
27  AttribValueLookupTable(const GA_Attribute *attrib);
28 
30 
31  exint entries() const { return SYSmax(myIntTable.size(), myStringTable.size()); }
32 
33  exint getIntValue(exint idx) const
34  {
35  if (idx < 0 || idx >= myIntValues.size())
36  return -1;
37  return myIntValues(idx);
38  }
40  {
41  if (idx < 0 || idx >= myStringValues.size())
43  return myStringValues(idx);
44  }
46  {
47  auto it = myIntTable.find(v);
48  if (it == myIntTable.end())
49  return nullptr;
50  return it->second;
51  }
53  {
54  auto it = myStringTable.find(v);
55  if (it == myStringTable.end())
56  return nullptr;
57  return it->second;
58  }
59 
60  int64 getMemoryUsage(bool inclusive) const
61  {
62  int64 mem = inclusive ? sizeof(*this) : 0;
63 
64  mem += myStringValues.getMemoryUsage(false);
65  mem += myIntValues.getMemoryUsage(false);
66 
67  mem += myStringTable.getMemoryUsage(false);
68  for (auto it = myStringTable.begin(); it != myStringTable.end(); ++it)
69  mem += it->second->getMemoryUsage(true);
70 
71  mem += UTgetMemoryUsage(myIntTable, false);
72  for (auto it = myIntTable.begin(); it != myIntTable.end(); ++it)
73  mem += it->second->getMemoryUsage(true);
74 
75  return mem;
76  }
77 
78 private:
79 
80  UT_StringMap<GA_OffsetList *> myStringTable;
82  UT_StringArray myStringValues;
83  UT_ExintArray myIntValues;
84 };
85 
87 {
88 public:
90 
92 
93  exint entries() const { return SYSmax(myIntTable.size(), myStringTable.size()); }
94 
96  {
97  auto it = myIntTable.find(v);
98  if (it == myIntTable.end())
99  return GA_INVALID_OFFSET;
100  return it->second;
101  }
102 
104  {
105  auto it = myStringTable.find(v);
106  if (it == myStringTable.end())
107  return GA_INVALID_OFFSET;
108  return it->second;
109  }
110 
111  int64 getMemoryUsage(bool inclusive) const
112  {
113  int64 mem = inclusive ? sizeof(*this) : 0;
114 
115  mem += myStringTable.getMemoryUsage(false);
116  mem += UTgetMemoryUsage(myIntTable, false);
117 
118  return mem;
119  }
120 
121 private:
122  UT_StringMap<GA_Offset> myStringTable;
123  UT_Map<exint, GA_Offset> myIntTable;
124 };
125 
126 #endif
const GA_OffsetList * getStringOffsets(const UT_StringRef &v) const
#define SYSmax(a, b)
Definition: SYS_Math.h:1538
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
Unsorted map container.
Definition: UT_Map.h:107
const GLdouble * v
Definition: glcorearb.h:837
int64 getMemoryUsage(bool inclusive) const
Definition: UT_Map.h:151
int64 exint
Definition: SYS_Types.h:125
int64 getMemoryUsage(bool inclusive=false) const
Definition: UT_Array.h:657
GA_Offset getStringOffset(const UT_StringRef &v) const
AttribSingleValueLookupTable(const GA_Attribute *attrib)
exint size() const
Definition: UT_Array.h:646
#define GA_INVALID_OFFSET
Definition: GA_Types.h:678
AttribValueLookupTable(const GA_Attribute *attrib)
GA_Size GA_Offset
Definition: GA_Types.h:641
static const UT_StringHolder theEmptyString
long long int64
Definition: SYS_Types.h:116
const UT_StringHolder & getStringHolder(exint idx) const
int64 UTgetMemoryUsage(const UT_ConcurrentHashMap< K, V, H, A > &map, const bool inclusive)
int64 getMemoryUsage(bool inclusive) const
const GA_OffsetList * getIntOffsets(exint v) const