ucx/ucx.h

changeset 5
88625853ae74
parent 1
1bcaac272cdf
child 39
3e55bed345f9
--- a/ucx/ucx.h	Sat Dec 01 20:34:55 2012 +0100
+++ b/ucx/ucx.h	Mon Aug 12 14:40:19 2013 +0200
@@ -1,8 +1,36 @@
-/* 
- * File:   ucx.h
- * Author: olaf
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2013 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
  *
- * Created on 31. Dezember 2011, 17:17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+/**
+ * Main UCX Header providing most common definitions.
+ * 
+ * @file   ucx.h
+ * @author Mike Becker
+ * @author Olaf Wintermann
  */
 
 #ifndef UCX_H
@@ -10,37 +38,77 @@
 
 #include <stdlib.h>
 
+#ifdef _WIN32
+#if !(defined __ssize_t_defined || defined _SSIZE_T_)
+#include <BaseTsd.h>
+typedef SSIZE_T ssize_t;
+#define __ssize_t_defined
+#define _SSIZE_T_
+#endif /* __ssize_t_defined and _SSIZE_T */
+#else /* !_WIN32 */
+#include <sys/types.h>
+#endif /* _WIN32 */
+
 #ifdef	__cplusplus
 #ifndef _Bool
 #define _Bool bool
 #define restrict
 #endif
+#define UCX_EXTERN extern "C"
 extern "C" {
+#else
+#define UCX_EXTERN
 #endif
 
-#define UCX_FOREACH(type,list,elem) \
-        for (type elem = list ; elem != NULL ; elem = elem->next)
-
-#ifdef __cplusplus
-#define ucx_dynarray_new(type,identifier,length)\
-    type* identifier; identifier = new type[length]
-#define ucx_dynarray_free(identifier) delete [] identifier
-#else
-#define ucx_dynarray_new(type,identifier,length)\
-    type identifier[length]
-#define ucx_dynarray_free(identifier)
-#endif
-    
-/* element1,element2,custom data -> {-1,0,1} */
+/**
+ * Function pointer to a compare function.
+ * 
+ * The compare function shall take three arguments: the two values that shall be
+ * compared and optional additional data.
+ * The function shall then return -1 if the first argument is less than the
+ * second argument, 1 if the first argument is greater than the second argument
+ * and 0 if both arguments are equal. If the third argument is
+ * <code>NULL</code>, it shall be ignored.
+ */
 typedef int(*cmp_func)(void*,void*,void*);
 
-/* element,custom data -> copy of element */
+/**
+ * Function pointer to a copy function.
+ * 
+ * The copy function shall create a copy of the first argument and may use
+ * additional data provided by the second argument. If the second argument is
+ * <code>NULL</code>, it shall be ignored.
+
+ * <b>Attention:</b> if pointers returned by functions of this type may be
+ * passed to <code>free()</code> depends on the implementation of the
+ * respective <code>copy_func</code>.
+ */
 typedef void*(*copy_func)(void*,void*);
 
-/* buffer, element size, element count, stream */
+/**
+ * Function pointer to a write function.
+ * 
+ * The signature of the write function shall be compatible to the signature
+ * of standard <code>fwrite</code>, though it may use arbitrary data types for
+ * source and destination.
+ * 
+ * The arguments shall contain (in ascending order): a pointer to the source,
+ * the length of one element, the element count and a pointer to the
+ * destination.
+ */
 typedef size_t(*write_func)(const void*, size_t, size_t, void*);
 
-/* buffer, element size, element count, stream */
+/**
+ * Function pointer to a read function.
+ * 
+ * The signature of the read function shall be compatible to the signature
+ * of standard <code>fread</code>, though it may use arbitrary data types for
+ * source and destination.
+ * 
+ * The arguments shall contain (in ascending order): a pointer to the
+ * destination, the length of one element, the element count and a pointer to
+ * the source.
+ */
 typedef size_t(*read_func)(void*, size_t, size_t, void*);
 
 #ifdef	__cplusplus

mercurial