HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_PythonConverter.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 __HUSD_PythonConverter_h__
19 #define __HUSD_PythonConverter_h__
20 
21 #include "HUSD_API.h"
22 #include "HUSD_DataHandle.h"
23 #include "HUSD_Overrides.h"
24 
26 {
27 public:
29  HUSD_AutoAnyLock &lock);
31  const HUSD_ConstOverridesPtr &overrides);
33 
34  // Functions for getting python objects representing a stage or layer
35  // from an HUSD_AutoAnyLock. The "Editable" methods only work if the
36  // lock is an HUSD_AutoWriteLock.
37  void *getEditableLayer() const;
38  void *getEditableOverridesLayer() const;
39  void *getActiveLayer() const;
40  void *getEditableStage() const;
41  void *getEditableOverridesStage() const;
42  void *getStage() const;
43  void *getSourceLayer(int layerindex) const;
44  int getSourceLayerCount() const;
45 
46  // Functions for getting python objects representing a layer from an
47  // HUSD_ConstOverridesPtr. Only read-only access is supported.
48  void *getOverridesLayer(
49  HUSD_OverridesLayerId layer_id) const;
50 
51  // Returns the lock the converter holds.
53  { return myAnyLock; }
54 
55 private:
56  HUSD_AutoAnyLock *myAnyLock;
57  HUSD_ConstOverridesPtr myOverrides;
58 };
59 
60 
61 // ===========================================================================
62 // Utility class for managing the python converter.
64 {
65 public:
66  /// Creates a python converter and sets the pointer reference to it.
67  /// Referenced pointer's lifetime must be greater than object of this class.
69  HUSD_PythonConverter **converter_ptr )
70  : myPythonConverter( lock )
71  , myPythonConverterPtr( converter_ptr )
72  {
73  // Set the ref to member converter. It sets the ctor's parameter too.
74  if( myPythonConverterPtr)
75  *myPythonConverterPtr = &myPythonConverter;
76  }
77 
79  {
80  // The python converter object is being destroyed, so clear the ref.
81  if( myPythonConverterPtr)
82  *myPythonConverterPtr = nullptr;
83  }
84 
85 private:
86  HUSD_PythonConverter myPythonConverter;
87  HUSD_PythonConverter **myPythonConverterPtr;
88 
89 };
90 
91 #endif
92 
HUSD_AutoAnyLock * getLock() const
#define HUSD_API
Definition: HUSD_API.h:32
HUSD_OverridesLayerId
Definition: HUSD_Utils.h:58
HUSD_ScopedPythonConverter(HUSD_AutoAnyLock &lock, HUSD_PythonConverter **converter_ptr)