MCPcopy Create free account
hub / github.com/carbonengine/trinity / PyGetParameterAnnotations

Function PyGetParameterAnnotations

trinity/Shader/Tr2Effect_Blue.cpp:17–90  ·  view source on GitHub ↗

--------------------------------------------------------------- PyGetParameterAnnotations Gets a python dict of the parameter annotations, using a parameter object or string for the name ---------------------------------------------------------------

Source from the content-addressed store, hash-verified

15// Gets a python dict of the parameter annotations, using a parameter object or string for the name
16// ---------------------------------------------------------------
17static PyObject* PyGetParameterAnnotations( PyObject* self, PyObject* args )
18{
19 Tr2Effect* pThis = BluePythonCast<Tr2Effect*>( self );
20
21 PyObject* parameterObject = NULL;
22 if( !PyArg_ParseTuple( args, "O", &parameterObject ) )
23 return NULL;
24
25 std::string parameterNameString;
26
27 if( !pThis->GetShaderStateInterface() )
28 {
29 Py_INCREF( Py_None );
30 return Py_None;
31 }
32
33 // If we got passed a string, look up the string, if we got passed a parameter, look up the name of that
34 if( PyVerCompat::IsPyString( parameterObject ) )
35 {
36 parameterNameString = FromPython<std::string>( parameterObject );
37 }
38 else
39 {
40 ITriEffectParameterPtr iParameterObject( parameterObject );
41 if( iParameterObject != NULL )
42 {
43 parameterNameString = iParameterObject->GetParameterName();
44 }
45 else
46 {
47 Py_INCREF( Py_None );
48 return Py_None;
49 }
50 }
51
52 PyObject* tmpValue = NULL;
53 PyObject* annotationDict = PyDict_New();
54
55 auto annotations = pThis->GetShaderStateInterface()->GetParameterAnnotations( parameterNameString.c_str() );
56 if( annotations == nullptr )
57 {
58 Py_INCREF( Py_None );
59 return Py_None;
60 }
61 for( auto annotation = annotations->begin(); annotation != annotations->end(); ++annotation )
62 {
63 if( annotation->type == Tr2EffectParameterAnnotation::BOOL )
64 {
65 tmpValue = ToPython( annotation->boolValue );
66 PyDict_SetItemString( annotationDict, annotation->name, tmpValue );
67 Py_DECREF( tmpValue );
68 }
69 else if( annotation->type == Tr2EffectParameterAnnotation::INT )
70 {
71 tmpValue = ToPython( annotation->intValue );
72 PyDict_SetItemString( annotationDict, annotation->name, tmpValue );
73 Py_DECREF( tmpValue );
74 }

Callers

nothing calls this directly

Calls 7

IsPyStringFunction · 0.85
ToPythonFunction · 0.85
GetParameterNameMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected