-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/ros2 #40
Merged
Merged
Feature/ros2 #40
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
ea6f107
don't warn about missing findpackage
nathanhhughes f3f63ee
(wip) start on ros2 interface
nathanhhughes 19fe974
add new launch extension package
nathanhhughes 3a3c156
drop broken unit test install
nathanhhughes 2a3ac3d
switch config tag format and work on parsing correctly
nathanhhughes a6e389d
work on performing substitutions on parsed param fields
nathanhhughes a74c0cb
allow optional new YAML merging behavior
nathanhhughes 832edfa
(wip) start on context
nathanhhughes 803ea39
outline basic commandline infrastructure
nathanhhughes c8aaf9b
remove rclcpp and add context command line function
nathanhhughes 0242800
fix linting warnings and add more coverage for external registry
nathanhhughes ebda7b3
split parsing and utils tests
nathanhhughes 189f53b
forward extend_sequence arg and add merge tests
nathanhhughes 018e47b
add additional yaml parsing test coverage
nathanhhughes 921f14f
fix broken test and make merge test more complicated
nathanhhughes 0e05454
(wip) initial implementation of parsing
nathanhhughes 922a9e4
condense files and allow for multiple tokens
nathanhhughes b433de0
implement custom parser because ros can't escape correctly
nathanhhughes f00a2c8
drop debug print
nathanhhughes 355e6bb
add ability to namespace files
nathanhhughes f00edbc
drop launch extension
nathanhhughes d640177
add command line tests and fix application order
nathanhhughes a58abd7
fix function name and add cli docs
nathanhhughes 1e9db51
mention multiple flags
nathanhhughes f542cb7
add full api to context plus quick documentation
nathanhhughes 3f044fd
add doc links
nathanhhughes eb34098
remove logging TODOs
nathanhhughes e49a47d
log to stderr for errors and warnings by default
nathanhhughes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
config_utilities/include/config_utilities/internal/config_context.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** ----------------------------------------------------------------------------- | ||
* Copyright (c) 2023 Massachusetts Institute of Technology. | ||
* All Rights Reserved. | ||
* | ||
* AUTHORS: Lukas Schmid <[email protected]>, Nathan Hughes <[email protected]> | ||
* AFFILIATION: MIT-SPARK Lab, Massachusetts Institute of Technology | ||
* YEAR: 2023 | ||
* LICENSE: BSD 3-Clause | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* -------------------------------------------------------------------------- */ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include <yaml-cpp/yaml.h> | ||
|
||
#include "config_utilities/factory.h" | ||
#include "config_utilities/internal/visitor.h" | ||
|
||
namespace config::internal { | ||
|
||
/** | ||
* @brief Context is a singleton that holds the raw parsed information used to generate configs | ||
*/ | ||
class Context { | ||
public: | ||
~Context() = default; | ||
|
||
static void update(const YAML::Node& other, const std::string& ns); | ||
|
||
static void clear(); | ||
|
||
static YAML::Node toYaml(); | ||
|
||
template <typename BaseT, typename... ConstructorArguments> | ||
static std::unique_ptr<BaseT> create(ConstructorArguments... args) { | ||
return internal::ObjectWithConfigFactory<BaseT, ConstructorArguments...>::create(instance().contents_, args...); | ||
} | ||
|
||
template <typename BaseT, typename... ConstructorArguments> | ||
static std::unique_ptr<BaseT> createNamespaced(const std::string& name_space, ConstructorArguments... args) { | ||
const auto ns_node = internal::lookupNamespace(instance().contents_, name_space); | ||
return internal::ObjectWithConfigFactory<BaseT, ConstructorArguments...>::create(ns_node, args...); | ||
} | ||
|
||
template <typename ConfigT> | ||
static ConfigT loadConfig(const std::string& name_space = "") { | ||
ConfigT config; | ||
internal::Visitor::setValues(config, internal::lookupNamespace(instance().contents_, name_space), true); | ||
return config; | ||
} | ||
|
||
private: | ||
Context() = default; | ||
static Context& instance(); | ||
|
||
YAML::Node contents_; | ||
}; | ||
|
||
} // namespace config::internal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
config_utilities/include/config_utilities/parsing/commandline.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/** ----------------------------------------------------------------------------- | ||
* Copyright (c) 2023 Massachusetts Institute of Technology. | ||
* All Rights Reserved. | ||
* | ||
* AUTHORS: Lukas Schmid <[email protected]>, Nathan Hughes <[email protected]> | ||
* AFFILIATION: MIT-SPARK Lab, Massachusetts Institute of Technology | ||
* YEAR: 2023 | ||
* LICENSE: BSD 3-Clause | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* -------------------------------------------------------------------------- */ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "config_utilities/factory.h" | ||
#include "config_utilities/internal/visitor.h" | ||
#include "config_utilities/internal/yaml_utils.h" | ||
|
||
namespace config { | ||
namespace internal { | ||
|
||
/** | ||
* @brief Parse and collate YAML node from arguments, optionally removing arguments | ||
* @param argc Number of command line arguments | ||
* @param argv Command line argument strings | ||
*/ | ||
YAML::Node loadFromArguments(int& argc, char* argv[], bool remove_args); | ||
|
||
} // namespace internal | ||
|
||
/** | ||
* @brief Loads a config based on collated YAML data specified via the command line | ||
* | ||
* See fromYaml() for more specific behavioral information. | ||
* | ||
* @tparam ConfigT The config type. This can also be a VirtualConfig<BaseT> or a std::vector<ConfigT>. | ||
* @param argc Number of arguments. | ||
* @param argv Actual command line arguments. | ||
* @param name_space Optional namespace to use under the resolved YAML parameter tree. | ||
* @returns The config. | ||
*/ | ||
template <typename ConfigT> | ||
ConfigT fromCLI(int argc, char* argv[], const std::string& name_space = "") { | ||
// when parsing CLI locally we don't want to modify the arguments ever | ||
const auto node = internal::loadFromArguments(argc, argv, false); | ||
|
||
ConfigT config; | ||
internal::Visitor::setValues(config, internal::lookupNamespace(node, name_space), true); | ||
return config; | ||
} | ||
|
||
/** | ||
* @brief Create a derived type object based on collated YAML data specified via the command line | ||
* | ||
* See createFromYaml() for more specific behavioral information. | ||
* | ||
* @tparam BaseT Type of the base class to be constructed. | ||
* @tparam Args Other constructor arguments. | ||
* @param argc Number of arguments. | ||
* @param argv Actual command line arguments. | ||
* @param args Other constructor arguments. | ||
* @returns Unique pointer of type base that contains the derived object. | ||
*/ | ||
template <typename BaseT, typename... ConstructorArguments> | ||
std::unique_ptr<BaseT> createFromCLI(int argc, char* argv[], ConstructorArguments... args) { | ||
// when parsing CLI locally we don't want to modify the arguments ever | ||
const auto node = internal::loadFromArguments(argc, argv, false); | ||
return internal::ObjectWithConfigFactory<BaseT, ConstructorArguments...>::create(node, args...); | ||
} | ||
|
||
/** | ||
* @brief Create a derived type object based on collated YAML data specified via the command line | ||
* | ||
* See createFromYamlWithNamespace() for more specific behavioral information. | ||
* | ||
* @tparam BaseT Type of the base class to be constructed. | ||
* @tparam Args Other constructor arguments. | ||
* @param argc Number of arguments. | ||
* @param argv Actual command line arguments. | ||
* @param name_space Optionally specify a name space to create the object from. | ||
* @param args Other constructor arguments. | ||
* @returns Unique pointer of type base that contains the derived object. | ||
*/ | ||
template <typename BaseT, typename... ConstructorArguments> | ||
std::unique_ptr<BaseT> createFromCLIWithNamespace(int argc, | ||
char* argv[], | ||
const std::string& name_space, | ||
ConstructorArguments... args) { | ||
// when parsing CLI locally we don't want to modify the arguments ever | ||
const auto node = internal::loadFromArguments(argc, argv, false); | ||
const auto ns_node = internal::lookupNamespace(node, name_space); | ||
return internal::ObjectWithConfigFactory<BaseT, ConstructorArguments...>::create(ns_node, args...); | ||
} | ||
|
||
} // namespace config |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!