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