From 276602723076553538821464b03b5ac515e5e3b5 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 25 Apr 2008 11:04:38 +0200 Subject: [PATCH] sn_network.[ch]: Add the sn_network_clone method. --- src/sn_network.c | 32 ++++++++++++++++++++++++++++++++ src/sn_network.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/sn_network.c b/src/sn_network.c index 3a37bb2..da87f37 100644 --- a/src/sn_network.c +++ b/src/sn_network.c @@ -94,6 +94,38 @@ int sn_network_stage_remove (sn_network_t *n, int s_num) return (0); } /* int sn_network_stage_remove */ +sn_network_t *sn_network_clone (const sn_network_t *n) +{ + sn_network_t *n_copy; + int i; + + n_copy = sn_network_create (n->inputs_num); + if (n_copy == NULL) + return (NULL); + + for (i = 0; i < n->stages_num; i++) + { + sn_stage_t *s; + int status; + + s = sn_stage_clone (n->stages[i]); + if (s == NULL) + break; + + status = sn_network_stage_add (n_copy, s); + if (status != 0) + break; + } + + if (i < n->stages_num) + { + sn_network_destroy (n_copy); + return (NULL); + } + + return (n_copy); +} /* sn_network_t *sn_network_clone */ + int sn_network_show (sn_network_t *n) { int i; diff --git a/src/sn_network.h b/src/sn_network.h index 2033786..8737f6e 100644 --- a/src/sn_network.h +++ b/src/sn_network.h @@ -19,6 +19,7 @@ typedef struct sn_network_s sn_network_t; #define SN_NETWORK_INPUT_NUM(n) (n)->inputs_num sn_network_t *sn_network_create (int inputs_num); +sn_network_t *sn_network_clone (const sn_network_t *n); void sn_network_destroy (sn_network_t *n); int sn_network_stage_add (sn_network_t *n, sn_stage_t *s); -- 2.11.0