HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HOM_HDAModule.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  * COMMENTS:
7  */
8 
9 #ifndef __HOM_HDAModule_h__
10 #define __HOM_HDAModule_h__
11 
12 #include "HOM_API.h"
13 #include "HOM_Defines.h"
14 #include "HOM_Errors.h"
15 #include "HOM_Module.h"
16 
18 
20 
21 SWIGOUT(%rename(HDAModule) HOM_HDAModule;)
22 
24 {
25 public:
27  { HOM_CONSTRUCT_OBJECT(this) }
29  { HOM_CONSTRUCT_OBJECT(this) }
30  virtual ~HOM_HDAModule()
31  { HOM_DESTRUCT_OBJECT(this) }
32 
33  virtual std::string __repr__() = 0;
34 
35  // Helper method for hou.hda.reloadHDAModule().
36  virtual void __reload() = 0;
37 
38 #if defined(SWIG) && defined(SWIGPYTHON)
39 %extend
40 {
41  // __getattr__ will look up the attribute name in the evaluation
42  // context's dictionaries and return the corresponding object if
43  // it exists. This way, the HDAModule object can give a dictionary
44  // the behaviour of an object.
45  InterpreterObject __getattr__(const char *name)
46  {
47  HOM_AutoLock hom_lock;
48  PY_InterpreterAutoLock py_lock;
49 
50  // First check the context's locals dictionary. If the context
51  // pointer is null we treat it as though the dictionary is empty.
52  PY_EvaluationContext *context = self->getEvaluationContext();
53  PyObject *dict = context
54  ? (PyObject *)context->getGlobalsDict() : NULL;
55  PyObject *attribute = (dict && name)
56  ? PyDict_GetItemString(dict, name) : NULL;
57 
58  // If the lookup failed, try the globals dictionary.
59  if (!attribute && dict)
60  {
61  dict = (PyObject *)context->getGlobalsDict();
62  attribute = name ? PyDict_GetItemString(dict, name) : NULL;
63  }
64 
65  // If we found an object in the dictionary, return it, being careful
66  // to increment the reference count on the object.
67  if (attribute)
68  return HOMincRef(attribute);
69 
70  // We didn't find the object, so raise an exception.
71  if (!name)
72  name = "";
73  UT_WorkBuffer error_message;
74  error_message.sprintf("'module' object has no attribute '%s'", name);
75  PyErr_SetString(PyExc_AttributeError, error_message.buffer());
76  return NULL;
77  }
78 }
79 
80 #endif
81 
82  // This method is not wrapped by swig. It is overridden by the HOMF
83  // subclass to provide access to the Python evaluation context containing
84  // the module's contents. It is ok for this method to return null.
85  SWIGOUT(%ignore getEvaluationContext;)
86  virtual PY_EvaluationContext *getEvaluationContext() = 0;
87 };
88 
89 #endif
#define HOM_DESTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:983
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
#define SWIGOUT(x)
Definition: HOM_Defines.h:24
#define HOM_API
Definition: HOM_API.h:13
#define HOM_CONSTRUCT_OBJECT(pointer)
Definition: HOM_Module.h:982
HOM_HDAModule(const HOM_HDAModule &module)
Definition: HOM_HDAModule.h:28
GLuint const GLchar * name
Definition: glcorearb.h:785
int sprintf(const char *fmt,...) SYS_PRINTF_CHECK_ATTRIBUTE(2
virtual ~HOM_HDAModule()
Definition: HOM_HDAModule.h:30
const char * buffer() const