// generated from rosidl_generator_c/resource/idl__functions.c.em
// with input from bcr_bot:srv/GetVisualTopics.idl
// generated code does not contain a copyright notice
#include "bcr_bot/srv/detail/get_visual_topics__functions.h"

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

#include "rcutils/allocator.h"

bool
bcr_bot__srv__GetVisualTopics_Request__init(bcr_bot__srv__GetVisualTopics_Request * msg)
{
  if (!msg) {
    return false;
  }
  // refresh
  return true;
}

void
bcr_bot__srv__GetVisualTopics_Request__fini(bcr_bot__srv__GetVisualTopics_Request * msg)
{
  if (!msg) {
    return;
  }
  // refresh
}

bool
bcr_bot__srv__GetVisualTopics_Request__are_equal(const bcr_bot__srv__GetVisualTopics_Request * lhs, const bcr_bot__srv__GetVisualTopics_Request * rhs)
{
  if (!lhs || !rhs) {
    return false;
  }
  // refresh
  if (lhs->refresh != rhs->refresh) {
    return false;
  }
  return true;
}

bool
bcr_bot__srv__GetVisualTopics_Request__copy(
  const bcr_bot__srv__GetVisualTopics_Request * input,
  bcr_bot__srv__GetVisualTopics_Request * output)
{
  if (!input || !output) {
    return false;
  }
  // refresh
  output->refresh = input->refresh;
  return true;
}

bcr_bot__srv__GetVisualTopics_Request *
bcr_bot__srv__GetVisualTopics_Request__create()
{
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  bcr_bot__srv__GetVisualTopics_Request * msg = (bcr_bot__srv__GetVisualTopics_Request *)allocator.allocate(sizeof(bcr_bot__srv__GetVisualTopics_Request), allocator.state);
  if (!msg) {
    return NULL;
  }
  memset(msg, 0, sizeof(bcr_bot__srv__GetVisualTopics_Request));
  bool success = bcr_bot__srv__GetVisualTopics_Request__init(msg);
  if (!success) {
    allocator.deallocate(msg, allocator.state);
    return NULL;
  }
  return msg;
}

void
bcr_bot__srv__GetVisualTopics_Request__destroy(bcr_bot__srv__GetVisualTopics_Request * msg)
{
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  if (msg) {
    bcr_bot__srv__GetVisualTopics_Request__fini(msg);
  }
  allocator.deallocate(msg, allocator.state);
}


bool
bcr_bot__srv__GetVisualTopics_Request__Sequence__init(bcr_bot__srv__GetVisualTopics_Request__Sequence * array, size_t size)
{
  if (!array) {
    return false;
  }
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  bcr_bot__srv__GetVisualTopics_Request * data = NULL;

  if (size) {
    data = (bcr_bot__srv__GetVisualTopics_Request *)allocator.zero_allocate(size, sizeof(bcr_bot__srv__GetVisualTopics_Request), allocator.state);
    if (!data) {
      return false;
    }
    // initialize all array elements
    size_t i;
    for (i = 0; i < size; ++i) {
      bool success = bcr_bot__srv__GetVisualTopics_Request__init(&data[i]);
      if (!success) {
        break;
      }
    }
    if (i < size) {
      // if initialization failed finalize the already initialized array elements
      for (; i > 0; --i) {
        bcr_bot__srv__GetVisualTopics_Request__fini(&data[i - 1]);
      }
      allocator.deallocate(data, allocator.state);
      return false;
    }
  }
  array->data = data;
  array->size = size;
  array->capacity = size;
  return true;
}

void
bcr_bot__srv__GetVisualTopics_Request__Sequence__fini(bcr_bot__srv__GetVisualTopics_Request__Sequence * array)
{
  if (!array) {
    return;
  }
  rcutils_allocator_t allocator = rcutils_get_default_allocator();

  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) {
      bcr_bot__srv__GetVisualTopics_Request__fini(&array->data[i]);
    }
    allocator.deallocate(array->data, allocator.state);
    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);
  }
}

bcr_bot__srv__GetVisualTopics_Request__Sequence *
bcr_bot__srv__GetVisualTopics_Request__Sequence__create(size_t size)
{
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  bcr_bot__srv__GetVisualTopics_Request__Sequence * array = (bcr_bot__srv__GetVisualTopics_Request__Sequence *)allocator.allocate(sizeof(bcr_bot__srv__GetVisualTopics_Request__Sequence), allocator.state);
  if (!array) {
    return NULL;
  }
  bool success = bcr_bot__srv__GetVisualTopics_Request__Sequence__init(array, size);
  if (!success) {
    allocator.deallocate(array, allocator.state);
    return NULL;
  }
  return array;
}

void
bcr_bot__srv__GetVisualTopics_Request__Sequence__destroy(bcr_bot__srv__GetVisualTopics_Request__Sequence * array)
{
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  if (array) {
    bcr_bot__srv__GetVisualTopics_Request__Sequence__fini(array);
  }
  allocator.deallocate(array, allocator.state);
}

bool
bcr_bot__srv__GetVisualTopics_Request__Sequence__are_equal(const bcr_bot__srv__GetVisualTopics_Request__Sequence * lhs, const bcr_bot__srv__GetVisualTopics_Request__Sequence * rhs)
{
  if (!lhs || !rhs) {
    return false;
  }
  if (lhs->size != rhs->size) {
    return false;
  }
  for (size_t i = 0; i < lhs->size; ++i) {
    if (!bcr_bot__srv__GetVisualTopics_Request__are_equal(&(lhs->data[i]), &(rhs->data[i]))) {
      return false;
    }
  }
  return true;
}

bool
bcr_bot__srv__GetVisualTopics_Request__Sequence__copy(
  const bcr_bot__srv__GetVisualTopics_Request__Sequence * input,
  bcr_bot__srv__GetVisualTopics_Request__Sequence * output)
{
  if (!input || !output) {
    return false;
  }
  if (output->capacity < input->size) {
    const size_t allocation_size =
      input->size * sizeof(bcr_bot__srv__GetVisualTopics_Request);
    rcutils_allocator_t allocator = rcutils_get_default_allocator();
    bcr_bot__srv__GetVisualTopics_Request * data =
      (bcr_bot__srv__GetVisualTopics_Request *)allocator.reallocate(
      output->data, allocation_size, allocator.state);
    if (!data) {
      return false;
    }
    // If reallocation succeeded, memory may or may not have been moved
    // to fulfill the allocation request, invalidating output->data.
    output->data = data;
    for (size_t i = output->capacity; i < input->size; ++i) {
      if (!bcr_bot__srv__GetVisualTopics_Request__init(&output->data[i])) {
        // If initialization of any new item fails, roll back
        // all previously initialized items. Existing items
        // in output are to be left unmodified.
        for (; i-- > output->capacity; ) {
          bcr_bot__srv__GetVisualTopics_Request__fini(&output->data[i]);
        }
        return false;
      }
    }
    output->capacity = input->size;
  }
  output->size = input->size;
  for (size_t i = 0; i < input->size; ++i) {
    if (!bcr_bot__srv__GetVisualTopics_Request__copy(
        &(input->data[i]), &(output->data[i])))
    {
      return false;
    }
  }
  return true;
}


// Include directives for member types
// Member `depth_image_topics`
// Member `rgb_image_topics`
// Member `camera_info_topics`
// Member `point_cloud_topics`
#include "rosidl_runtime_c/string_functions.h"

bool
bcr_bot__srv__GetVisualTopics_Response__init(bcr_bot__srv__GetVisualTopics_Response * msg)
{
  if (!msg) {
    return false;
  }
  // depth_image_topics
  if (!rosidl_runtime_c__String__Sequence__init(&msg->depth_image_topics, 0)) {
    bcr_bot__srv__GetVisualTopics_Response__fini(msg);
    return false;
  }
  // rgb_image_topics
  if (!rosidl_runtime_c__String__Sequence__init(&msg->rgb_image_topics, 0)) {
    bcr_bot__srv__GetVisualTopics_Response__fini(msg);
    return false;
  }
  // camera_info_topics
  if (!rosidl_runtime_c__String__Sequence__init(&msg->camera_info_topics, 0)) {
    bcr_bot__srv__GetVisualTopics_Response__fini(msg);
    return false;
  }
  // point_cloud_topics
  if (!rosidl_runtime_c__String__Sequence__init(&msg->point_cloud_topics, 0)) {
    bcr_bot__srv__GetVisualTopics_Response__fini(msg);
    return false;
  }
  return true;
}

void
bcr_bot__srv__GetVisualTopics_Response__fini(bcr_bot__srv__GetVisualTopics_Response * msg)
{
  if (!msg) {
    return;
  }
  // depth_image_topics
  rosidl_runtime_c__String__Sequence__fini(&msg->depth_image_topics);
  // rgb_image_topics
  rosidl_runtime_c__String__Sequence__fini(&msg->rgb_image_topics);
  // camera_info_topics
  rosidl_runtime_c__String__Sequence__fini(&msg->camera_info_topics);
  // point_cloud_topics
  rosidl_runtime_c__String__Sequence__fini(&msg->point_cloud_topics);
}

bool
bcr_bot__srv__GetVisualTopics_Response__are_equal(const bcr_bot__srv__GetVisualTopics_Response * lhs, const bcr_bot__srv__GetVisualTopics_Response * rhs)
{
  if (!lhs || !rhs) {
    return false;
  }
  // depth_image_topics
  if (!rosidl_runtime_c__String__Sequence__are_equal(
      &(lhs->depth_image_topics), &(rhs->depth_image_topics)))
  {
    return false;
  }
  // rgb_image_topics
  if (!rosidl_runtime_c__String__Sequence__are_equal(
      &(lhs->rgb_image_topics), &(rhs->rgb_image_topics)))
  {
    return false;
  }
  // camera_info_topics
  if (!rosidl_runtime_c__String__Sequence__are_equal(
      &(lhs->camera_info_topics), &(rhs->camera_info_topics)))
  {
    return false;
  }
  // point_cloud_topics
  if (!rosidl_runtime_c__String__Sequence__are_equal(
      &(lhs->point_cloud_topics), &(rhs->point_cloud_topics)))
  {
    return false;
  }
  return true;
}

bool
bcr_bot__srv__GetVisualTopics_Response__copy(
  const bcr_bot__srv__GetVisualTopics_Response * input,
  bcr_bot__srv__GetVisualTopics_Response * output)
{
  if (!input || !output) {
    return false;
  }
  // depth_image_topics
  if (!rosidl_runtime_c__String__Sequence__copy(
      &(input->depth_image_topics), &(output->depth_image_topics)))
  {
    return false;
  }
  // rgb_image_topics
  if (!rosidl_runtime_c__String__Sequence__copy(
      &(input->rgb_image_topics), &(output->rgb_image_topics)))
  {
    return false;
  }
  // camera_info_topics
  if (!rosidl_runtime_c__String__Sequence__copy(
      &(input->camera_info_topics), &(output->camera_info_topics)))
  {
    return false;
  }
  // point_cloud_topics
  if (!rosidl_runtime_c__String__Sequence__copy(
      &(input->point_cloud_topics), &(output->point_cloud_topics)))
  {
    return false;
  }
  return true;
}

bcr_bot__srv__GetVisualTopics_Response *
bcr_bot__srv__GetVisualTopics_Response__create()
{
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  bcr_bot__srv__GetVisualTopics_Response * msg = (bcr_bot__srv__GetVisualTopics_Response *)allocator.allocate(sizeof(bcr_bot__srv__GetVisualTopics_Response), allocator.state);
  if (!msg) {
    return NULL;
  }
  memset(msg, 0, sizeof(bcr_bot__srv__GetVisualTopics_Response));
  bool success = bcr_bot__srv__GetVisualTopics_Response__init(msg);
  if (!success) {
    allocator.deallocate(msg, allocator.state);
    return NULL;
  }
  return msg;
}

void
bcr_bot__srv__GetVisualTopics_Response__destroy(bcr_bot__srv__GetVisualTopics_Response * msg)
{
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  if (msg) {
    bcr_bot__srv__GetVisualTopics_Response__fini(msg);
  }
  allocator.deallocate(msg, allocator.state);
}


bool
bcr_bot__srv__GetVisualTopics_Response__Sequence__init(bcr_bot__srv__GetVisualTopics_Response__Sequence * array, size_t size)
{
  if (!array) {
    return false;
  }
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  bcr_bot__srv__GetVisualTopics_Response * data = NULL;

  if (size) {
    data = (bcr_bot__srv__GetVisualTopics_Response *)allocator.zero_allocate(size, sizeof(bcr_bot__srv__GetVisualTopics_Response), allocator.state);
    if (!data) {
      return false;
    }
    // initialize all array elements
    size_t i;
    for (i = 0; i < size; ++i) {
      bool success = bcr_bot__srv__GetVisualTopics_Response__init(&data[i]);
      if (!success) {
        break;
      }
    }
    if (i < size) {
      // if initialization failed finalize the already initialized array elements
      for (; i > 0; --i) {
        bcr_bot__srv__GetVisualTopics_Response__fini(&data[i - 1]);
      }
      allocator.deallocate(data, allocator.state);
      return false;
    }
  }
  array->data = data;
  array->size = size;
  array->capacity = size;
  return true;
}

void
bcr_bot__srv__GetVisualTopics_Response__Sequence__fini(bcr_bot__srv__GetVisualTopics_Response__Sequence * array)
{
  if (!array) {
    return;
  }
  rcutils_allocator_t allocator = rcutils_get_default_allocator();

  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) {
      bcr_bot__srv__GetVisualTopics_Response__fini(&array->data[i]);
    }
    allocator.deallocate(array->data, allocator.state);
    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);
  }
}

bcr_bot__srv__GetVisualTopics_Response__Sequence *
bcr_bot__srv__GetVisualTopics_Response__Sequence__create(size_t size)
{
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  bcr_bot__srv__GetVisualTopics_Response__Sequence * array = (bcr_bot__srv__GetVisualTopics_Response__Sequence *)allocator.allocate(sizeof(bcr_bot__srv__GetVisualTopics_Response__Sequence), allocator.state);
  if (!array) {
    return NULL;
  }
  bool success = bcr_bot__srv__GetVisualTopics_Response__Sequence__init(array, size);
  if (!success) {
    allocator.deallocate(array, allocator.state);
    return NULL;
  }
  return array;
}

void
bcr_bot__srv__GetVisualTopics_Response__Sequence__destroy(bcr_bot__srv__GetVisualTopics_Response__Sequence * array)
{
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  if (array) {
    bcr_bot__srv__GetVisualTopics_Response__Sequence__fini(array);
  }
  allocator.deallocate(array, allocator.state);
}

bool
bcr_bot__srv__GetVisualTopics_Response__Sequence__are_equal(const bcr_bot__srv__GetVisualTopics_Response__Sequence * lhs, const bcr_bot__srv__GetVisualTopics_Response__Sequence * rhs)
{
  if (!lhs || !rhs) {
    return false;
  }
  if (lhs->size != rhs->size) {
    return false;
  }
  for (size_t i = 0; i < lhs->size; ++i) {
    if (!bcr_bot__srv__GetVisualTopics_Response__are_equal(&(lhs->data[i]), &(rhs->data[i]))) {
      return false;
    }
  }
  return true;
}

bool
bcr_bot__srv__GetVisualTopics_Response__Sequence__copy(
  const bcr_bot__srv__GetVisualTopics_Response__Sequence * input,
  bcr_bot__srv__GetVisualTopics_Response__Sequence * output)
{
  if (!input || !output) {
    return false;
  }
  if (output->capacity < input->size) {
    const size_t allocation_size =
      input->size * sizeof(bcr_bot__srv__GetVisualTopics_Response);
    rcutils_allocator_t allocator = rcutils_get_default_allocator();
    bcr_bot__srv__GetVisualTopics_Response * data =
      (bcr_bot__srv__GetVisualTopics_Response *)allocator.reallocate(
      output->data, allocation_size, allocator.state);
    if (!data) {
      return false;
    }
    // If reallocation succeeded, memory may or may not have been moved
    // to fulfill the allocation request, invalidating output->data.
    output->data = data;
    for (size_t i = output->capacity; i < input->size; ++i) {
      if (!bcr_bot__srv__GetVisualTopics_Response__init(&output->data[i])) {
        // If initialization of any new item fails, roll back
        // all previously initialized items. Existing items
        // in output are to be left unmodified.
        for (; i-- > output->capacity; ) {
          bcr_bot__srv__GetVisualTopics_Response__fini(&output->data[i]);
        }
        return false;
      }
    }
    output->capacity = input->size;
  }
  output->size = input->size;
  for (size_t i = 0; i < input->size; ++i) {
    if (!bcr_bot__srv__GetVisualTopics_Response__copy(
        &(input->data[i]), &(output->data[i])))
    {
      return false;
    }
  }
  return true;
}
