208 std::string inputDir, outputDir;
211 std::string s = argv[1];
213 if (s[s.size()-1] !=
'/')
225 std::istringstream iss;
226 std::ostringstream oss;
228 std::map<std::string,bool> attributeFlags;
232 std::string attDefFile = inputDir + attDefName +
".txt";
233 std::string attDefHeader = outputDir + attDefName +
".hpp";
242 std::string UpperAttDefName = attDefName ;
243 for (
auto & c: UpperAttDefName) c =
toupper(c);
245 oss <<
"//////////// THIS FILE MUST BE CREATED BY EXECUTING WriteAttributeDefinitionFile ////////////" << std::endl;
246 oss <<
"//////////// DO NOT MODIFY THIS FILE MANUALLY ///////////////////////////////////////////////" << std::endl << std::endl;
248 oss <<
"#ifndef __NOMAD400_"<< UpperAttDefName <<
"__" << std::endl;
249 oss <<
"#define __NOMAD400_"<< UpperAttDefName <<
"__" << std::endl << std::endl;
250 oss <<
"_definition = {" ;
258 errMsg =
" Failed to open file " + attDefFile +
".";
261 fin.open ( attDefFile );
267 if ( !errMsg.empty() )
273 bool firstAttribute =
true;
275 while ( fin.good() && !fin.eof() )
279 if ( firstAttribute )
293 errMsg =
" Failed to read file " + attDefFile +
".";
297 if ( line.size() > 0 && line.find_first_of(
"#")== 0 )
308 if ( ! firstAttribute )
309 oss <<
"," << std::endl;
313 std::string attributeName;
316 iss >> attributeName;
318 if ( attributeName.size()==0)
320 errMsg =
" The first word after a comment must be an attribute name. \n An empty line is not valid.";
323 oss <<
"{ \"" << attributeName <<
"\", ";
329 if ( fin.fail() || line.empty() )
331 errMsg =
"Failed to read file " + attDefFile +
".";
335 std::string attributeType;
339 iss >> attributeType ;
341 if ( attributeType.size()==0 )
343 errMsg =
" The next word after an attribute name must be the attribute type. \n An empty line is not valid.";
346 oss <<
" \"" << attributeType <<
"\", " ;
352 if ( fin.fail() || line.empty() )
354 errMsg =
" Failed to read file " + attDefFile +
".";
358 std::string attributeDefault= line;
363 if (
"std::string" == attributeType ||
"NOMAD::ArrayOfString" == attributeType)
365 if (
"\"\"" == attributeDefault ||
"-" == attributeDefault ||
"N/A" == attributeDefault)
367 attributeDefault.clear();
371 oss <<
" \"" << attributeDefault <<
"\", ";
378 std::string attributeShortInfo =
readBlockOfLines( fin, lineNumber ,R
"f(\()f" , R"f(\))f" );
379 oss << " \"" << attributeShortInfo <<
"\", " ;
387 std::string attributeHelpInfo =
readBlockOfLines( fin , lineNumber , R
"f(\()f", R"f(\))f");
391 bool flagEmpty = attributeDefault.empty() || attributeDefault==
"\"\"";
392 bool flagNoDefault = attributeDefault==
"-";
393 attributeHelpInfo +=
". ";
396 attributeHelpInfo +=
"No default value.";
400 attributeHelpInfo +=
"Default: Empty string.";
404 attributeHelpInfo +=
"Default: " + attributeDefault;
406 attributeHelpInfo +=
"\\n\\n";
408 oss <<
" \"" << attributeHelpInfo <<
"\", ";
415 std::string attributeKeywords =
readBlockOfLines( fin , lineNumber , R
"f(\()f", R"f(\))f");
417 oss << " \"" << attributeKeywords <<
"\" ";
423 std::string attributeFlagName,attributeFlagValue;
428 while ( line.size() > 0 && line.find_first_of(
"#") != 0 )
432 iss >> attributeFlagName >> attributeFlagValue;
434 if ( attributeFlagName.size()==0 || attributeFlagValue.size()==0 )
436 errMsg =
" An attribute flag name and value (bool) is expected (ex. RESTART_ATTRIBUTE yes). \n An empty line or a missing flag value (bool) is not valid.";
443 if ( attributeFlags.find(attributeFlagName) != attributeFlags.end() )
448 if ( attributeFlagValue.compare(
"YES")==0 || attributeFlagValue.compare(
"TRUE")==0 )
449 attributeFlags[attributeFlagName] =
true;
450 else if ( attributeFlagValue.compare(
"NO")==0 || attributeFlagValue.compare(
"FALSE")==0 )
451 attributeFlags[attributeFlagName] =
false;
454 errMsg =
" An attribute flag name and value (bool) is expected (ex. RESTART_ATTRIBUTE yes). \n The value must be YES/TRUE or NO/FALSE.";
460 errMsg =
" An attribute flag name and value (bool) is expected (ex. RESTART_ATTRIBUTE yes).\n This flag name: " + attributeFlagName +
" is not registered.";
469 for (
auto attFlag : attributeFlags )
471 oss <<
" , \"" << ((attFlag.second) ?
"true":
"false") <<
"\"";
478 firstAttribute =
false;
482 oss << std::endl << std::endl <<
"#endif" << std::endl;
490 fout.open( attDefHeader );
494 errMsg =
" Failed to open the header file for writing attribute definition.";
506 std::cerr <<
"ERROR: Problem handling file for attribute definition: " << ((flagInFile) ? attDefFile:attDefHeader) <<
" at line " << e.
getLineNumber() <<
". \n" << e.
what() << std::endl << std::endl;