HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_PackedNameMap.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: GEO_PackedNameMap.h (GEO Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GEO_PackedNameMap__
12 #define __GEO_PackedNameMap__
13 
14 #include "GEO_API.h"
15 #include "GEO_PackedTypes.h"
16 #include <UT/UT_IntrusivePtr.h>
17 #include <UT/UT_SymbolTable.h>
18 #include <UT/UT_StringMMPattern.h>
19 #include <GA/GA_Types.h>
20 #include <GA/GA_SharedLoadData.h>
21 
22 class UT_JSONWriter;
23 class UT_JSONParser;
24 class UT_MemoryCounter;
25 
26 class GEO_PackedNameMap;
28 
29 /// Map to translate from Alembic attribute names to Houdini names
31  : public UT_IntrusiveRefCounter<GEO_PackedNameMap>
32 {
33 public:
35 
37  {
38  public:
39  LoadContainer(const char* key): myKey(key) {}
40  ~LoadContainer() override {}
41 
43  {
44  return myKey;
45  }
46 
49  };
50 
53 
54  /// Compare equality
55  bool isEqual(const GEO_PackedNameMap &src) const;
56 
57  /// Compute a hash for the name map
58  uint hash() const;
59 
60  /// Is the name map default (allow all attributes and no renaming)
61  bool isDefault() const
62  {
63  for (int i = 0; i < GA_ATTRIB_OWNER_N; ++i)
64  if (myPatterns[i] != "*")
65  return false;
66  return myMap.entries() == 0 && myTypeInfoMap.entries() == 0;
67  }
68 
69  /// @{
70  /// Equality operator
71  bool operator==(const GEO_PackedNameMap &src) const
72  { return isEqual(src); }
73  bool operator!=(const GEO_PackedNameMap &src) const
74  { return !isEqual(src); }
75  /// @}
76 
77  /// Get the name mapping. If the name isn't mapped, the original name
78  /// will be returned.
79  /// If the attribute should be skipped, a NULL pointer will be returned.
80  const char *getName(const char *name) const;
81  const char *getName(const std::string &name) const
82  { return getName(name.c_str()); }
83  /// Get the typeinfo mapping. If the name isn't mapped, nullptr will be
84  /// returned.
85  const char *getTypeInfo(const char *name) const;
86  const char *getTypeInfo(const std::string &name) const
87  { return getTypeInfo(name.c_str()); }
88 
89  /// Add a translation from the abcName to the houdini attribute name
90  void addMap(const char *abcName, const char *houdiniName);
91 
92  /// Add a translation from the abcName to the attribute's type info
93  void addTypeInfo(const char *abcName, const char *typeInfo);
94 
95  /// Avoid adding an attribute of the given name. This is done by
96  void skip(const char *abcName)
97  { addMap(abcName, NULL); }
98 
99  /// Set a pattern for load attributes. Only attributes which match the
100  /// given pattern should be created. The default pattern is "*" (allowing
101  /// all attributes).
102  void setPattern(GA_AttributeOwner owner,
103  const char *pattern);
104 
105  /// Return the attribute type pattern
106  const char *pattern(GA_AttributeOwner owner) const
107  { return myPatterns[owner].nonNullBuffer(); }
108 
109  /// Check to see whether an attribute can be added. This matches the
110  /// pattern for the given owner.
111  bool matchPattern(GA_AttributeOwner owner,
112  const char *name) const;
113 
114  /// @{
115  /// JSON I/O. It's up to the caller to determine which version of the name
116  /// map to load. This is typically done by using a different keyword when
117  /// loading/saving.
118  ///
119  /// - Version 1: @n
120  /// Saves a single map for the attribute name map
121  /// - Version 2: @n
122  /// Saves a keyword map with different components. The name map along
123  /// with the patterns.
124  bool save(UT_JSONWriter &w, int version=2) const;
125  static bool load(GEO_PackedNameMapPtr &map, UT_JSONParser &p, int version);
126  /// @}
127 
128  /// Report memory usage (includes all shared memory)
129  int64 getMemoryUsage(bool inclusive) const;
130 
131  /// Count memory usage using a UT_MemoryCounter in order to count
132  /// shared memory correctly.
133  void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
134 
135  void dump() const;
136 
137 private:
138  UT_String myPatterns[GA_ATTRIB_OWNER_N];
140  MapType myMap;
141  MapType myTypeInfoMap;
142 };
143 
144 #endif
UT_SymbolMap< UT_String > MapType
bool operator!=(const GEO_PackedNameMap &src) const
const char * getTypeInfo(const std::string &name) const
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
A reference counter base class for use with UT_IntrusivePtr.
Map to translate from Alembic attribute names to Houdini names.
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
bool operator==(const GEO_PackedNameMap &src) const
#define GEO_API
Definition: GEO_API.h:14
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
bool isDefault() const
Is the name map default (allow all attributes and no renaming)
GLushort pattern
Definition: glad.h:2583
const char * pattern(GA_AttributeOwner owner) const
Return the attribute type pattern.
GT_API const UT_StringHolder version
GA_AttributeOwner
Definition: GA_Types.h:34
const char * getName(const std::string &name) const
void skip(const char *abcName)
Avoid adding an attribute of the given name. This is done by.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
UT_StringHolder getSharedDataKey() const override
Returns the key that is used to refer to this shared data.
unsigned int uint
Definition: SYS_Types.h:45
GLenum src
Definition: glcorearb.h:1793