/***************************************************************************
                          File.h  -  description
                             -------------------
    begin                : Don Mai 8 2003
    copyright            : (C) 2003 by klaus frieler
    email                : kgf@omniversum.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef FILE_H
#define FILE_H
#include "Melody.h"
#include "Types.h"

class File
{
public:
   string sFieldSeparator;
   static SimType SimTypes[];
   static FeatureDef FeatureDefs[];
   static FeatureDef *getFeature(const string& feature);
   static bool getFeaturesFromString(const string& feature, FeatureList& fl);
   static string getToken(const char *str, uint which, const char delim);
   static void printFeatures(bool bExplanation = false);
   static void printSimTypes();

public:
   File():errorString(""), m_sFieldSeparator(";"), m_verbLevel(silent) {}
   ~File(){}

   bool        readCSVFile(const char* file, Melody &melody);
   bool        readMelodies(Melody **pMelody, const vector<string>& fileList, const uint quantLevel = 6);
   bool        readTypesFile(const char* file, SimTypeList &typeList, string &header, bool &bNeedGauss);
   bool        readFeatureFile(const char* file, FeatureList &typeList);
   bool        readFilesFile(const char* file, vector<string> &fileList);
   void        getAllTypes(SimTypeList &typeList, string& header, bool &bNeedGauss);
   void        getDefaultSimTypes(SimTypeList &typeList, string &header, bool &bNeedGauss);

   bool        printCSV(const char *filename, const uint mode, const char* line );
   bool        writeQueryResultFile(const string &sResultFile, vector<string> fileList1, vector<string> fileList2, 
                                    dataVec& totVals, const string &sPath, const int idx, const SimTypeList& simName);
   string      getErrorString(){ return errorString; }
   void        setVerbosity(const verbosity verb){m_verbLevel = verb;}
   void        setFieldSeparator(const string FS){m_sFieldSeparator= FS;}
protected:
   string      errorString;
   string      m_sFieldSeparator;
   verbosity   m_verbLevel;
   bool        parseCSVHeader(const char * buf, Signature& sig, uint& key);
   BarPosition getBarPosition(const char * buf, const Signature* pSig);
   uint        getNearestTick(const uint ticks, const uint quant, const uint ticksPerBeat);
   BarPosition quantizeTick(BarPosition bar, const Signature& sig);
   bool        getCombiType(const char *buf, CombiType& combiType, string& combiDisplay, bool &bNeedGauss);
   bool        getMultSimList(const string &sMultType, CombiTypeElement &combiType);

};

#endif
