36 #include <sys/types.h> 
   59 int module_init(
const char *module_name, 
void *pdm, 
void *php){
 
   99         std::string fieldNameDelimiter = 
":";
 
  100         std::string fieldInfoDelimiter = 
"= ";
 
  101         std::string fieldInfoSeparator = 
",";
 
  102         std::string openSquareBracket = 
"[";
 
  104         std::ifstream infile(filePath);
 
  107         if(!infile.is_open()){
 
  108           silent_cerr(
"Error while loading of " << filePath << 
": file not found" << std::endl);
 
  113         std::getline(infile, line);
 
  117           silent_cerr(
"Error while reading " << filePath << 
": file is empty"<< std::endl);
 
  123         if(line.find(currentVersionLabel) == std::string::npos){
 
  124           silent_cerr(
"Error while reading " << filePath << 
": " << currentVersionLabel << 
" not found at line '" << line.substr(0, line.size()-1) << 
"'" << std::endl);
 
  127         std::size_t found = line.find(fieldInfoDelimiter);
 
  128         if(found == std::string::npos){
 
  129           silent_cerr(
"Error while reading " << filePath << 
": " << 
"delimiter '" << fieldInfoDelimiter << 
"' not found after " << currentVersionLabel << std::endl);
 
  134         std::string value = std::string();
 
  135         for(
int i = 0 ; isdigit(line.at(found + fieldInfoDelimiter.size() + i)) ; i++){
 
  136           char digit = line.at(found + fieldInfoDelimiter.size() + i);
 
  137           std::stringstream ss;
 
  144         if(value.size() == 0){
 
  145           silent_cerr(
"Error while reading " << filePath << 
": " << 
" missing value of " << currentVersionLabel << 
" at line '" << line.substr(0, line.size()-1) << 
"'" << std::endl);
 
  149         std::stringstream tmpss1;
 
  151         tmpss1 >> currentVersion; 
 
  155         int fieldPosition = 1; 
 
  157           std::getline(infile, line);
 
  162               std::string fieldName; 
 
  163               found = line.find(fieldNameDelimiter); 
 
  164               if(found == std::string::npos){
 
  165                 silent_cerr(
"Error while reading " << filePath << 
": " << 
"delimiter '" << fieldNameDelimiter << 
"' not found at line '" << line.substr(0,line.size()-1) << 
"'" << std::endl);
 
  168               fieldName = line.substr(0, found); 
 
  169               found = line.find(fieldInfoDelimiter);
 
  170               if(found == std::string::npos){
 
  171                 silent_cerr(
"Error while reading " << filePath << 
": " << 
"delimiter '" << fieldInfoDelimiter << 
"' not found for field '" << fieldName << 
"'" << std::endl);
 
  174               std::string fieldInfoRawString = line.substr(line.find(fieldInfoDelimiter) + fieldInfoDelimiter.size(), line.size()); 
 
  178               found = fieldInfoRawString.find(openSquareBracket);
 
  180                                 std::string typeFullName;
 
  181               if(found != std::string::npos){
 
  183                 value = std::string();
 
  184                 for(
int i = 0 ; isdigit(fieldInfoRawString.at(found + openSquareBracket.size() + i)) ; i++){
 
  185                   char digit = fieldInfoRawString.at(found + openSquareBracket.size() + i);
 
  186                   std::stringstream ss;
 
  192                 if(value.size() == 0){
 
  193                   silent_cerr(
"Error while reading " << filePath << 
": " << 
" empty brackets for field '" << fieldName << 
"' at line '" << line.substr(0, line.size()-1) << 
"'" << std::endl);
 
  196                 std::stringstream tmpss2;
 
  198                 tmpss2 >> fieldNumOfElem;
 
  200                 typeFullName = fieldInfoRawString.substr(0, found-1); 
 
  201                 found = fieldInfoRawString.find(fieldInfoSeparator); 
 
  204                 found = fieldInfoRawString.find(fieldInfoSeparator); 
 
  205                                         if(found != std::string::npos){
 
  206                         typeFullName = fieldInfoRawString.substr(0, found);
 
  211                                 if(found == std::string::npos){
 
  212                                         silent_cerr(
"Error while reading " << filePath << 
": " << 
"both info separators '" <<fieldInfoSeparator << 
"' missing for field '" << fieldName << 
"' at line '" << line.substr(0, line.size()-1) << 
"'" << std::endl);
 
  217                                 std::string tmp = fieldInfoRawString.substr(found+1, fieldInfoRawString.size());
 
  218                                 if(tmp.find(fieldInfoSeparator) == std::string::npos){
 
  219                                         silent_cerr(
"Error while reading " << filePath << 
": " << 
"missing info separator '" <<fieldInfoSeparator << 
"' for field '" << fieldName << 
"' at line '" << line.substr(0, line.size()-1) << 
"'" << std::endl);
 
  223               std::string sizeAndOffsetRawString = fieldInfoRawString.substr(found+1, fieldInfoRawString.size()); 
 
  224               found = sizeAndOffsetRawString.find(fieldInfoSeparator); 
 
  228               value = std::string();
 
  229              for(
int i = 0 ; isdigit(sizeAndOffsetRawString.at(found+2+i)) && found+2+i < sizeAndOffsetRawString.size() ; i++){
 
  230                 char digit = sizeAndOffsetRawString.at(found+2+i);
 
  231                 std::stringstream ss;
 
  238               if(value.size() == 0){
 
  239                 silent_cerr(
"Error while reading " << filePath << 
": " << 
" missing offset for field '" << fieldName << 
"' at line '" << line.substr(0, line.size()-1) << 
"'" << std::endl);
 
  243               std::stringstream tmpss3;
 
  249               for(
int i = 0 ; i < fieldNumOfElem ; i++){
 
  250                 std::string label = std::string();
 
  251                 std::string finalFieldName = std::string(fieldName);
 
  253                 if(fieldNumOfElem > 1){
 
  254                   label = std::string(
"_");
 
  256                   std::stringstream convert;
 
  260                   if(fieldNumOfElem < 10){
 
  266                 finalFieldName.append(label);
 
  268                 if(typeFullName.compare(
"unsigned int") == 0){
 
  269                   fieldsDescriptionFG.insert(FieldsDescriptionFG::value_type(finalFieldName,{
typeid(uint32_t),
sizeof(uint32_t),fieldPosition,offset+
sizeof(uint32_t)*i}));
 
  270                                         }
else if(typeFullName.compare(
"int") == 0){
 
  271                     fieldsDescriptionFG.insert(FieldsDescriptionFG::value_type(finalFieldName,{
typeid(int32_t),
sizeof(int32_t),fieldPosition,offset+
sizeof(int32_t)*i}));
 
  272                 }
else if(typeFullName.compare(
"float") == 0){
 
  273                   fieldsDescriptionFG.insert(FieldsDescriptionFG::value_type(finalFieldName,{
typeid(float),
sizeof(
float),fieldPosition,offset+
sizeof(
float)*i}));
 
  274                 }
else if(typeFullName.compare(
"double") == 0){
 
  275                   fieldsDescriptionFG.insert(FieldsDescriptionFG::value_type(finalFieldName,{
typeid(double),
sizeof(
double),fieldPosition,offset+
sizeof(
double)*i}));
 
  277                                                 silent_cerr(
"Error while reading " << filePath << 
": " << 
" unknown type for field '" << fieldName << 
"' at line '" << line.substr(0, line.size()-1) << 
"'" << std::endl);
 
  283           }
else if(fieldPosition == 1){
 
  284                         silent_cerr(
"Error while reading " << filePath << 
": " << 
" file does not contain any field description" << std::endl);
 
  287         }
while(!infile.eof());
 
  293         std::ofstream outFile;
 
  294         outFile.open(fileName);
 
  296         if(!outFile.is_open()){
 
  297                 silent_cerr(
"Error while writing on file: " << fileName << 
", impossible to open it" << std::endl);
 
  301         for(
int i = 0 ; i < (
int)fieldsDescriptionFG.size() ; i++){
 
  302                 for(FieldsDescriptionFG::iterator it = fieldsDescriptionFG.begin() ; it != fieldsDescriptionFG.end() ; it++){
 
  303                         if(it->second.position == i+1){
 
  304                           outFile << it->first << std::endl;
 
  318                   for(TypeMap_t::iterator i = swapmap.begin() ; i != swapmap.end() ; i++){
 
  323                 for (FieldsDescriptionFG::iterator it = fieldsDescriptionFGInUse.begin() ; it != fieldsDescriptionFGInUse.end() ; it++){
 
  324                         data[it->second.position-1] = 
buildOneFGBufCast(it->second.offset, swapmap, it->second.type);
 
  331                 if (fieldType == 
typeid(int8_t)) {
 
  332                         TypeMap_t::const_iterator i = swapmap.find(
typeid(int8_t).name());
 
  339                 } 
else if (fieldType == 
typeid(uint8_t)) {
 
  340                         TypeMap_t::const_iterator i = swapmap.find(
typeid(uint8_t).name());
 
  347                 } 
else if (fieldType == 
typeid(int16_t)) {
 
  348                         TypeMap_t::const_iterator i = swapmap.find(
typeid(int16_t).name());
 
  355                 } 
else if (fieldType == 
typeid(uint16_t)) {
 
  356                         TypeMap_t::const_iterator i = swapmap.find(
typeid(uint16_t).name());
 
  363                 } 
else if (fieldType == 
typeid(int32_t)) {
 
  364                         TypeMap_t::const_iterator i = swapmap.find(
typeid(int32_t).name());
 
  371                 } 
else if (fieldType == 
typeid(uint32_t)) {
 
  372                         TypeMap_t::const_iterator i = swapmap.find(
typeid(uint32_t).name());
 
  379                 } 
else if (fieldType == 
typeid(
float)) {
 
  380                         TypeMap_t::const_iterator i = swapmap.find(
typeid(
float).name());
 
  387                 } 
else if (fieldType == 
typeid(
double)) {
 
  388                         TypeMap_t::const_iterator i = swapmap.find(
typeid(
double).name());
 
#define MBDYN_EXCEPT_ARGS
void SwapMapInit(TypeMap_t &swapmap)
bool setFileDriveCallerType(const char *name, FileDriveCallerTypeReader *rf)
void printOptionsOnTextFile(const char *fileName, FieldsDescriptionFG &fieldsDescriptionFG)
void buildFGBufCast(std::vector< BufCast * > &data, FieldsDescriptionFG &fieldsDescriptionFGInUse)
bool SetStreamOutputContentType(const char *name, StreamOutputContentTypeReader *rf)
void readFGStructuresFromFile(const char *filePath, std::string currentVersionLabel, FieldsDescriptionFG &fieldsDescriptionFG, int ¤tVersion)
FGNetCtrlsWordSet fGNetCtrlsWordSet
bool SetFileDriveContentType(const char *name, FileDriveContentTypeReader *rf)
bool bIsLittleEndian(void)
int module_init(const char *module_name, void *pdm, void *php)
This function registers our user defined element for the math parser. 
std::map< std::string, bool > TypeMap_t
FieldsDescriptionFG fieldsDescriptionFGNetCtrls
void buildFieldsDescriptionFG(void)
FGNetFDMWordSet fGNetFDMWordSet
BufCast * buildOneFGBufCast(size_t &offset, TypeMap_t &swapmap, const std::type_info &fieldType)
FieldsDescriptionFG fieldsDescriptionFGNetFDM
static std::stack< const HighParser * > pHP
std::map< std::string, FieldInfo > FieldsDescriptionFG