diff options
| author | 2009-10-17 23:03:07 +0200 | |
|---|---|---|
| committer | 2009-10-17 23:03:07 +0200 | |
| commit | a2588b4b19e898d483d5512cf974e1ccda45d5b6 (patch) | |
| tree | d8dd122d25b6ffb72a4fde1bb0445fba2ef84ef1 /swig | |
| parent | 33de762cf636e3f13f17e02d70de2869664e3f2b (diff) | |
| download | libplist-a2588b4b19e898d483d5512cf974e1ccda45d5b6.tar.gz libplist-a2588b4b19e898d483d5512cf974e1ccda45d5b6.tar.bz2 | |
Add dynamic subtyping for abstract nodes.
Diffstat (limited to 'swig')
| -rw-r--r-- | swig/plist.i | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/swig/plist.i b/swig/plist.i index 1b97451..41931b0 100644 --- a/swig/plist.i +++ b/swig/plist.i | |||
| @@ -40,6 +40,55 @@ PListNode *allocate_plist_wrapper(plist_t plist, char should_keep_plist) { | |||
| 40 | int length = PyString_Size($input); | 40 | int length = PyString_Size($input); |
| 41 | $1 = std::vector<char>(buffer, buffer + length); | 41 | $1 = std::vector<char>(buffer, buffer + length); |
| 42 | } | 42 | } |
| 43 | |||
| 44 | %apply SWIGTYPE *DYNAMIC { PList::Node* }; | ||
| 45 | %apply SWIGTYPE *DYNAMIC { PList::Structure* }; | ||
| 46 | |||
| 47 | %{ | ||
| 48 | static swig_type_info *Node_dynamic(void **ptr) | ||
| 49 | { | ||
| 50 | PList::Node* node = dynamic_cast<PList::Node *>((PList::Node *) *ptr); | ||
| 51 | if (node) | ||
| 52 | { | ||
| 53 | plist_type type = node->GetType(); | ||
| 54 | switch(type) | ||
| 55 | { | ||
| 56 | case PLIST_DICT: | ||
| 57 | *ptr = dynamic_cast<PList::Dictionary *>(node); | ||
| 58 | return SWIGTYPE_p_PList__Dictionary; | ||
| 59 | case PLIST_ARRAY: | ||
| 60 | *ptr = dynamic_cast<PList::Array *>(node); | ||
| 61 | return SWIGTYPE_p_PList__Array; | ||
| 62 | case PLIST_BOOLEAN: | ||
| 63 | *ptr = dynamic_cast<PList::Boolean *>(node); | ||
| 64 | return SWIGTYPE_p_PList__Boolean; | ||
| 65 | case PLIST_UINT: | ||
| 66 | *ptr = dynamic_cast<PList::Integer *>(node); | ||
| 67 | return SWIGTYPE_p_PList__Integer; | ||
| 68 | case PLIST_REAL: | ||
| 69 | *ptr = dynamic_cast<PList::Real *>(node); | ||
| 70 | return SWIGTYPE_p_PList__Real; | ||
| 71 | case PLIST_STRING: | ||
| 72 | *ptr = dynamic_cast<PList::String *>(node); | ||
| 73 | return SWIGTYPE_p_PList__String; | ||
| 74 | case PLIST_DATE: | ||
| 75 | *ptr = dynamic_cast<PList::Date *>(node); | ||
| 76 | return SWIGTYPE_p_PList__Date; | ||
| 77 | case PLIST_DATA: | ||
| 78 | *ptr = dynamic_cast<PList::Data *>(node); | ||
| 79 | return SWIGTYPE_p_PList__Data; | ||
| 80 | default: | ||
| 81 | break; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | return 0; | ||
| 85 | } | ||
| 86 | %} | ||
| 87 | |||
| 88 | // Register the above casting function | ||
| 89 | DYNAMIC_CAST(SWIGTYPE_p_PList__Node, Node_dynamic); | ||
| 90 | DYNAMIC_CAST(SWIGTYPE_p_PList__Structure, Node_dynamic); | ||
| 91 | |||
| 43 | #else | 92 | #else |
| 44 | #endif | 93 | #endif |
| 45 | 94 | ||
