Added a set method for serialization callback functions.
authorFlorian Forster <octo@leeloo.home.verplant.org>
Fri, 11 Jul 2008 15:35:12 +0000 (17:35 +0200)
committerFlorian Forster <octo@leeloo.home.verplant.org>
Fri, 11 Jul 2008 15:35:12 +0000 (17:35 +0200)
src/libpopulation.c
src/population.h

index f5379a0..42d1cb1 100644 (file)
@@ -88,6 +88,10 @@ struct population_s
   pi_free_f free;
   pi_copy_f copy;
 
+  /* Optional serialization */
+  pi_serialize_f serialize;
+  pi_unserialize_f unserialize;
+
   individual_t fittest;
 
   individual_t *individuals;
@@ -212,6 +216,21 @@ int population_set_size (population_t *p, /* {{{ */
   return (0);
 } /* }}} */
 
+int population_set_serialization (population_t *p,
+    pi_serialize_f serialize, pi_unserialize_f unserialize) /* {{{ */
+{
+  if (p == NULL)
+    return (-1);
+
+  pthread_mutex_lock (&p->lock);
+
+  p->serialize = serialize;
+  p->unserialize = unserialize;
+
+  pthread_mutex_unlock (&p->lock);
+  return (0);
+} /* }}} int population_set_serialization */
+
 void *population_get_random (population_t *p) /* {{{ */
 {
   void *ret = NULL;
index 53cd5c8..a512b40 100644 (file)
@@ -12,8 +12,8 @@ typedef int   (*pi_rate_f) (const void *);
 typedef void *(*pi_copy_f) (const void *);
 typedef void  (*pi_free_f) (void *);
 
-typedef int   (*pi_serialize) (void *, char **, size_t *);
-typedef void *(*pi_unserialize) (char * size_t);
+typedef int   (*pi_serialize_f) (void *, char **, size_t *);
+typedef void *(*pi_unserialize_f) (char *, size_t);
 
 /*
  * (Opaque) data types
@@ -31,6 +31,8 @@ void population_destroy (population_t *p);
  * Object configuration
  */
 int population_set_size (population_t *p, size_t population_size);
+int population_set_serialization (population_t *p,
+    pi_serialize_f serialize, pi_unserialize_f unserialize);
 
 /*
  * Methods