// generated from rosidl_generator_c/resource/idl__functions.c.em
// with input from aruco_interfaces:msg/ArucoMarkerPose.idl
// generated code does not contain a copyright notice
#include "aruco_interfaces/msg/detail/aruco_marker_pose__functions.h"

#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>


// Include directives for member types
// Member `marker_ids`
#include "rosidl_runtime_c/primitives_sequence_functions.h"
// Member `poses`
#include "geometry_msgs/msg/detail/pose__functions.h"

bool
aruco_interfaces__msg__ArucoMarkerPose__init(aruco_interfaces__msg__ArucoMarkerPose * msg)
{
  if (!msg) {
    return false;
  }
  // marker_ids
  if (!rosidl_runtime_c__int64__Sequence__init(&msg->marker_ids, 0)) {
    aruco_interfaces__msg__ArucoMarkerPose__fini(msg);
    return false;
  }
  // poses
  if (!geometry_msgs__msg__Pose__Sequence__init(&msg->poses, 0)) {
    aruco_interfaces__msg__ArucoMarkerPose__fini(msg);
    return false;
  }
  return true;
}

void
aruco_interfaces__msg__ArucoMarkerPose__fini(aruco_interfaces__msg__ArucoMarkerPose * msg)
{
  if (!msg) {
    return;
  }
  // marker_ids
  rosidl_runtime_c__int64__Sequence__fini(&msg->marker_ids);
  // poses
  geometry_msgs__msg__Pose__Sequence__fini(&msg->poses);
}

aruco_interfaces__msg__ArucoMarkerPose *
aruco_interfaces__msg__ArucoMarkerPose__create()
{
  aruco_interfaces__msg__ArucoMarkerPose * msg = (aruco_interfaces__msg__ArucoMarkerPose *)malloc(sizeof(aruco_interfaces__msg__ArucoMarkerPose));
  if (!msg) {
    return NULL;
  }
  memset(msg, 0, sizeof(aruco_interfaces__msg__ArucoMarkerPose));
  bool success = aruco_interfaces__msg__ArucoMarkerPose__init(msg);
  if (!success) {
    free(msg);
    return NULL;
  }
  return msg;
}

void
aruco_interfaces__msg__ArucoMarkerPose__destroy(aruco_interfaces__msg__ArucoMarkerPose * msg)
{
  if (msg) {
    aruco_interfaces__msg__ArucoMarkerPose__fini(msg);
  }
  free(msg);
}


bool
aruco_interfaces__msg__ArucoMarkerPose__Sequence__init(aruco_interfaces__msg__ArucoMarkerPose__Sequence * array, size_t size)
{
  if (!array) {
    return false;
  }
  aruco_interfaces__msg__ArucoMarkerPose * data = NULL;
  if (size) {
    data = (aruco_interfaces__msg__ArucoMarkerPose *)calloc(size, sizeof(aruco_interfaces__msg__ArucoMarkerPose));
    if (!data) {
      return false;
    }
    // initialize all array elements
    size_t i;
    for (i = 0; i < size; ++i) {
      bool success = aruco_interfaces__msg__ArucoMarkerPose__init(&data[i]);
      if (!success) {
        break;
      }
    }
    if (i < size) {
      // if initialization failed finalize the already initialized array elements
      for (; i > 0; --i) {
        aruco_interfaces__msg__ArucoMarkerPose__fini(&data[i - 1]);
      }
      free(data);
      return false;
    }
  }
  array->data = data;
  array->size = size;
  array->capacity = size;
  return true;
}

void
aruco_interfaces__msg__ArucoMarkerPose__Sequence__fini(aruco_interfaces__msg__ArucoMarkerPose__Sequence * array)
{
  if (!array) {
    return;
  }
  if (array->data) {
    // ensure that data and capacity values are consistent
    assert(array->capacity > 0);
    // finalize all array elements
    for (size_t i = 0; i < array->capacity; ++i) {
      aruco_interfaces__msg__ArucoMarkerPose__fini(&array->data[i]);
    }
    free(array->data);
    array->data = NULL;
    array->size = 0;
    array->capacity = 0;
  } else {
    // ensure that data, size, and capacity values are consistent
    assert(0 == array->size);
    assert(0 == array->capacity);
  }
}

aruco_interfaces__msg__ArucoMarkerPose__Sequence *
aruco_interfaces__msg__ArucoMarkerPose__Sequence__create(size_t size)
{
  aruco_interfaces__msg__ArucoMarkerPose__Sequence * array = (aruco_interfaces__msg__ArucoMarkerPose__Sequence *)malloc(sizeof(aruco_interfaces__msg__ArucoMarkerPose__Sequence));
  if (!array) {
    return NULL;
  }
  bool success = aruco_interfaces__msg__ArucoMarkerPose__Sequence__init(array, size);
  if (!success) {
    free(array);
    return NULL;
  }
  return array;
}

void
aruco_interfaces__msg__ArucoMarkerPose__Sequence__destroy(aruco_interfaces__msg__ArucoMarkerPose__Sequence * array)
{
  if (array) {
    aruco_interfaces__msg__ArucoMarkerPose__Sequence__fini(array);
  }
  free(array);
}
