Code:
Recipes.h:
EXTERN int LoadRecipe_Par(FILE * RecipeFile, etc., int * RecipePar);
EXTERN int LoadRecipe_Par(FILE * RecipeFile, etc., unsigned int * RecipePar);
EXTERN int LoadRecipe_Par(FILE * RecipeFile, etc., float * RecipePar);
Recipes.cpp:
int Cabled_sscanf(char * LoadString, char * VarName, int * RecipePar)
{
return(sscanf(LoadString,"%s \t# \t%d",VarName, RecipePar));
}
int Cabled_sscanf(char * LoadString, char * VarName,unsigned int * RecipePar)
{
return(sscanf(LoadString,"%s \t# \t%u",VarName, RecipePar));
}
int Cabled_sscanf(char * LoadString, char * VarName, float * RecipePar)
{
return(sscanf(LoadString,"%s \t# \t%f",VarName, RecipePar));
}
template <class Type_Par> int LoadRecipePar(FILE * RecipeFile, int * BreakAll,int BreakAllAllowed, char * LoadString, char * VarName, Type_Par * RecipePar)
{
int res;
if ( GetNextRecipeLine(RecipeFile, BreakAll, BreakAllAllowed, LoadString) )
{
fclose(RecipeFile);
return -1; //fine file inaspettata
}
if ( (strstr(LoadString, "#HMI")==NULL) && (strstr(LoadString, "# HMI")==NULL) && (strstr(LoadString, "# HMI")==NULL) )
{
res=Cabled_sscanf(LoadString, VarName, RecipePar);
if(res!=2)
{
fclose(RecipeFile);
printf("Problems reading Recipe at or after %hs\n",VarName);
return -1;
}
}
return(0);
}
//This way I basically have a template available outside (which is not supported by standard C++)
int LoadRecipe_Par(FILE * RecipeFile, int * BreakAll,int BreakAllAllowed, char * LoadString, char * VarName, int * RecipePar)
{
LoadRecipePar(RecipeFile, BreakAll, BreakAllAllowed, LoadString, VarName, RecipePar);
}
int LoadRecipe_Par(FILE * RecipeFile, int * BreakAll,int BreakAllAllowed, char * LoadString, char * VarName, unsigned int * RecipePar)
{
LoadRecipePar(RecipeFile, BreakAll, BreakAllAllowed, LoadString, VarName, RecipePar);
}
int LoadRecipe_Par(FILE * RecipeFile, int * BreakAll,int BreakAllAllowed, char * LoadString, char * VarName, float * RecipePar)
{
LoadRecipePar(RecipeFile, BreakAll, BreakAllAllowed, LoadString, VarName, RecipePar);
}