aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-06-26 17:10:29 +0200
committerThomas White <taw@physics.org>2020-07-29 18:53:44 +0200
commit21acbb9efcbc5158f62e43d025db1ca7b2369fb8 (patch)
tree0c2d06975ff0b55b66fdf776fc02a6ef1970193f
parent9509c5e2ae310e80d880104bfb57fc887878ccbc (diff)
Add crystal_copy_deep()
-rw-r--r--libcrystfel/src/crystal.c41
-rw-r--r--libcrystfel/src/crystal.h1
2 files changed, 41 insertions, 1 deletions
diff --git a/libcrystfel/src/crystal.c b/libcrystfel/src/crystal.c
index 9202c668..bec3a890 100644
--- a/libcrystfel/src/crystal.c
+++ b/libcrystfel/src/crystal.c
@@ -7,7 +7,7 @@
* a research centre of the Helmholtz Association.
*
* Authors:
- * 2013-2016 Thomas White <taw@physics.org>
+ * 2013-2020 Thomas White <taw@physics.org>
* 2016 Valerio Mariani
*
* This file is part of CrystFEL.
@@ -33,6 +33,7 @@
#include "crystal.h"
#include "utils.h"
+#include "reflist-utils.h"
/**
@@ -127,6 +128,44 @@ Crystal *crystal_copy(const Crystal *cryst)
/**
+ * \param cryst: A \ref Crystal to copy.
+ *
+ * Creates a new \ref Crystal which is a copy of \p cryst. The copy is a "deep
+ * copy", which means that copies ARE made of the data structures which
+ * \p cryst contains references to, for example its \ref RefList.
+ *
+ * \returns A (deep) copy of \p cryst, or NULL on failure.
+ *
+ */
+Crystal *crystal_copy_deep(const Crystal *cryst)
+{
+ Crystal *c;
+
+ c = crystal_new();
+ if ( c == NULL ) return NULL;
+
+ memcpy(c, cryst, sizeof(Crystal));
+ if ( c->notes != NULL ) c->notes = strdup(c->notes);
+
+ if ( cryst->cell != NULL ) {
+ UnitCell *cell;
+ cell = cell_new_from_cell(cryst->cell);
+ if ( cell == NULL ) return NULL;
+ c->cell = cell;
+ }
+
+ if ( cryst->reflections != NULL ) {
+ RefList *refls;
+ refls = copy_reflist(cryst->reflections);
+ if ( refls == NULL ) return NULL;
+ c->reflections = refls;
+ }
+
+ return c;
+}
+
+
+/**
* \param cryst: A \ref Crystal to free.
*
* Frees a \ref Crystal, and all internal resources concerning that crystal.
diff --git a/libcrystfel/src/crystal.h b/libcrystfel/src/crystal.h
index 669c173f..592a4b43 100644
--- a/libcrystfel/src/crystal.h
+++ b/libcrystfel/src/crystal.h
@@ -56,6 +56,7 @@ extern "C" {
extern Crystal *crystal_new(void);
extern Crystal *crystal_copy(const Crystal *cryst);
+extern Crystal *crystal_copy_deep(const Crystal *cryst);
extern void crystal_free(Crystal *cryst);
extern UnitCell *crystal_get_cell(Crystal *cryst);