Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / libraries / PyMite / vm / class.h
blob15efcd938c45ba0a6756aa50615420e2c387d1f9
1 /*
2 # This file is Copyright 2009, 2010 Dean Hall.
4 # This file is part of the PyMite VM.
5 # The PyMite VM is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU GENERAL PUBLIC LICENSE Version 2.
8 # The PyMite VM is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # A copy of the GNU GENERAL PUBLIC LICENSE Version 2
12 # is seen in the file COPYING in this directory.
16 #ifndef __CLASS_H__
17 #define __CLASS_H__
19 /**
20 * \file
21 * \brief Class header.
25 /**
26 * Class struct
28 * This C struct is used for PyMite class objects
29 * Note: Exceptions are objects.
31 typedef struct PmClass_s
33 /** Object descriptor */
34 PmObjDesc_t od;
36 /** Attributes dict */
37 pPmDict_t cl_attrs;
39 /** Bases tuple */
40 pPmTuple_t cl_bases;
41 } PmClass_t,
42 *pPmClass_t;
44 /** Class instance struct */
45 typedef struct PmInstance_s
47 /** Object descriptor */
48 PmObjDesc_t od;
50 /** Class of this instance */
51 pPmClass_t cli_class;
53 /** Attributes dict */
54 pPmDict_t cli_attrs;
55 } PmInstance_t,
56 *pPmInstance_t;
58 /** Method struct */
59 typedef struct PmMethod_s
61 /** Object descriptor */
62 PmObjDesc_t od;
64 /** Class instance of this method */
65 pPmInstance_t m_instance;
67 /** Func of this method */
68 pPmFunc_t m_func;
70 /** Attributes dict */
71 pPmDict_t m_attrs;
72 } PmMethod_t,
73 *pPmMethod_t;
76 /**
77 * Creates a new Class object from the methods dict, bases tuple,
78 * and name string.
80 * @param pmeths ptr to methods dict.
81 * @param pbases ptr to bases tuple.
82 * @param pname ptr to name string.
83 * @param r_pclass Return by ref, ptr to new class
84 * @return Return status
86 PmReturn_t class_new(pPmObj_t pmeths, pPmObj_t pbases, pPmObj_t pname,
87 pPmObj_t *r_pclass);
89 /**
90 * Returns an instance of the given class
92 * @param pclass Pointer to class object
93 * @param r_pobj Return by ref, instance object
94 * @return Return status
96 PmReturn_t class_instantiate(pPmObj_t pclass, pPmObj_t *r_pobj);
98 /**
99 * Returns a method based on the given inputs
101 * @param pinstance ptr to instance
102 * @param pfunc ptr to func
103 * @param r_pmeth Return by ref, ptr to new method
104 * @return Return status
106 PmReturn_t class_method(pPmObj_t pinstance, pPmObj_t pfunc, pPmObj_t *r_pmeth);
109 * Returns the first attribute named __init__ in the class' inheritance tree
111 * @param pobj ptr to class or instance to search
112 * @param pname ptr to name of attr to find
113 * @param r_pobj Return by ref, ptr to attr if found, or undetermined
114 * @return Return status
116 PmReturn_t class_getAttr(pPmObj_t pobj, pPmObj_t pname, pPmObj_t *r_pobj);
119 * Returns a C boolean if the base class is found in the inheritance tree
120 * of the test class. NOTE: This function is recursive.
122 * @param ptest_class ptr to class whose inheritance tree is searched
123 * @param pbase_class ptr to class to look for
124 * @return Returns C_TRUE if pbase_class is found in the inheritance tree;
125 * C_FALSE otherwise.
127 uint8_t class_isSubclass(pPmObj_t ptest_class, pPmObj_t pbase_class);
129 #endif /* __CLASS_H__ */