summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMichael Jennings <mej@kainx.org>2004-01-24 19:56:23 +0000
committerMichael Jennings <mej@kainx.org>2004-01-24 19:56:23 +0000
commitf6d4c98083e357f3d4856b551ea5c35c7b66ce8f (patch)
tree4005a93286eda2bd067b26f12faeff4632ed7313 /include
parent8f010efe97de3b4759f60ad541c12f5b7305fab4 (diff)
downloadlibast-f6d4c98083e357f3d4856b551ea5c35c7b66ce8f.tar.gz
Sat Jan 24 13:54:02 2004 Michael Jennings (mej)
Added map interface (unimplemented) and a paired object class. SVN revision: 8639
Diffstat (limited to 'include')
-rw-r--r--include/libast.h2
-rw-r--r--include/libast/Makefile.am7
-rw-r--r--include/libast/array.h2
-rw-r--r--include/libast/dlinked_list.h2
-rw-r--r--include/libast/linked_list.h2
-rw-r--r--include/libast/list_if.h1
-rw-r--r--include/libast/map_if.h85
-rw-r--r--include/libast/objpair.h234
8 files changed, 329 insertions, 6 deletions
diff --git a/include/libast.h b/include/libast.h
index 7307557..3cc8a78 100644
--- a/include/libast.h
+++ b/include/libast.h
@@ -98,6 +98,7 @@ extern int re_exec();
#include <libast/types.h>
#include <libast/obj.h>
+#include <libast/objpair.h>
#include <libast/regexp.h>
#include <libast/socket.h>
#include <libast/str.h>
@@ -106,6 +107,7 @@ extern int re_exec();
#include <libast/iterator_if.h>
#include <libast/list_if.h>
+#include <libast/map_if.h>
#include <libast/vector_if.h>
#include <libast/array.h>
diff --git a/include/libast/Makefile.am b/include/libast/Makefile.am
index 42adf40..8251b49 100644
--- a/include/libast/Makefile.am
+++ b/include/libast/Makefile.am
@@ -1,8 +1,9 @@
# $Id: Makefile.am,v 1.6 2001/09/22 16:25:29 mej Exp $
-EXTRA_HEADERS = \
- array.h avl_tree.h dlinked_list.h iterator_if.h linked_list.h list_if.h \
- obj.h regexp.h socket.h str.h sysdefs.h tok.h types.h url.h vector_if.h
+EXTRA_HEADERS = \
+ array.h avl_tree.h dlinked_list.h iterator_if.h linked_list.h list_if.h \
+ obj.h objpair.h regexp.h socket.h str.h sysdefs.h tok.h types.h \
+ url.h vector_if.h
install-exec-hook:
$(mkinstalldirs) $(DESTDIR)$(includedir)/$(PACKAGE)
diff --git a/include/libast/array.h b/include/libast/array.h
index 4ea41c1..dd72be0 100644
--- a/include/libast/array.h
+++ b/include/libast/array.h
@@ -32,7 +32,7 @@
SPIF_DECL_OBJ(array) {
SPIF_DECL_PARENT_TYPE(obj);
- size_t len;
+ spif_listidx_t len;
spif_obj_t *items;
};
diff --git a/include/libast/dlinked_list.h b/include/libast/dlinked_list.h
index a571064..41bf100 100644
--- a/include/libast/dlinked_list.h
+++ b/include/libast/dlinked_list.h
@@ -38,7 +38,7 @@ SPIF_DECL_OBJ(dlinked_list_item) {
SPIF_DECL_OBJ(dlinked_list) {
SPIF_DECL_PARENT_TYPE(obj);
- size_t len;
+ spif_listidx_t len;
spif_dlinked_list_item_t head, tail;
};
diff --git a/include/libast/linked_list.h b/include/libast/linked_list.h
index c6b64bb..caedd1a 100644
--- a/include/libast/linked_list.h
+++ b/include/libast/linked_list.h
@@ -42,7 +42,7 @@ SPIF_DECL_OBJ(linked_list_item) {
SPIF_DECL_OBJ(linked_list) {
SPIF_DECL_PARENT_TYPE(obj);
- size_t len;
+ spif_listidx_t len;
spif_linked_list_item_t head;
};
diff --git a/include/libast/list_if.h b/include/libast/list_if.h
index 7ab7f5f..5a07a6a 100644
--- a/include/libast/list_if.h
+++ b/include/libast/list_if.h
@@ -70,6 +70,7 @@
#define SPIF_LIST_TO_ARRAY(o) SPIF_CAST_PTR(obj) ((SPIF_LIST_CALL_METHOD((o), to_array))(o))
typedef spif_obj_t spif_list_t;
+typedef spif_int32_t spif_listidx_t;
SPIF_DECL_OBJ(listclass) {
SPIF_DECL_PARENT_TYPE(class);
diff --git a/include/libast/map_if.h b/include/libast/map_if.h
new file mode 100644
index 0000000..034b19f
--- /dev/null
+++ b/include/libast/map_if.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 1997-2004, Michael Jennings
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies of the Software, its documentation and marketing & publicity
+ * materials, and acknowledgment shall be given in the documentation, materials
+ * and software packages that this Software was used.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _LIBAST_MAP_IF_H_
+#define _LIBAST_MAP_IF_H_
+
+/*
+ * interface goop
+ */
+
+/* Standard typecast macros.... */
+#define SPIF_MAP(o) (SPIF_CAST(map) (o))
+#define SPIF_MAP_CLASS(o) (SPIF_CAST(mapclass) SPIF_OBJ_CLASS(o))
+
+/* Name of class variable associated with map interface */
+#define SPIF_MAPCLASS_VAR(type) spif_ ## type ## _mapclass
+
+/* Check if a map is NULL */
+#define SPIF_MAP_ISNULL(o) (SPIF_MAP(o) == SPIF_NULL_TYPE(map))
+
+/* Check if an object is a map */
+#define SPIF_OBJ_IS_MAP(o) SPIF_OBJ_IS_TYPE(o, map)
+
+/* Call a method on an instance of an implementation class */
+#define SPIF_MAP_CALL_METHOD(o, meth) SPIF_MAP_CLASS(o)->meth
+
+/* Calls to the basic functions. */
+#define SPIF_MAP_NEW(type) SPIF_MAP((SPIF_CLASS(SPIF_MAPCLASS_VAR(type)))->noo())
+#define SPIF_MAP_INIT(o) SPIF_OBJ_INIT(o)
+#define SPIF_MAP_DONE(o) SPIF_OBJ_DONE(o)
+#define SPIF_MAP_DEL(o) SPIF_OBJ_DEL(o)
+#define SPIF_MAP_SHOW(o, b, i) SPIF_OBJ_SHOW(o, b, i)
+#define SPIF_MAP_COMP(o1, o2) SPIF_OBJ_COMP(o1, o2)
+#define SPIF_MAP_DUP(o) SPIF_OBJ_DUP(o)
+#define SPIF_MAP_TYPE(o) SPIF_OBJ_TYPE(o)
+
+#define SPIF_MAP_COUNT(o) SPIF_CAST_C(size_t) ((SPIF_MAP_CALL_METHOD((o), count))(o))
+#define SPIF_MAP_GET(o, key) SPIF_CAST(obj) ((SPIF_MAP_CALL_METHOD((o), get))(o, key))
+#define SPIF_MAP_GET_KEYS(o) SPIF_CAST(list) ((SPIF_MAP_CALL_METHOD((o), get_keys))(o))
+#define SPIF_MAP_GET_PAIRS(o) SPIF_CAST(list) ((SPIF_MAP_CALL_METHOD((o), get_pairs))(o))
+#define SPIF_MAP_GET_VALUES(o) SPIF_CAST(list) ((SPIF_MAP_CALL_METHOD((o), get_values))(o))
+#define SPIF_MAP_HAS_KEY(o, key) SPIF_CAST(bool) ((SPIF_MAP_CALL_METHOD((o), has_key))(o, key))
+#define SPIF_MAP_HAS_VALUE(o, value) SPIF_CAST(bool) ((SPIF_MAP_CALL_METHOD((o), hash_value))(o, value))
+#define SPIF_MAP_ITERATOR(o) SPIF_CAST(iterator) ((SPIF_MAP_CALL_METHOD((o), iterator))(o))
+#define SPIF_MAP_REMOVE(o, item) SPIF_CAST(obj) ((SPIF_MAP_CALL_METHOD((o), remove))(o, item))
+#define SPIF_MAP_SET(o, key, value) SPIF_CAST(bool) ((SPIF_MAP_CALL_METHOD((o), set))(o, key, value))
+
+typedef spif_obj_t spif_map_t;
+
+SPIF_DECL_OBJ(mapclass) {
+ SPIF_DECL_PARENT_TYPE(class);
+
+ spif_func_t count;
+ spif_func_t get;
+ spif_func_t get_keys;
+ spif_func_t get_pairs;
+ spif_func_t get_values;
+ spif_func_t has_key;
+ spif_func_t has_value;
+ spif_func_t iterator;
+ spif_func_t remove;
+ spif_func_t set;
+};
+
+#endif /* _LIBAST_MAP_IF_H_ */
diff --git a/include/libast/objpair.h b/include/libast/objpair.h
new file mode 100644
index 0000000..96960af
--- /dev/null
+++ b/include/libast/objpair.h
@@ -0,0 +1,234 @@
+/*
+ * Copyright (C) 1997-2004, Michael Jennings
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies of the Software, its documentation and marketing & publicity
+ * materials, and acknowledgment shall be given in the documentation, materials
+ * and software packages that this Software was used.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _LIBAST_OBJPAIR_H_
+#define _LIBAST_OBJPAIR_H_
+
+
+/**
+ * @file objpair.h
+ * LibAST Object Infrastructure -- Paired Objects
+ *
+ * This file contains the declarations for the paired object type.
+ *
+ * @author Michael Jennings <mej@eterm.org>
+ * $Revision$
+ * $Date$
+ */
+
+/*@{*/
+/**
+ * @name Paired Object Macros
+ * ---
+ *
+ * This set of macros
+ *
+ * @ingroup DOXGRP_OBJPAIR
+ */
+
+/**
+ * Cast an arbitrary object to an objpair.
+ *
+ * This macro allows an arbitrary object of any valid object type
+ * (i.e., anything derived from spif_objpair_t) to be treated as a generic
+ * objpair (the spif_objpair_t type).
+ *
+ * @param o An objpair, or a descendent thereof.
+ * @return An objpair reference to that object.
+ *
+ * @see @link DOXGRP_OBJPAIR Paired Objects @endlink, SPIF_CAST()
+ */
+#define SPIF_OBJPAIR(o) (SPIF_CAST(objpair) (o))
+
+/**
+ * Determine if an arbitrary object is of type "objpair."
+ *
+ * This macro returns a boolean value based on whether or not the
+ * object passed to it is of type "objpair."
+ *
+ * @param o The object to test.
+ * @return Whether or not the object is of type "objpair."
+ *
+ * @see @link DOXGRP_OBJPAIR Paired Objects @endlink, SPIF_OBJ_IS_TYPE()
+ */
+#define SPIF_OBJ_IS_OBJPAIR(o) (SPIF_OBJ_IS_TYPE(o, objpair))
+
+/**
+ * Determine if an object of type "objpair" is NULL.
+ *
+ * This macro returns a boolean value based on whether or not the
+ * object passed to it is NULL. The object is cast to type "objpair"
+ * before the comparison, so it should work for any valid object.
+ * This macro will not often be used by user code. However, each
+ * object type needs to define a macro like this named
+ * SPIF_xxx_ISNULL() (where xxx is the object type), so this macro
+ * serves as a template for how those should be written.
+ *
+ * @param o The object to test.
+ * @return Whether or not the object is NULL.
+ *
+ * @see @link DOXGRP_OBJPAIR Paired Objects @endlink, SPIF_OBJPAIR(), SPIF_NULL_TYPE()
+ */
+#define SPIF_OBJPAIR_ISNULL(o) (SPIF_OBJPAIR(o) == SPIF_NULL_TYPE(objpair))
+
+/**
+ * Create an instance of a objpair.
+ *
+ * This macro allocates and returns an object of type "objpair."
+ *
+ * @return An allocated object of type "objpair."
+ *
+ * @see @link DOXGRP_OBJPAIR Paired Objects @endlink, spif_objpair_new()
+ */
+#define SPIF_OBJPAIR_NEW() SPIF_CAST(objpair) (SPIF_CLASS(SPIF_CLASS_VAR(objpair)))->(noo)()
+
+/**
+ * Initialize an objpair.
+ *
+ * This macro calls the @c init method of an objpair in order to
+ * initialize it.
+ *
+ * @param o An already-allocated objpair.
+ * @return #TRUE if successful, #FALSE otherwise.
+ *
+ * @see @link DOXGRP_OBJPAIR Paired Objects @endlink, spif_objpair_init()
+ */
+#define SPIF_OBJPAIR_INIT(o) SPIF_CAST(bool) (SPIF_OBJPAIR_CALL_METHOD((o), init)(o))
+
+/**
+ * Clean up an objpair.
+ *
+ * This macro calls the @c done method of an objpair. This basically
+ * restores it to its original allocated-and-initialized state.
+ *
+ * @param o An objpair.
+ * @return #TRUE if successful, #FALSE otherwise.
+ *
+ * @see @link DOXGRP_OBJPAIR Paired Objects @endlink, spif_objpair_done()
+ */
+#define SPIF_OBJPAIR_DONE(o) SPIF_CAST(bool) (SPIF_OBJPAIR_CALL_METHOD((o), done)(o))
+
+/**
+ * Delete an objpair.
+ *
+ * This macro calls the @c del method of an objpair, destroying it and
+ * freeing its memory.
+ *
+ * @param o An objpair. It will cease to exist after this call.
+ * @return #TRUE if successful, #FALSE otherwise.
+ *
+ * @see @link DOXGRP_OBJPAIR Paired Objects @endlink, spif_objpair_del()
+ */
+#define SPIF_OBJPAIR_DEL(o) SPIF_CAST(bool) (SPIF_OBJPAIR_CALL_METHOD((o), del)(o))
+
+/**
+ * Convert the contents of an objpair to a string.
+ *
+ * This macro calls the @c show method of an objpair, returning a
+ * spif_str_t object containing its string representation.
+ *
+ * @param o The objpair to display.
+ * @param b An existing spif_str_t buffer to use. If NULL, a new str
+ * object will be created and returned.
+ * @param i Number of leading spaces to indent.
+ * @return A str object containing the string representation of @a o.
+ *
+ * @see @link DOXGRP_OBJPAIR Paired Objects @endlink, spif_objpair_show(), SPIF_SHOW()
+ */
+#define SPIF_OBJPAIR_SHOW(o, b, i) SPIF_CAST(str) (SPIF_OBJPAIR_CALL_METHOD((o), show)(o, #o, b, i))
+
+/**
+ * Compare two objpairs.
+ *
+ * This macro calls the @c comp method of objpair #1 to compare the two
+ * objpairs.
+ *
+ * @param o1 Objpair #1.
+ * @param o2 Objpair #2.
+ * @return A spif_cmp_t value containing the comparison result.
+ *
+ * @see @link DOXGRP_OBJPAIR Paired Objects @endlink, spif_objpair_comp(), spif_comp_t
+ */
+#define SPIF_OBJPAIR_COMP(o1, o2) SPIF_CAST(cmp) (SPIF_OBJPAIR_CALL_METHOD((o1), comp)(o1, o2))
+
+/**
+ * Duplicate an objpair.
+ *
+ * This macro calls the @c dup method of an objpair. A copy of the
+ * objpair is returned.
+ *
+ * @param o An objpair.
+ * @return A duplicate of that objpair.
+ *
+ * @see @link DOXGRP_OBJPAIR Paired Objects @endlink, spif_objpair_dup()
+ */
+#define SPIF_OBJPAIR_DUP(o) SPIF_CAST(objpair) (SPIF_OBJPAIR_CALL_METHOD((o), dup)(o))
+
+/**
+ * Obtain the type of the objpair.
+ *
+ * This macro calls the @c type method of an objpair to obtain its
+ * classname.
+ *
+ * @param o An objpair.
+ * @return The classname of that objpair.
+ *
+ * @see @link DOXGRP_OBJPAIR Paired Objects @endlink, spif_objpair_type(), SPIF_OBJPAIR_CLASSNAME()
+ */
+#define SPIF_OBJPAIR_TYPE(o) SPIF_CAST(classname) (SPIF_OBJPAIR_CALL_METHOD((o), type)(o))
+
+
+/**
+ * Objpair structure.
+ *
+ * This class contains the objpair structure. It contains the
+ * parent type (obj) and all member variables.
+ *
+ * @note Doxygen doesn't understand how to handle the macro-based
+ * class definition for this structure, so it thinks it's a function.
+ * It's actually a struct definition (spif_const_objpair_t) and a
+ * pointer definition (spif_objpair_t) as provided by the
+ * SPIF_DECL_OBJ() macro.
+ *
+ * @see @link DOXGRP_OBJPAIR Paired Objects @endlink, SPIF_OBJPAIR_CALL_METHOD()
+ */
+SPIF_DECL_OBJ(objpair) {
+ SPIF_DECL_PARENT_TYPE(obj);
+ SPIF_DECL_PROPERTY(obj, left);
+ SPIF_DECL_PROPERTY(obj, right);
+};
+/*@}*/
+
+extern spif_class_t SPIF_CLASS_VAR(objpair);
+extern spif_objpair_t spif_objpair_new(void);
+extern spif_bool_t spif_objpair_del(spif_objpair_t);
+extern spif_bool_t spif_objpair_init(spif_objpair_t);
+extern spif_bool_t spif_objpair_done(spif_objpair_t);
+extern spif_str_t spif_objpair_show(spif_objpair_t, spif_charptr_t, spif_str_t, size_t);
+extern spif_cmp_t spif_objpair_comp(spif_objpair_t, spif_objpair_t);
+extern spif_objpair_t spif_objpair_dup(spif_objpair_t);
+extern spif_classname_t spif_objpair_type(spif_objpair_t);
+SPIF_DECL_PROPERTY_FUNC(objpair, obj, left);
+SPIF_DECL_PROPERTY_FUNC(objpair, obj, right);
+
+#endif /* _LIBAST_OBJPAIR_H_ */