HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_AttributeEvaluatorCache.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  * COMMENTS:
7  */
8 
9 #ifndef __PDG_ATTRIBUTE_EVAL_CACHE_H__
10 #define __PDG_ATTRIBUTE_EVAL_CACHE_H__
11 
12 #include "PDG_API.h"
13 #include "PDG_AttributeTypes.h"
14 #include "PDG_WorkItemTypes.h"
15 
16 #include <UT/UT_Array.h>
17 #include <UT/UT_ArrayMap.h>
18 #include <UT/UT_WorkBuffer.h>
19 
21 class PDG_WorkItem;
22 
23 /**
24  * Evaluates attributes from a list of work items using an attribute evaluator,
25  * and caches the evaluation results. This is useful when e.g. sorting by
26  * attribute which may need to make multiple look-ups of the same attribute
27  * value during the sorting process
28  */
30 {
31 public:
32  /// Helper struct that contains the actual cached evaluation data
33  struct CacheEntry
34  {
35  /// The cast result
37 
38  /// The string value, if the attribute is castable to a string
40 
41  /// The float value, if the attribute is castable to a number
43 
44  /// Whether or not the entry has a float value
45  bool myHasFloat;
46  };
47 
48 public:
49  /// Constructs a cache from an evaluator and a list of work items
51  const PDG_AttributeEvaluator* evaluator,
52  const PDG_WorkItemArray& work_items);
53 
55  const PDG_AttributeEvaluator* evaluator,
56  const PDG_WorkItemConstArray& work_items);
57 
58  /// Returns the cache value for the specified work item
59  inline const CacheEntry& cacheEntry(const PDG_WorkItem* work_item) const
60  {
61  auto&& iter = myCacheMap.find(
62  work_item);
63  if (iter == myCacheMap.end())
64  return theDefaultCacheEntry;
65 
66  return myCacheEntries[iter->second];
67  }
68 
69 private:
70  static CacheEntry theDefaultCacheEntry;
71 
72  UT_Array<CacheEntry> myCacheEntries;
74  myCacheMap;
75 };
76 
77 #endif
#define PDG_API
Definition: PDG_API.h:23
const CacheEntry & cacheEntry(const PDG_WorkItem *work_item) const
Returns the cache value for the specified work item.
fpreal myFloat
The float value, if the attribute is castable to a number.
UT_WorkBuffer myString
The string value, if the attribute is castable to a string.
PDG_AttributeCast
Enumeration of attribute cast results.
PDG_AttributeCast myCast
The cast result.
Helper struct that contains the actual cached evaluation data.
fpreal64 fpreal
Definition: SYS_Types.h:278
bool myHasFloat
Whether or not the entry has a float value.