diff options
| author | J08nY | 2018-03-03 01:35:04 +0100 |
|---|---|---|
| committer | J08nY | 2018-03-28 17:25:02 +0200 |
| commit | 97149b9104569f70dc0eec47e2e0df4d8d05022d (patch) | |
| tree | ac144c92971491bec46c471fa8f68f09ad5bb64e /src/obj | |
| parent | 72f2a5d4fb0aaa054fb73e30944c10a41c830727 (diff) | |
| download | ecgen-97149b9104569f70dc0eec47e2e0df4d8d05022d.tar.gz ecgen-97149b9104569f70dc0eec47e2e0df4d8d05022d.tar.zst ecgen-97149b9104569f70dc0eec47e2e0df4d8d05022d.zip | |
Separate point object functions into obj.
Diffstat (limited to 'src/obj')
| -rw-r--r-- | src/obj/point.c | 90 | ||||
| -rw-r--r-- | src/obj/point.h | 103 |
2 files changed, 193 insertions, 0 deletions
diff --git a/src/obj/point.c b/src/obj/point.c new file mode 100644 index 0000000..9c9b37d --- /dev/null +++ b/src/obj/point.c @@ -0,0 +1,90 @@ + +#include "point.h" +#include "misc/types.h" +#include "util/memory.h" + +point_t *point_new(void) { return try_calloc(sizeof(point_t)); } + +point_t *point_copy(const point_t *src, point_t *dest) { + if (src->point) dest->point = gcopy(src->point); + if (src->order) dest->order = gcopy(src->order); + if (src->cofactor) dest->cofactor = gcopy(src->cofactor); + return dest; +} + +point_t *point_new_copy(const point_t *src) { + point_t *result = point_new(); + return point_copy(src, result); +} + +point_t *point_clone(const point_t *src, point_t *dest) { + if (src->point) dest->point = gclone(src->point); + if (src->order) dest->order = gclone(src->order); + if (src->cofactor) dest->cofactor = gclone(src->cofactor); + return dest; +} + +point_t *point_new_clone(const point_t *src) { + point_t *result = point_new(); + return point_clone(src, result); +} + +void point_free(point_t **point) { + if (*point) { + if ((*point)->point && isclone((*point)->point)) { + gunclone((*point)->point); + } + if ((*point)->order && isclone((*point)->order)) { + gunclone((*point)->order); + } + if ((*point)->cofactor && isclone((*point)->cofactor)) { + gunclone((*point)->cofactor); + } + try_free(*point); + *point = NULL; + } +} + +point_t **points_new(unsigned long num) { + return try_calloc(num * sizeof(point_t *)); +} + +point_t **points_copy(point_t **const src, point_t **dest, unsigned long num) { + for (unsigned long i = 0; i < num; ++i) { + dest[i] = point_new_copy(src[i]); + } + return dest; +} + +point_t **points_new_copy(point_t **const src, unsigned long num) { + point_t **result = points_new(num); + return points_copy(src, result, num); +} + +point_t **points_clone(point_t **const src, point_t **dest, unsigned long num) { + for (unsigned long i = 0; i < num; ++i) { + dest[i] = point_new_clone(src[i]); + } + return dest; +} + +point_t **points_new_clone(point_t **const src, unsigned long num) { + point_t **result = points_new(num); + return points_clone(src, result, num); +} + +void points_free(point_t ***points) { + if (*points) { + try_free(*points); + *points = NULL; + } +} + +void points_free_deep(point_t ***points, unsigned long npoints) { + if (*points) { + for (unsigned long i = 0; i < npoints; ++i) { + point_free(&(*points)[i]); + } + points_free(points); + } +}
\ No newline at end of file diff --git a/src/obj/point.h b/src/obj/point.h new file mode 100644 index 0000000..d6aa55e --- /dev/null +++ b/src/obj/point.h @@ -0,0 +1,103 @@ + +#ifndef ECGEN_OBJ_POINT_H +#define ECGEN_OBJ_POINT_H + +#include "misc/types.h" + +/** + * + * @return + */ +point_t *point_new(void); + +/** + * + * @param src + * @param dest + * @return + */ +point_t *point_copy(const point_t *src, point_t *dest); + +/** + * + * @param src + * @return + */ +point_t *point_new_copy(const point_t *src); + +/** + * + * @param src + * @param dest + * @return + */ +point_t *point_clone(const point_t *src, point_t *dest); + +/** + * + * @param src + * @return + */ +point_t *point_new_clone(const point_t *src); + +/** + * + * @param point + */ +void point_free(point_t **point); + +/** + * + * @param num + * @return + */ +point_t **points_new(unsigned long num); + +/** + * + * @param src + * @param dest + * @param num + * @return + */ +point_t **points_copy(point_t **src, point_t **dest, unsigned long num); + +/** + * + * @param src + * @param num + * @return + */ +point_t **points_new_copy(point_t **src, unsigned long num); + +/** + * + * @param src + * @param dest + * @param num + * @return + */ +point_t **points_clone(point_t **src, point_t **dest, unsigned long num); + +/** + * + * @param src + * @param num + * @return + */ +point_t **points_new_clone(point_t **src, unsigned long num); + +/** + * + * @param point + */ +void points_free(point_t ***point); + +/** + * + * @param points + * @param npoints + */ +void points_free_deep(point_t ***points, unsigned long npoints); + +#endif // ECGEN_OBJ_POINT_H |
