38 #include <rclcpp/rclcpp.hpp> 
   39 #include <boost/algorithm/string.hpp>   
   44 static const rclcpp::Logger 
LOGGER = rclcpp::get_logger(
"moveit_setup.templates");
 
   51   if (!std::filesystem::is_regular_file(template_path))
 
   53     RCLCPP_ERROR_STREAM(LOGGER, 
"Unable to find template file " << template_path.string());
 
   58   std::ifstream template_stream(template_path);
 
   59   if (!template_stream.good())  
 
   61     RCLCPP_ERROR_STREAM(LOGGER, 
"Unable to load file " << template_path.string());
 
   66   std::string template_string;
 
   67   template_stream.seekg(0, std::ios::end);
 
   68   template_string.reserve(template_stream.tellg());
 
   69   template_stream.seekg(0, std::ios::beg);
 
   70   template_string.assign((std::istreambuf_iterator<char>(template_stream)), std::istreambuf_iterator<char>());
 
   71   template_stream.close();
 
   76     std::string key_with_brackets = 
"[" + variable.key + 
"]";
 
   77     boost::replace_all(template_string, key_with_brackets, variable.value);
 
   81   std::filesystem::path file_path = 
getPath();
 
   84   std::ofstream output_stream(file_path, std::ios_base::trunc);
 
   85   if (!output_stream.good())
 
   87     RCLCPP_ERROR_STREAM(LOGGER, 
"Unable to open file for writing " << file_path.string());
 
   91   output_stream << template_string.c_str();
 
   92   output_stream.close();
 
std::filesystem::path getPath() const
Returns the fully qualified path to this file.
 
static std::vector< TemplateVariable > variables_
 
virtual std::filesystem::path getTemplatePath() const =0
Returns the full path to the template file.
 
bool write() override
Writes the file to disk.
 
bool createParentFolders(const std::filesystem::path &file_path)
Create parent folders (recursively)
 
const rclcpp::Logger LOGGER