[Freeciv-Dev] Re: (PR#8683) remove specvec?
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8683 >
On Wed, 5 May 2004, Mike Kaufman wrote:
> > Can we remove it?
>
> No. gen-effects makes extensive use of specvec.
Here is a quick patch to make it inline, like speclists. Not tested, since
my gen eff tree choked on some recent commit.
- Per
Index: utility/specvec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/specvec.h,v
retrieving revision 1.3
diff -u -r1.3 specvec.h
--- utility/specvec.h 8 Aug 2003 03:13:02 -0000 1.3
+++ utility/specvec.h 6 May 2004 19:55:20 -0000
@@ -44,6 +44,8 @@
which _is_ itself protected against multiple inclusions.
*/
+#include <string.h> /* for memcpy */
+
#include "astring.h"
#ifndef SPECVEC_TAG
@@ -64,12 +66,62 @@
struct athing vector;
};
-void SPECVEC_FOO(_vector_init) (SPECVEC_VECTOR *tthis);
-void SPECVEC_FOO(_vector_reserve) (SPECVEC_VECTOR *tthis, int n);
-size_t SPECVEC_FOO(_vector_size) (SPECVEC_VECTOR *tthis);
-SPECVEC_TYPE *SPECVEC_FOO(_vector_get) (SPECVEC_VECTOR *tthis, int index);
-void SPECVEC_FOO(_vector_copy) (SPECVEC_VECTOR *to, SPECVEC_VECTOR *from);
-void SPECVEC_FOO(_vector_free) (SPECVEC_VECTOR *tthis);
+#ifndef SPECVEC_TAG
+#error Must define a SPECVEC_TAG to use this header
+#endif
+
+#ifndef SPECVEC_TYPE
+#define SPECVEC_TYPE struct SPECVEC_TAG
+#endif
+
+#define SPECVEC_PASTE_(x,y) x ## y
+#define SPECVEC_PASTE(x,y) SPECVEC_PASTE_(x,y)
+
+#define SPECVEC_VECTOR struct SPECVEC_PASTE(SPECVEC_TAG, _vector)
+
+#define SPECVEC_FOO(suffix) SPECVEC_PASTE(SPECVEC_TAG, suffix)
+
+static inline void SPECVEC_FOO(_vector_init) (SPECVEC_VECTOR *tthis)
+{
+ ath_init(&tthis->vector, sizeof(SPECVEC_TYPE));
+}
+
+static inline void SPECVEC_FOO(_vector_reserve) (SPECVEC_VECTOR *tthis, int n)
+{
+ ath_minnum(&tthis->vector, n);
+}
+
+static inline size_t SPECVEC_FOO(_vector_size) (SPECVEC_VECTOR *tthis)
+{
+ return tthis->vector.n;
+}
+
+static inline SPECVEC_TYPE *SPECVEC_FOO(_vector_get) (SPECVEC_VECTOR *tthis,
int index)
+{
+ assert(index>=0 && index<tthis->vector.n);
+
+ return ((SPECVEC_TYPE *)ath_get(&tthis->vector, index));
+}
+
+/* You must _init "*to" before using this function */
+static inline void SPECVEC_FOO(_vector_copy) (SPECVEC_VECTOR *to,
SPECVEC_VECTOR *from)
+{
+ int i;
+ size_t size = SPECVEC_FOO(_vector_size) (from);
+
+ SPECVEC_FOO(_vector_reserve) (to, size);
+
+ for (i = 0; i < size; i++) {
+ memcpy(SPECVEC_FOO(_vector_get) (to, i),
+ SPECVEC_FOO(_vector_get) (from, i),
+ sizeof(SPECVEC_TYPE));
+ }
+}
+
+static inline void SPECVEC_FOO(_vector_free) (SPECVEC_VECTOR *tthis)
+{
+ ath_free(&tthis->vector);
+}
#undef SPECVEC_TAG
#undef SPECVEC_TYPE
- [Freeciv-Dev] Re: (PR#8683) remove specvec?, Jason Short, 2004/05/05
- [Freeciv-Dev] Re: (PR#8683) remove specvec?, Mike Kaufman, 2004/05/05
- [Freeciv-Dev] Re: (PR#8683) remove specvec?, Jason Short, 2004/05/05
- [Freeciv-Dev] Re: (PR#8683) remove specvec?, Vasco Alexandre da Silva Costa, 2004/05/05
- [Freeciv-Dev] Re: (PR#8683) remove specvec?, Vasco Alexandre da Silva Costa, 2004/05/05
- [Freeciv-Dev] Re: (PR#8683) remove specvec?,
Per Inge Mathisen <=
- [Freeciv-Dev] Re: (PR#8683) remove specvec?, Jason Short, 2004/05/06
- [Freeciv-Dev] Re: (PR#8683) remove specvec?, Jason Short, 2004/05/06
- [Freeciv-Dev] Re: (PR#8683) remove specvec?, Mike Kaufman, 2004/05/06
- [Freeciv-Dev] (PR#8683) rewrite specvec so it doesn't use athing, Jason Short, 2004/05/12
- [Freeciv-Dev] (PR#8683) specvec iterator patch, Vasco Alexandre da Silva Costa, 2004/05/14
- [Freeciv-Dev] (PR#8683) specvec iterator patch v2, Vasco Alexandre da Silva Costa, 2004/05/14
- [Freeciv-Dev] (PR#8683) specvec patch v3, Vasco Alexandre da Silva Costa, 2004/05/14
|
|