Skip to content

Commit

Permalink
Allow Parameter construction with empty name (#67)
Browse files Browse the repository at this point in the history
* Private comes after public

* Allow Parameter construction without name

* Docstrings update

* Update CHANGELOG

* Improve docstring

Co-authored-by: Enrico Eberhard <[email protected]>

* 6.3.41 -> 6.3.42

---------

Co-authored-by: Enrico Eberhard <[email protected]>
  • Loading branch information
domire8 and eeberhard authored Feb 8, 2023
1 parent d6c87f4 commit abec0d2
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Release Versions:
- Refactor operators in JointState (multiplication & division #62, addition #63, subtraction #64)
- Bind operators of joint states (#65)
- Add initialize method to Parameter class (#68)
- Allow Parameter construction with empty name (#67)

## 6.3.1

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.41
6.3.42
2 changes: 1 addition & 1 deletion demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(control_libraries 6.3.41 CONFIG REQUIRED)
find_package(control_libraries 6.3.42 CONFIG REQUIRED)

set(DEMOS_SCRIPTS
task_space_control_loop
Expand Down
2 changes: 1 addition & 1 deletion doxygen/doxygen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Control Libraries"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 6.3.41
PROJECT_NUMBER = 6.3.42

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion protocol/clproto_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.15)

project(clproto VERSION 6.3.41)
project(clproto VERSION 6.3.42)

# Default to C99
if(NOT CMAKE_C_STANDARD)
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# names of the environment variables that define osqp and openrobots include directories
osqp_path_var = 'OSQP_INCLUDE_DIR'

__version__ = "6.3.41"
__version__ = "6.3.42"
__libraries__ = ['state_representation', 'clproto', 'controllers', 'dynamical_systems', 'robot_model']
__include_dirs__ = ['include']

Expand Down
2 changes: 1 addition & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.15)

project(control_libraries VERSION 6.3.41)
project(control_libraries VERSION 6.3.42)

# Build options
option(BUILD_TESTING "Build all tests." OFF)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,38 @@

namespace state_representation {

/**
* @class Parameter
* @brief Class to represent name-value pairs of different types
* @tparam T The type of the value stored in the parameter
*/
template<typename T>
class Parameter : public ParameterInterface {
private:
T value_;///< Value of the parameter

public:
/**
* @brief Constructor with name of the parameter.
* @param name The name of the parameter
* @brief Constructor with the name of the parameter
* @param name The name of the parameter (default is empty)
*/
explicit Parameter(const std::string& name);
explicit Parameter(const std::string& name = "");

/**
* @brief Constructor with a name and a value.
* @brief Constructor with a name and a value
* @param name The name of the parameter
* @param value The value of the parameter
*/
explicit Parameter(const std::string& name, const T& value);

/**
* @brief Default virtual destructor
*/
virtual ~Parameter() = default;
Parameter(const std::string& name, const T& value);

/**
* @brief Copy constructor
* @param parameter The parameter to copy
*/
template<typename U>
Parameter(const Parameter<U>& parameter);
explicit Parameter(const Parameter<U>& parameter);

/**
* @brief Default virtual destructor
*/
virtual ~Parameter() = default;

/**
* @brief Conversion equality
Expand All @@ -47,28 +49,28 @@ class Parameter : public ParameterInterface {
Parameter<T>& operator=(const Parameter<U>& parameter);

/**
* @brief Getter of the value attribute.
* @brief Getter of the value attribute
* @tparam U The expected type of the parameter
* @return The value attribute
*/
template<typename U>
U get_value() const;

/**
* @brief Getter of the value attribute.
* @brief Getter of the value attribute
* @return The value attribute
*/
const T& get_value() const;

/**
* @brief Getter of the value attribute.
* @brief Getter of the value attribute
* @return The value attribute
*/
T& get_value();

/**
* @brief Setter of the value attribute.
* @param The new value attribute
* @brief Setter of the value attribute
* @param value The new value attribute
*/
virtual void set_value(const T& value);

Expand All @@ -78,13 +80,16 @@ class Parameter : public ParameterInterface {
void initialize() override;

/**
* @brief Overload the ostream operator for printing.
* @param os The ostream to append the string representing the State to
* @param parameter The Parameter to print
* @brief Overload the ostream operator for printing
* @param os The ostream to append the string representing the state to
* @param parameter The parameter to print
* @return The appended ostream
*/
template<typename U>
friend std::ostream& operator<<(std::ostream& os, const Parameter<U>& parameter);

private:
T value_;///< Value of the parameter
};

template<typename T>
Expand All @@ -105,7 +110,7 @@ Parameter<T>& Parameter<T>::operator=(const Parameter<U>& parameter) {

template<typename T>
template<typename U>
U Parameter<T>::get_value() const {
inline U Parameter<T>::get_value() const {
return static_cast<U>(this->value_);
}

Expand All @@ -131,11 +136,25 @@ inline void Parameter<T>::initialize() {
this->value_ = T();
}

/**
* @brief Create a Parameter object that is owned by a shared_ptr
* @tparam T The type of the value stored in the parameter
* @param name The name of the parameter
* @param param_value The value of the parameter
* @return A shared_ptr that owns the newly created Parameter object
*/
template<typename T>
static std::shared_ptr<Parameter<T>> make_shared_parameter(const std::string& name, const T& param_value) {
return std::make_shared<Parameter<T>>(name, param_value);
}

/**
* @brief Encapsulate a parameter in a ParameterInterface pointer
* @param name The name of the parameter
* @param type The type of the parameter
* @param parameter_state_type The state type of the parameter, if applicable
* @return A ParameterInterface pointer holding a reference to a Parameter object
*/
[[maybe_unused]] static std::shared_ptr<ParameterInterface> make_shared_parameter_interface(
const std::string& name, const ParameterType& type, const StateType& parameter_state_type = StateType::NONE
) {
Expand Down Expand Up @@ -179,7 +198,7 @@ static std::shared_ptr<Parameter<T>> make_shared_parameter(const std::string& na
case ParameterType::MATRIX:
return std::make_shared<Parameter<Eigen::MatrixXd>>(name);
default:
throw exceptions::InvalidParameterException("This StateType is not supported for parameters.");
throw exceptions::InvalidParameterException("This ParameterType is not supported for parameters.");
}
}
}// namespace state_representation
5 changes: 3 additions & 2 deletions source/state_representation/test/tests/test_parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ TYPED_TEST_SUITE_P(ParameterTest);

TYPED_TEST_P(ParameterTest, Construction) {
for (auto const& test_case: this->test_cases_) {
Parameter<TypeParam> param("test");
EXPECT_EQ(param.get_name(), "test");
Parameter<TypeParam> param;
EXPECT_EQ(param.get_parameter_type(), std::get<1>(test_case));
EXPECT_EQ(param.get_parameter_state_type(), std::get<2>(test_case));
EXPECT_TRUE(param.is_empty());
EXPECT_FALSE(param);
param.set_name("test");
EXPECT_EQ(param.get_name(), "test");
expect_values_equal(param.get_value(), TypeParam());
ParameterInterface param_interface(param);
EXPECT_EQ(param_interface.get_name(), param.get_name());
Expand Down

0 comments on commit abec0d2

Please sign in to comment.