From dedd667655631511e39d789f25f1a340510ce888 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 5 Oct 2006 21:14:49 +0000 Subject: [PATCH] Hash and List examples added git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9413 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Devel/internals.html | 105 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 4 deletions(-) diff --git a/Doc/Devel/internals.html b/Doc/Devel/internals.html index 4a8988bb5..4fd2d53ba 100644 --- a/Doc/Devel/internals.html +++ b/Doc/Devel/internals.html @@ -423,13 +423,112 @@ operations that allow them to be used interchangeably with DOH file objects.

2.6 Lists

-[ TODO ] +

+Example usage of lists: +

+ +
+
+/* Create and populate */
+List *list = NewList();
+Append(list, NewString("listval1"));
+Append(list, NewString("listval2"));
+Append(list, NewString("listval3"));
+Append(list, NewString("listval4"));
+Append(list, NewString("listval5"));
+
+/* Size */
+Printf(stdout, "list len: %d\n", Len(list));
+
+/* Delete */
+Delitem(list, 3);
+
+/* Replace */
+Setitem(list, 0, NewString("newlistval1"));
+
+/* Get */
+String *item = Getitem(list,1);
+if (item)
+  Printf(stdout, "get: %s\n", item);
+else
+  Printf(stdout, "get: [non-existent]\n");
+
+/* Iterate through the container */
+int len = Len(list);
+for (int i=0; i<len; i++) {
+  String *item = Getitem(list,i);
+  Printf(stdout, "list item: %s\n", item);
+}
+
+ + +

+Resulting output: +

+ +
+
+hash len: 5
+get: hashval2
+hash item: hashval5 [h5]
+hash item: hashval1 [h1]
+hash item: hashval2 [h2]
+hash item: hashval3 [h3]
+
+

2.7 Hash tables

-[ TODO ] +

+Example usage of hash tables: +

+ +
+
+/* Create and populate */
+Hash *hash = NewHash();
+Setattr(hash, "h1", NewString("hashval1"));
+Setattr(hash, "h2", NewString("hashval2"));
+Setattr(hash, "h3", NewString("hashval3"));
+Setattr(hash, "h4", NewString("hashval4"));
+Setattr(hash, "h5", NewString("hashval5"));
+
+/* Size */
+Printf(stdout, "hash len: %d\n", Len(hash));
+
+/* Delete */
+Delattr(hash, "h4");
+
+/* Get */
+String *item = Getattr(hash, "h2");
+if (item)
+  Printf(stdout, "get: %s\n", item);
+else
+  Printf(stdout, "get: [non-existent]\n");
+
+/* Iterate through the container */
+Iterator it;
+for (it = First(hash); it.key; it= Next(it))
+  Printf(stdout, "hash item: %s [%s]\n", (it.item), (it.key));
+
+
+ +

+Resulting output: +

+ +
+
+list len: 5
+get: listval2
+list item: newlistval1
+list item: listval2
+list item: listval3
+list item: listval5
+
+

2.8 Files

@@ -453,8 +552,6 @@ operations that allow them to be used interchangeably with DOH file objects.

3. Types and Typemaps

-Revised: Dave Beazley (8/14/00) -

The representation and manipulation of types is currently in the process of being reorganized and (hopefully) simplified. The