[Freeciv-Dev] (PR#4784) new function: specvec_copy
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
here's a new function: SPECVEC_FOO(_vector_copy)
It will be well used in the up-and-coming effects code.
-mike
Index: common/specvec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/specvec.h,v
retrieving revision 1.2
diff -u -r1.2 specvec.h
--- common/specvec.h 2002/03/05 10:07:10 1.2
+++ common/specvec.h 2003/08/07 23:00:21
@@ -31,6 +31,7 @@
void foo_vector_reserve(struct foo_vector *tthis, int n);
int foo_vector_size(struct foo_vector *tthis);
foo_t *foo_vector_get(struct foo_vector *tthis, int index);
+ void foo_vector_copy(struct foo_vector *to, struct foo_vector *from);
void foo_vector_free(struct foo_vector *tthis);
Also, in a single .c file, you should include specvec_c.h,
@@ -67,6 +68,7 @@
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);
#undef SPECVEC_TAG
Index: common/specvec_c.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/specvec_c.h,v
retrieving revision 1.3
diff -u -r1.3 specvec_c.h
--- common/specvec_c.h 2002/03/05 10:07:10 1.3
+++ common/specvec_c.h 2003/08/07 23:00:21
@@ -24,6 +24,8 @@
happens anyway, so this restriction may be considered beneficial.
*/
+#include <stdio.h>
+
#ifndef SPECVEC_TAG
#error Must define a SPECVEC_TAG to use this header
#endif
@@ -59,6 +61,21 @@
assert(index>=0 && index<tthis->vector.n);
return ((SPECVEC_TYPE *)ath_get(&tthis->vector, index));
+}
+
+/* You must _init "*to" before using this function */
+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));
+ }
}
void SPECVEC_FOO(_vector_free) (SPECVEC_VECTOR *tthis)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#4784) new function: specvec_copy,
Mike Kaufman <=
|
|