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

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

#include "rcutils/allocator.h"


bool
virtual_robot_prococol__msg__RobotStatus__init(virtual_robot_prococol__msg__RobotStatus * msg)
{
  if (!msg) {
    return false;
  }
  // pos_x
  // pos_y
  // speed_x
  // speed_y
  return true;
}

void
virtual_robot_prococol__msg__RobotStatus__fini(virtual_robot_prococol__msg__RobotStatus * msg)
{
  if (!msg) {
    return;
  }
  // pos_x
  // pos_y
  // speed_x
  // speed_y
}

bool
virtual_robot_prococol__msg__RobotStatus__are_equal(const virtual_robot_prococol__msg__RobotStatus * lhs, const virtual_robot_prococol__msg__RobotStatus * rhs)
{
  if (!lhs || !rhs) {
    return false;
  }
  // pos_x
  if (lhs->pos_x != rhs->pos_x) {
    return false;
  }
  // pos_y
  if (lhs->pos_y != rhs->pos_y) {
    return false;
  }
  // speed_x
  if (lhs->speed_x != rhs->speed_x) {
    return false;
  }
  // speed_y
  if (lhs->speed_y != rhs->speed_y) {
    return false;
  }
  return true;
}

bool
virtual_robot_prococol__msg__RobotStatus__copy(
  const virtual_robot_prococol__msg__RobotStatus * input,
  virtual_robot_prococol__msg__RobotStatus * output)
{
  if (!input || !output) {
    return false;
  }
  // pos_x
  output->pos_x = input->pos_x;
  // pos_y
  output->pos_y = input->pos_y;
  // speed_x
  output->speed_x = input->speed_x;
  // speed_y
  output->speed_y = input->speed_y;
  return true;
}

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

void
virtual_robot_prococol__msg__RobotStatus__destroy(virtual_robot_prococol__msg__RobotStatus * msg)
{
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  if (msg) {
    virtual_robot_prococol__msg__RobotStatus__fini(msg);
  }
  allocator.deallocate(msg, allocator.state);
}


bool
virtual_robot_prococol__msg__RobotStatus__Sequence__init(virtual_robot_prococol__msg__RobotStatus__Sequence * array, size_t size)
{
  if (!array) {
    return false;
  }
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  virtual_robot_prococol__msg__RobotStatus * data = NULL;

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

void
virtual_robot_prococol__msg__RobotStatus__Sequence__fini(virtual_robot_prococol__msg__RobotStatus__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) {
      virtual_robot_prococol__msg__RobotStatus__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);
  }
}

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

void
virtual_robot_prococol__msg__RobotStatus__Sequence__destroy(virtual_robot_prococol__msg__RobotStatus__Sequence * array)
{
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  if (array) {
    virtual_robot_prococol__msg__RobotStatus__Sequence__fini(array);
  }
  allocator.deallocate(array, allocator.state);
}

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

bool
virtual_robot_prococol__msg__RobotStatus__Sequence__copy(
  const virtual_robot_prococol__msg__RobotStatus__Sequence * input,
  virtual_robot_prococol__msg__RobotStatus__Sequence * output)
{
  if (!input || !output) {
    return false;
  }
  if (output->capacity < input->size) {
    const size_t allocation_size =
      input->size * sizeof(virtual_robot_prococol__msg__RobotStatus);
    rcutils_allocator_t allocator = rcutils_get_default_allocator();
    virtual_robot_prococol__msg__RobotStatus * data =
      (virtual_robot_prococol__msg__RobotStatus *)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 (!virtual_robot_prococol__msg__RobotStatus__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; ) {
          virtual_robot_prococol__msg__RobotStatus__fini(&output->data[i]);
        }
        return false;
      }
    }
    output->capacity = input->size;
  }
  output->size = input->size;
  for (size_t i = 0; i < input->size; ++i) {
    if (!virtual_robot_prococol__msg__RobotStatus__copy(
        &(input->data[i]), &(output->data[i])))
    {
      return false;
    }
  }
  return true;
}
