10 #include <unordered_map> 25 using StringMap = std::vector<std::pair<std::string, std::string>> ;
28 void init(
const std::string &desc )
override ;
52 TiXmlComment
createComment(
const std::string &comment )
const ;
53 TiXmlText
createText(
const std::string &text )
const ;
75 for(
auto &pc : procsConds ) {
76 if( pc.second ==
"true" ) {
77 executeElement.InsertEndChild(
createElement(
"processor", {{
"name", pc.first}} ) ) ;
80 executeElement.InsertEndChild(
createElement(
"processor", {{
"name", pc.first}, {
"condition", pc.second}} ) ) ;
83 root.InsertEndChild( executeElement ) ;
99 {
"DatasourceType",
"type"}
105 {
"GeometryType",
"type"}
112 auto &procs = cfg.
section(
"processors" ) ;
114 for(
auto &proc : processorNames ) {
115 auto &procSection = procs.section( proc ) ;
118 {
"ProcessorName",
"name"},
119 {
"ProcessorType",
"type"},
120 {
"ProcessorCritical",
"critical"},
121 {
"ProcessorClone",
"clone"}
126 TiXmlDocument document ;
128 TiXmlDeclaration declaration(
"1.0",
"utf8",
"" ) ;
129 document.InsertEndChild( declaration ) ;
131 auto t = std::time(
nullptr) ;
132 auto tm = *std::localtime(&t) ;
133 std::string indent =
" " ;
134 std::stringstream dateStr ; dateStr << std::put_time(&tm,
"Date: %d-%m-%Y %T") ;
135 std::stringstream header ;
137 indent <<
"This an example steering file generated by MarlinMT\n" <<
138 indent << dateStr.str() <<
"\n" <<
140 std::cout << cfg << std::endl ;
142 auto &cmdline = cfg.
section(
"CmdLine" ) ;
143 header << indent <<
"Full command line: " << cmdline.
parameter<std::string>(
"Arguments") <<
" \n" ;
147 document.InsertEndChild( root ) ;
148 document.SaveFile(
_fname ) ;
154 auto iter = section.
metadata().find(
"description" ) ;
155 if( section.
metadata().end() != iter ) {
165 for(
auto &attr : attrMapping ) {
166 attributes.push_back( { attr.second, section.
parameter<std::string>( attr.first ) } ) ;
170 for(
auto &p : parameters ) {
171 if( excludeParameters.end() != std::find( excludeParameters.begin(), excludeParameters.end(), p.first ) ) {
174 const auto &metadata = section.
metadata( ) ;
175 auto desciter = metadata.find( p.first +
".description" ) ;
176 auto optiter = metadata.find( p.first +
".optional" ) ;
177 if( (metadata.end() != desciter) && (metadata.end() != optiter) ) {
178 std::stringstream comment ;
179 if( optiter->second ==
"true" ) {
180 comment <<
"[Optional] " ;
182 comment << desciter->second ;
193 TiXmlElement element( name ) ;
194 for(
auto &attr : attrs ) {
195 element.SetAttribute( attr.first, attr.second ) ;
203 return TiXmlComment( comment.c_str() ) ;
209 return TiXmlText( text ) ;
215 auto parameter =
createElement(
"parameter", { {
"name", name} } ) ;
216 parameter.InsertEndChild(
createText( value ) ) ;
const Metadata & metadata() const
Get the section metadata.
XMLConfigWriter plugin Write an XML file from the configuration sections and parameters.
T parameter(const std::string &n) const
Get a parameter value as type T.
void write(const Configuration &cfg) override
Write the configuration object.
std::vector< std::pair< std::string, std::string > > StringMap
#define MARLINMT_DECLARE_CONFIG_WRITER(Class)
constexpr unsigned long long value(const Flag_t &flag)
void appendDescription(TiXmlElement &element, const ConfigSection §ion) const
Append the config section description in the element tree as comment.
TiXmlElement createParameter(const std::string &name, const std::string &value) const
std::string _fname
The output file name.
TiXmlElement createParameterSection(const std::string &name, const ConfigSection §ion, const StringMap &attrMapping={})
Create an XML element containing all parameters from a section.
ConfigSection & section(const std::string &sn)
Get a section by name.
ConfigWriter base class Interface for writing configuration.
void init(const std::string &desc) override
Initialize the parser.
std::vector< std::string > subsectionNames() const
Get the list of subsection names.
TiXmlElement createElement(const std::string &name, const StringMap &attrs={}) const
TiXmlText createText(const std::string &text) const
const ParameterMap & parameters() const
Get the raw parameter storage.
ConfigSection class Holds a set of parameters and subsection.
TiXmlComment createComment(const std::string &comment) const
bool hasSection(const std::string &n) const
Whether the section exists.
std::vector< K > keys(const std::map< K, V > &m)