Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rcl_yaml_param_parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
endif()

set(rcl_yaml_parser_sources
src/add_to_arrays.c
src/namespace.c
src/node_params.c
src/parse.c
src/parser.c
src/yaml_variant.c
)

add_library(
Expand Down
2 changes: 2 additions & 0 deletions rcl_yaml_param_parser/include/rcl_yaml_param_parser/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#ifndef RCL_YAML_PARAM_PARSER__TYPES_H_
#define RCL_YAML_PARAM_PARSER__TYPES_H_

#include <stdint.h>

#include "rcutils/allocator.h"
#include "rcutils/types/string_array.h"

Expand Down
121 changes: 121 additions & 0 deletions rcl_yaml_param_parser/src/add_to_arrays.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright 2018 Apex.AI, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "./impl/add_to_arrays.h"

#include "rcutils/error_handling.h"

#define ADD_VALUE_TO_SIMPLE_ARRAY(val_array, value, value_type, allocator) \
do { \
if (NULL == val_array->values) { \
val_array->values = value; \
val_array->size = 1; \
} else { \
/* Increase the array size by one and add the new value */ \
value_type * tmp_arr = val_array->values; \
val_array->values = allocator.zero_allocate( \
val_array->size + 1U, sizeof(value_type), allocator.state); \
if (NULL == val_array->values) { \
val_array->values = tmp_arr; \
RCUTILS_SAFE_FWRITE_TO_STDERR("Error allocating mem\n"); \
return RCUTILS_RET_BAD_ALLOC; \
} \
memcpy(val_array->values, tmp_arr, (val_array->size * sizeof(value_type))); \
val_array->values[val_array->size] = *value; \
val_array->size++; \
allocator.deallocate(value, allocator.state); \
allocator.deallocate(tmp_arr, allocator.state); \
} \
return RCUTILS_RET_OK; \
} while (0)

rcutils_ret_t add_val_to_bool_arr(
rcl_bool_array_t * const val_array,
bool * value,
const rcutils_allocator_t allocator)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(val_array, RCUTILS_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(value, RCUTILS_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
&allocator, "invalid allocator", return RCUTILS_RET_INVALID_ARGUMENT);

ADD_VALUE_TO_SIMPLE_ARRAY(val_array, value, bool, allocator);
}

///
/// Add a value to an integer array. Create the array if it does not exist
///
rcutils_ret_t add_val_to_int_arr(
rcl_int64_array_t * const val_array,
int64_t * value,
const rcutils_allocator_t allocator)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(val_array, RCUTILS_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(value, RCUTILS_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
&allocator, "invalid allocator", return RCUTILS_RET_INVALID_ARGUMENT);

ADD_VALUE_TO_SIMPLE_ARRAY(val_array, value, int64_t, allocator);
}

///
/// Add a value to a double array. Create the array if it does not exist
///
rcutils_ret_t add_val_to_double_arr(
rcl_double_array_t * const val_array,
double * value,
const rcutils_allocator_t allocator)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(val_array, RCUTILS_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(value, RCUTILS_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
&allocator, "invalid allocator", return RCUTILS_RET_INVALID_ARGUMENT);

ADD_VALUE_TO_SIMPLE_ARRAY(val_array, value, double, allocator);
}

///
/// Add a value to a string array. Create the array if it does not exist
///
rcutils_ret_t add_val_to_string_arr(
rcutils_string_array_t * const val_array,
char * value,
const rcutils_allocator_t allocator)
{
RCUTILS_CHECK_ARGUMENT_FOR_NULL(val_array, RCUTILS_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ARGUMENT_FOR_NULL(value, RCUTILS_RET_INVALID_ARGUMENT);
RCUTILS_CHECK_ALLOCATOR_WITH_MSG(
&allocator, "invalid allocator", return RCUTILS_RET_INVALID_ARGUMENT);

if (NULL == val_array->data) {
rcutils_ret_t ret = rcutils_string_array_init(val_array, 1, &allocator);
if (RCUTILS_RET_OK != ret) {
return ret;
}
val_array->data[0U] = value;
} else {
/// Increase the array size by one and add the new value
char ** new_string_arr_ptr = allocator.reallocate(
val_array->data,
((val_array->size + 1U) * sizeof(char *)), allocator.state);
if (NULL == new_string_arr_ptr) {
RCUTILS_SAFE_FWRITE_TO_STDERR("Error allocating mem\n");
return RCUTILS_RET_BAD_ALLOC;
}
val_array->data = new_string_arr_ptr;
val_array->data[val_array->size] = value;
val_array->size++;
}
return RCUTILS_RET_OK;
}
79 changes: 79 additions & 0 deletions rcl_yaml_param_parser/src/impl/add_to_arrays.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2018 Apex.AI, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef IMPL__ADD_TO_ARRAYS_H_
#define IMPL__ADD_TO_ARRAYS_H_

#include <yaml.h>

#include "rcutils/types.h"

#include "./types.h"
#include "rcl_yaml_param_parser/types.h"
#include "rcl_yaml_param_parser/visibility_control.h"

#ifdef __cplusplus
extern "C"
{
#endif

///
/// Add a value to a bool array. Create the array if it does not exist
///
RCL_YAML_PARAM_PARSER_PUBLIC
RCUTILS_WARN_UNUSED
rcutils_ret_t add_val_to_bool_arr(
rcl_bool_array_t * const val_array,
bool * value,
const rcutils_allocator_t allocator);

///
/// Add a value to an integer array. Create the array if it does not exist
///
RCL_YAML_PARAM_PARSER_PUBLIC
RCUTILS_WARN_UNUSED
rcutils_ret_t add_val_to_int_arr(
rcl_int64_array_t * const val_array,
int64_t * value,
const rcutils_allocator_t allocator);

///
/// Add a value to a double array. Create the array if it does not exist
///
RCL_YAML_PARAM_PARSER_PUBLIC
RCUTILS_WARN_UNUSED
rcutils_ret_t add_val_to_double_arr(
rcl_double_array_t * const val_array,
double * value,
const rcutils_allocator_t allocator);

///
/// Add a value to a string array. Create the array if it does not exist
///
RCL_YAML_PARAM_PARSER_PUBLIC
RCUTILS_WARN_UNUSED
rcutils_ret_t add_val_to_string_arr(
rcutils_string_array_t * const val_array,
char * value,
const rcutils_allocator_t allocator);

///
/// TODO (anup.pemmaiah): Support byte array
///

#ifdef __cplusplus
}
#endif

#endif // IMPL__ADD_TO_ARRAYS_H_
68 changes: 68 additions & 0 deletions rcl_yaml_param_parser/src/impl/namespace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2018 Apex.AI, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef IMPL__NAMESPACE_H_
#define IMPL__NAMESPACE_H_

#include <yaml.h>

#include "rcutils/types.h"

#include "./types.h"
#include "rcl_yaml_param_parser/types.h"
#include "rcl_yaml_param_parser/visibility_control.h"

#ifdef __cplusplus
extern "C"
{
#endif

///
/// Add name to namespace tracker
///
RCL_YAML_PARAM_PARSER_PUBLIC
RCUTILS_WARN_UNUSED
rcutils_ret_t add_name_to_ns(
namespace_tracker_t * ns_tracker,
const char * name,
const namespace_type_t namespace_type,
rcutils_allocator_t allocator);

///
/// Remove name from namespace tracker
///
RCL_YAML_PARAM_PARSER_PUBLIC
RCUTILS_WARN_UNUSED
rcutils_ret_t rem_name_from_ns(
namespace_tracker_t * ns_tracker,
const namespace_type_t namespace_type,
rcutils_allocator_t allocator);

///
/// Replace namespace in namespace tracker
///
RCL_YAML_PARAM_PARSER_PUBLIC
RCUTILS_WARN_UNUSED
rcutils_ret_t replace_ns(
namespace_tracker_t * ns_tracker,
char * const new_ns,
const uint32_t new_ns_count,
const namespace_type_t namespace_type,
rcutils_allocator_t allocator);

#ifdef __cplusplus
}
#endif

#endif // IMPL__NAMESPACE_H_
47 changes: 47 additions & 0 deletions rcl_yaml_param_parser/src/impl/node_params.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2018 Apex.AI, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef IMPL__NODE_PARAMS_H_
#define IMPL__NODE_PARAMS_H_

#include "rcl_yaml_param_parser/types.h"
#include "rcl_yaml_param_parser/visibility_control.h"

#ifdef __cplusplus
extern "C"
{
#endif

///
/// Create rcl_node_params_t structure
///
RCL_YAML_PARAM_PARSER_PUBLIC
RCUTILS_WARN_UNUSED
rcutils_ret_t node_params_init(
rcl_node_params_t * node_params,
const rcutils_allocator_t allocator);

///
/// Finalize rcl_node_params_t structure
///
RCL_YAML_PARAM_PARSER_PUBLIC
void rcl_yaml_node_params_fini(
rcl_node_params_t * node_params,
const rcutils_allocator_t allocator);

#ifdef __cplusplus
}
#endif

#endif // IMPL__NODE_PARAMS_H_
Loading