-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* don't warn about missing findpackage * (wip) start on ros2 interface * add new launch extension package * drop broken unit test install * switch config tag format and work on parsing correctly * work on performing substitutions on parsed param fields * allow optional new YAML merging behavior * (wip) start on context * outline basic commandline infrastructure * remove rclcpp and add context command line function * fix linting warnings and add more coverage for external registry * split parsing and utils tests * forward extend_sequence arg and add merge tests * add additional yaml parsing test coverage * fix broken test and make merge test more complicated * (wip) initial implementation of parsing * condense files and allow for multiple tokens * implement custom parser because ros can't escape correctly * drop debug print * add ability to namespace files * drop launch extension * add command line tests and fix application order * fix function name and add cli docs * mention multiple flags * add full api to context plus quick documentation * add doc links * remove logging TODOs * log to stderr for errors and warnings by default
- Loading branch information
1 parent
09f2d73
commit b210eb1
Showing
29 changed files
with
1,381 additions
and
115 deletions.
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.