HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XUSD_AutoCollection.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef __XUSD_AutoCollection_h__
19 #define __XUSD_AutoCollection_h__
20 
21 #include "HUSD_API.h"
22 #include "HUSD_TimeCode.h"
23 #include "HUSD_Utils.h"
24 #include "XUSD_PathSet.h"
26 #include <UT/UT_StringHolder.h>
27 #include <pxr/usd/sdf/path.h>
28 #include <pxr/usd/usd/stage.h>
29 
30 extern "C" {
31  SYS_VISIBILITY_EXPORT extern void newAutoCollection(void *unused);
32 };
33 class HUSD_AutoAnyLock;
34 
36 
38 
40 {
41 public:
43  { }
45  { }
46 
47  virtual bool canCreateAutoCollection(const char *token) const = 0;
48  virtual XUSD_AutoCollection *create(const char *token,
49  HUSD_AutoAnyLock &lock,
51  int nodeid,
52  const HUSD_TimeCode &timecode) const = 0;
53 };
54 
55 template <class AutoCollection>
57 {
58 public:
60  : myPrefix(prefix)
61  { }
63  { }
64 
66  const char *token) const override
67  {
68  if (strncmp(token, myPrefix.c_str(), myPrefix.length()) != 0)
69  return false;
70 
71  // Token starts with our prefix. Now if our prefix doesn't end with
72  // a ':', make sure the token follows the prefix with either a ':'
73  // or a null char.
74  if (!myPrefix.endsWith(":") &&
75  token[myPrefix.length()] != ':' &&
76  token[myPrefix.length()] != '\0')
77  return false;
78 
79  return true;
80  }
81  XUSD_AutoCollection *create(const char *token,
82  HUSD_AutoAnyLock &lock,
84  int nodeid,
85  const HUSD_TimeCode &timecode) const override
86  {
87  if (canCreateAutoCollection(token))
88  return new AutoCollection(token + myPrefix.length(),
89  lock, demands, nodeid, timecode);
90 
91  return nullptr;
92  }
93 
94 private:
95  UT_StringHolder myPrefix;
96 };
97 
99 {
100 public:
101  XUSD_AutoCollection(const char *token,
102  HUSD_AutoAnyLock &lock,
104  int nodeid,
105  const HUSD_TimeCode &timecode);
106  virtual ~XUSD_AutoCollection();
107 
108  // Determines whether or not this class works in random access mode.
109  virtual bool randomAccess() const = 0;
110 
111  // A non-random access auto collection does its own traversal of the stage
112  // all at once when the auto collection is created, generating a full set
113  // of all matching paths at once.
114  virtual void matchPrimitives(XUSD_PathSet &matches) const
115  { UT_ASSERT(false); }
116 
117  // A random access auto collection gets no benefit from being executed
118  // as a depth first traversal of the whole stage. It will be called for
119  // each primitive as part of the overall pattern matching process.
121  bool *prune_branch) const
122  { UT_ASSERT(false); return false; }
123 
125  { return myTokenParsingError; }
126 
127  static bool canCreateAutoCollection(const char *token);
128  static XUSD_AutoCollection *create(const char *token,
129  HUSD_AutoAnyLock &lock,
131  int nodeid,
132  const HUSD_TimeCode &timecode);
133  static void registerPlugins();
134  static void registerPlugin(XUSD_AutoCollectionFactory *factory);
135 
136 protected:
140  int myNodeId;
144 
145 private:
146  static UT_Array<XUSD_AutoCollectionFactory *> theFactories;
147 };
148 
150 {
151 public:
152  XUSD_SimpleAutoCollection(const char *token,
153  HUSD_AutoAnyLock &lock,
155  int nodeid,
156  const HUSD_TimeCode &timecode);
157  ~XUSD_SimpleAutoCollection() override;
158 
159  bool randomAccess() const override
160  { return false; }
161  void matchPrimitives(XUSD_PathSet &matches) const override;
162  virtual bool matchPrimitive(const UsdPrim &prim,
163  bool *prune_branch) const = 0;
164 };
165 
167 {
168 public:
169  XUSD_RandomAccessAutoCollection(const char *token,
170  HUSD_AutoAnyLock &lock,
172  int nodeid,
173  const HUSD_TimeCode &timecode);
175 
176  bool randomAccess() const override
177  { return true; }
179  bool *prune_branch) const override;
180  virtual bool matchPrimitive(const UsdPrim &prim,
181  bool *prune_branch) const = 0;
182 };
183 
185 
186 #endif
187 
bool randomAccess() const override
#define SYS_VISIBILITY_EXPORT
const UT_StringHolder & getTokenParsingError() const
HUSD_TimeCode myHusdTimeCode
#define HUSD_API
Definition: HUSD_API.h:32
bool endsWith(const UT_StringView &suffix, bool case_sense=true) const
HUSD_PrimTraversalDemands
Definition: HUSD_Utils.h:31
XUSD_SimpleAutoCollectionFactory(const char *prefix)
exint length() const
UT_StringHolder myTokenParsingError
Definition: prim.h:132
virtual XUSD_AutoCollection * create(const char *token, HUSD_AutoAnyLock &lock, HUSD_PrimTraversalDemands demands, int nodeid, const HUSD_TimeCode &timecode) const =0
SYS_FORCE_INLINE const char * c_str() const
Definition: path.h:288
GLsizei const GLchar *const * path
Definition: glew.h:6461
HUSD_AutoAnyLock & myLock
HUSD_PrimTraversalDemands myDemands
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
virtual void matchPrimitives(XUSD_PathSet &matches) const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual bool matchRandomAccessPrimitive(const SdfPath &path, bool *prune_branch) const
bool canCreateAutoCollection(const char *token) const override
XUSD_AutoCollection * create(const char *token, HUSD_AutoAnyLock &lock, HUSD_PrimTraversalDemands demands, int nodeid, const HUSD_TimeCode &timecode) const override
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:135
SYS_VISIBILITY_EXPORT void newAutoCollection(void *unused)
virtual bool canCreateAutoCollection(const char *token) const =0