3636 */
3737
3838
39- #ifndef ListWrapper_h
40- #define ListWrapper_h
41-
42- #include < sbml/util/List.h>
43- #include < sedml/common/extern.h>
44-
45- LIBSEDML_CPP_NAMESPACE_USE
46-
47- /* *
48- *
49- * ListWrapper : a wrapper template class for List class.
50- */
51- template <typename IType>
52- class LIBSEDML_EXTERN ListWrapper
53- {
54- private:
55- List *mList ;
56- bool mMemOwn ;
57-
58- public:
59- /* *
60- * Creates a new List.
61- *
62- * A ListXXX object is newly created (i.e. owned by the caller) and
63- * deleted by the destructor below if the constructor of this class
64- * invoked without an argument.
65- */
66- ListWrapper () : mList (new List()), mMemOwn (true ) {}
67-
68-
69- #ifndef SWIG
70- /* *
71- * Creates a new List.
72- * (internal implementation)
73- *
74- * An existing List object is given (i.e. not owned by the caller)
75- * and stored.
76- *
77- */
78- ListWrapper (List* list, bool memown = false ) : mList(list), mMemOwn(memown) {}
79-
80- List* getList () { return mList ; }
81- #endif
82-
83-
84- /* *
85- * destructor
86- */
87- virtual ~ListWrapper () { if (mMemOwn ) delete mList ; }
88-
89-
90- /* *
91- * Adds @p item to the end of this List.
92- *
93- * @param item a pointer to the item to be added.
94- */
95- void add (IType* item)
96- {
97- if (mList ) mList ->add (static_cast <void *>(item));
98- }
99-
100-
101- /* *
102- * Get the nth item in this List.
103- *
104- * If @p n > <code>listobj.size()</code>, this method returns @c 0.
105- *
106- * @return the nth item in this List.
107- *
108- * @see remove()
109- *
110- */
111- IType* get (unsigned int n) const
112- {
113- return (mList ) ? static_cast <IType*>(mList ->get (n)) : 0 ;
114- }
115-
116-
117- /* *
118- * Adds @p item to the beginning of this List.
119- *
120- * @param item a pointer to the item to be added.
121- */
122- void prepend (IType* item)
123- {
124- if (mList ) mList ->prepend (static_cast <void *>(item));
125- }
126-
127-
128- /* *
129- * Removes the nth item from this List and returns a pointer to it.
130- *
131- * If @p n > <code>listobj.size()</code>, this method returns @c 0.
132- *
133- * @return the nth item in this List.
134- *
135- * @see get()
136- */
137- IType* remove (unsigned int n)
138- {
139- return (mList ) ? static_cast <IType*>(mList ->remove (n)) : 0 ;
140- }
141-
142-
143- /* *
144- * Get the number of items in this List.
145- *
146- * @return the number of elements in this List.
147- */
148- unsigned int getSize () const
149- {
150- return (mList ) ? mList ->getSize () : 0 ;
151- }
152- };
153-
154- #endif // ListWrapper_h
39+ #ifndef ListWrapper_h
40+ #define ListWrapper_h
41+
42+ #include < sbml/util/List.h>
43+ #include < sedml/common/extern.h>
44+
45+ LIBSEDML_CPP_NAMESPACE_USE
46+
47+ /* *
48+ *
49+ * ListWrapper : a wrapper template class for List class.
50+ */
51+ template <typename IType>
52+ class LIBSEDML_EXTERN ListWrapper
53+ {
54+ private:
55+ List *mList ;
56+ bool mMemOwn ;
57+
58+ public:
59+ /* *
60+ * Creates a new List.
61+ *
62+ * A ListXXX object is newly created (i.e. owned by the caller) and
63+ * deleted by the destructor below if the constructor of this class
64+ * invoked without an argument.
65+ */
66+ ListWrapper () : mList (new List()), mMemOwn (true ) {}
67+
68+
69+ #ifndef SWIG
70+ /* *
71+ * Creates a new List.
72+ * (internal implementation)
73+ *
74+ * An existing List object is given (i.e. not owned by the caller)
75+ * and stored.
76+ *
77+ */
78+ ListWrapper (List* list, bool memown = false ) : mList(list), mMemOwn(memown) {}
79+
80+ List* getList () { return mList ; }
81+ #endif
82+
83+
84+ /* *
85+ * destructor
86+ */
87+ virtual ~ListWrapper () { if (mMemOwn ) delete mList ; }
88+
89+
90+ /* *
91+ * Adds @p item to the end of this List.
92+ *
93+ * @param item a pointer to the item to be added.
94+ */
95+ void add (IType* item)
96+ {
97+ if (mList ) mList ->add (static_cast <void *>(item));
98+ }
99+
100+
101+ /* *
102+ * Get the nth item in this List.
103+ *
104+ * If @p n > <code>listobj.size()</code>, this method returns @c 0.
105+ *
106+ * @return the nth item in this List.
107+ *
108+ * @see remove()
109+ *
110+ */
111+ IType* get (unsigned int n) const
112+ {
113+ return (mList ) ? static_cast <IType*>(mList ->get (n)) : 0 ;
114+ }
115+
116+
117+ /* *
118+ * Adds @p item to the beginning of this List.
119+ *
120+ * @param item a pointer to the item to be added.
121+ */
122+ void prepend (IType* item)
123+ {
124+ if (mList ) mList ->prepend (static_cast <void *>(item));
125+ }
126+
127+
128+ /* *
129+ * Removes the nth item from this List and returns a pointer to it.
130+ *
131+ * If @p n > <code>listobj.size()</code>, this method returns @c 0.
132+ *
133+ * @return the nth item in this List.
134+ *
135+ * @see get()
136+ */
137+ IType* remove (unsigned int n)
138+ {
139+ return (mList ) ? static_cast <IType*>(mList ->remove (n)) : 0 ;
140+ }
141+
142+
143+ /* *
144+ * Get the number of items in this List.
145+ *
146+ * @return the number of elements in this List.
147+ */
148+ unsigned int getSize () const
149+ {
150+ return (mList ) ? mList ->getSize () : 0 ;
151+ }
152+
153+ #ifdef SWIGPYTHON
154+ int __len__ ()
155+ {
156+ return getSize ();
157+ }
158+
159+ IType* __getitem__ (unsigned int index)
160+ {
161+ return get (index);
162+ }
163+
164+ #endif // SWIGPYTHON
165+
166+ };
167+
168+ #endif // ListWrapper_h
169+
0 commit comments