00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __HOM_IterableList_h__
00017 #define __HOM_IterableList_h__
00018
00019 #include "HOM_API.h"
00020 #include "HOM_Defines.h"
00021 #include "HOM_Errors.h"
00022 #include "HOM_Module.h"
00023 #include <string>
00024 #include <vector>
00025 #include <stdexcept>
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #ifdef SWIG
00049 #define GETITEM_SWIG_EXTENSION \
00050 %extend { \
00051 \
00052 %newobject __getitem__; \
00053 InterpreterObject __getitem__(int key) \
00054 throw(HOM_ObjectWasDeleted, HOM_Error) \
00055 { \
00056 int length = self->__len__(); \
00057 if (key < 0) \
00058 key += length; \
00059 if (key < 0 || key >= length) \
00060 { \
00061 PyErr_SetString(PyExc_IndexError, "Invalid index"); \
00062 return NULL; \
00063 } \
00064 return HOMconvertValueForInterpreter( \
00065 self->getItemWithValidIndex(key), SWIG_POINTER_OWN); \
00066 } \
00067 }
00068 #else
00069 #define GETITEM_SWIG_EXTENSION
00070 #endif
00071
00072 #define DEFINE_HOM_ITERABLE_LIST(template_parm, template_type, specialization, getitem_type) \
00073 template <template_parm> \
00074 class HOM_IterableList specialization \
00075 { \
00076 public: \
00077 HOM_IterableList() \
00078 { HOM_CONSTRUCT_OBJECT(this) } \
00079 HOM_IterableList(const HOM_IterableList<template_type> &) \
00080 { HOM_CONSTRUCT_OBJECT(this) } \
00081 virtual ~HOM_IterableList() \
00082 { HOM_DESTRUCT_OBJECT(this) } \
00083 \
00084 \
00085 \
00086 GETITEM_SWIG_EXTENSION \
00087 \
00088 virtual int __len__() throw(HOM_ObjectWasDeleted, HOM_Error) = 0; \
00089 virtual std::string __repr__() throw(HOM_ObjectWasDeleted, HOM_Error) = 0; \
00090 \
00091 SWIGOUT(%ignore getItemWithValidIndex;) \
00092 virtual getitem_type getItemWithValidIndex(int key) \
00093 throw(HOM_ObjectWasDeleted, HOM_Error) = 0; \
00094 };
00095
00096
00097
00098 DEFINE_HOM_ITERABLE_LIST(typename T, T, , T*)
00099 DEFINE_HOM_ITERABLE_LIST(, int, <int>, int)
00100 DEFINE_HOM_ITERABLE_LIST(, float, <float>, float)
00101 DEFINE_HOM_ITERABLE_LIST(, double, <double>, double)
00102 DEFINE_HOM_ITERABLE_LIST(, std::string, <std::string>, std::string)
00103
00104 #undef DEFINE_HOM_ITERABLE_LIST
00105 #undef GETITEM_SWIG_EXTENSION
00106
00107 #endif