HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_AttributeMap.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: GT_AttributeMap.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_AttributeMap__
12 #define __GT_AttributeMap__
13 
14 #include "GT_API.h"
15 #include "GT_Handles.h"
16 #include "GT_Types.h"
17 
18 #include <UT/UT_ArrayStringMap.h>
19 #include <UT/UT_IntrusivePtr.h>
20 #include <UT/UT_StringArray.h>
21 #include <UT/UT_StringHolder.h>
22 
23 class UT_WorkBuffer;
24 
25 /// @brief Used to filter out entries when constructing an attribute map.
27 {
28 public:
30  virtual ~GT_AttributeMapFilter();
31  /// Override this method when creating a sub-set of a attribute map
32  /// @param name @n The name of the attribute
33  /// @param index @n The attributes index in the current map
34  virtual bool accept(const UT_StringHolder &name, int index) const = 0;
35 };
36 
37 /// @brief A symbol table for attribute data
38 ///
39 /// Attribute data is stored in two structures. The GT_AttributeMap keeps a
40 /// mapping of names to integer values. The integer values are the offsets
41 /// into the GT_AttributeList, which stores the actual data.
43  : public UT_IntrusiveRefCounter<GT_AttributeMap>
44 {
45 public:
50 
51  /// Default constructor
52  explicit GT_AttributeMap(int capacity = 0);
53  /// Copy constructor
55  /// Destructor
56  ~GT_AttributeMap();
57 
58  /// Create a new attribute map by filtering the entries. Each entry in the
59  /// @c src is filtered by the @c filter and if accepted, added to the new
60  /// map.
61  static const GT_AttributeMapHandle filter(
64 
65  /// Compare two maps
66  bool operator==(const GT_AttributeMap &map) const;
67  bool operator!=(const GT_AttributeMap &map) const
68  { return !(*this == map); }
69 
70  /// Clear the map
71  void clear();
72 
73  /// How many symbols are there
74  int entries() const { return myNames.entries(); }
75 
76  /// Return approximate memory used by map
77  int64 getMemoryUsage(bool inclusive) const;
78 
79  /// Find the symbol index (or -1 if no symbol exists)
80  int get(const UT_StringRef &name) const
81  {
82  auto item = myNamesMap.find(name);
83  return (item != myNamesMap.end()) ? item->second : -1;
84  }
85 
86  /// Test if a name exists
87  bool hasName(const UT_StringRef &name) const
88  { return myNamesMap.contains(name); }
89 
90  /// Find the name for the given index
91  const UT_StringHolder &getName(int index) const
92  { return myNames(index); }
93 
94  /// Get a label which includes the export name and other properties
95  /// This returns the string stored in the @c label_storage
96  const char *getLabel(int index, UT_WorkBuffer &label_storage) const;
97 
98  /// @{
99  /// Add export mapping (from parameter name to export name)
100  void addExportName(int idx, const UT_StringHolder &export_name)
101  { addExportName(getName(idx), export_name); }
102  void addExportName(const UT_StringHolder &name,
103  const UT_StringHolder &export_name);
104  /// @}
105  /// Get the exported name for a parameter
106  const UT_StringHolder &getExportName(int index) const;
107 
108  /// Since GT can move attribute storage classes around, especially compared
109  /// with GEO, it's sometimes useful to know what the original attribute
110  /// owner was. This is not always guaranteed to be set to something other
111  /// that GT_OWNER_INVALID, but it will likely be set if the attribute
112  /// originates from a GA_Attribute.
113  GT_Owner getOriginalOwner(int idx) const { return myOwners(idx); }
114 
115  /// Set the original owner
116  void setOriginalOwner(int i, GT_Owner o) { myOwners(i) = o; }
117 
118  /// Get the symbol names
119  const UT_StringArray &getNames() const { return myNames; }
120 
121  /// Add a new symbol to the index. If this is a duplicate symbol, setting
122  /// @c replace_existing will return the previous index. Otherwise, -1 will
123  /// be returned.
124  int add(const UT_StringHolder &name, bool replace_existing);
125 
126  /// Access to a symbol table traverser.
127  const_names_iterator begin() const { return myNamesMap.begin(); }
128 
129 private:
130  // Remove a symbol, returning the index that was removed, or -1.
131  // @warning If the map is referenced by an attribute lists, this will
132  // cause the arrays in the attribute list to be mis-matched.
133  int remove(const UT_StringRef &name);
134  friend class GT_AttributeList; // Access to remove()
135 
136  ExportMapType myExportMap;
137  UT_StringArray myNames;
138  NamesMapType myNamesMap;
139  UT_Array<GT_Owner> myOwners;
140 };
141 
142 #endif
143 
const_names_iterator begin() const
Access to a symbol table traverser.
GT_Owner getOriginalOwner(int idx) const
A symbol table for attribute data.
#define GT_API
Definition: GT_API.h:13
UT_ArrayStringMap< int > NamesMapType
A reference counter base class for use with UT_IntrusivePtr.
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
const UT_StringArray & getNames() const
Get the symbol names.
void addExportName(int idx, const UT_StringHolder &export_name)
long long int64
Definition: SYS_Types.h:116
NamesMapType::const_iterator const_names_iterator
GLuint const GLchar * name
Definition: glcorearb.h:786
Used to filter out entries when constructing an attribute map.
void setOriginalOwner(int i, GT_Owner o)
Set the original owner.
GT_Owner
Definition: GT_Types.h:90
const UT_StringHolder & getName(int index) const
Find the name for the given index.
int entries() const
How many symbols are there.
GLuint index
Definition: glcorearb.h:786
ImageBuf OIIO_API add(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
ExportMapType::const_iterator const_export_iterator
bool hasName(const UT_StringRef &name) const
Test if a name exists.
bool operator!=(const GT_AttributeMap &map) const
UT_ArrayStringMap< UT_StringHolder > ExportMapType
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297
GLenum src
Definition: glcorearb.h:1793