stil.h
/*
* This file is part of libsidplayfp, a SID player engine.
*
* Copyright 1998, 2002 by LaLa <LaLa@C64.org>
* Copyright 2012-2013 Leandro Nini <drfiemost@users.sourceforge.net>
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef STIL_H
#define STIL_H
#include <string>
#include <algorithm>
#include <map>
#include <iosfwd>
#include "stildefs.h"
class STIL_EXTERN STIL
{
public:
enum STILField
{
all,
name,
author,
title,
artist,
comment
};
enum STILerror
{
NO_STIL_ERROR = 0,
BUG_OPEN,
WRONG_DIR,
NOT_IN_STIL,
NOT_IN_BUG,
WRONG_ENTRY,
CRITICAL_STIL_ERROR = 10,
BASE_DIR_LENGTH,
STIL_OPEN,
NO_EOL,
NO_STIL_DIRS,
NO_BUG_DIRS
};
bool STIL_DEBUG;
//----//
STIL(const char *stilPath = DEFAULT_PATH_TO_STIL, const char *bugsPath = DEFAULT_PATH_TO_BUGLIST);
const char *getVersion();
float getVersionNo();
bool setBaseDir(const char *pathToHVSC);
float getSTILVersionNo();
const char *getEntry(const char *relPathToEntry, int tuneNo = 0, STILField field = all);
const char *getAbsEntry(const char *absPathToEntry, int tuneNo = 0, STILField field = all);
const char *getGlobalComment(const char *relPathToEntry);
const char *getAbsGlobalComment(const char *absPathToEntry);
const char *getBug(const char *relPathToEntry, int tuneNo = 0);
const char *getAbsBug(const char *absPathToEntry, int tuneNo = 0);
inline STILerror getError() const {return (lastError);}
inline bool hasCriticalError() const
{
return ((lastError >= CRITICAL_STIL_ERROR) ? true : false);
}
inline const char *getErrorStr() const {return (STIL_ERROR_STR[lastError]);}
private:
typedef std::map<std::string, std::streampos> dirList;
const char *PATH_TO_STIL;
const char *PATH_TO_BUGLIST;
std::string versionString;
float STILVersion;
std::string baseDir;
dirList stilDirs;
dirList bugDirs;
char STIL_EOL;
char STIL_EOL2;
STILerror lastError;
static const char *STIL_ERROR_STR[];
std::string entrybuf;
std::string globalbuf;
std::string bugbuf;
std::string resultEntry;
std::string resultBug;
void setVersionString();
bool determineEOL(std::ifstream &stilFile);
bool getDirs(std::ifstream &inFile, dirList &dirs, bool isSTILFile);
bool positionToEntry(const char *entryStr, std::ifstream &inFile, dirList &dirs);
void readEntry(std::ifstream &inFile, std::string &buffer);
bool getField(std::string &result, const char *buffer, int tuneNo = 0, STILField field = all);
bool getOneField(std::string &result, const char *start, const char *end, STILField field);
void getStilLine(std::ifstream &infile, std::string &line);
private:
static void convertSlashes(std::string &str) { std::replace(str.begin(), str.end(), '/', SLASH); }
static void convertToSlashes(std::string &str) { std::replace(str.begin(), str.end(), SLASH, '/'); }
};
#endif // STIL_H
STIL::getError
STILerror getError() const
Definition: stil.h:246
STIL
Definition: stil.h:45
STIL::BASE_DIR_LENGTH
The length of the HVSC base dir was wrong (empty string?)
Definition: stil.h:70
STIL::STIL_DEBUG
bool STIL_DEBUG
To turn debug output on.
Definition: stil.h:78
STIL::NO_EOL
Failed to determine EOL char(s).
Definition: stil.h:72
STIL::BUG_OPEN
INFO ONLY: failed to open BUGlist.txt.
Definition: stil.h:64
STIL::NOT_IN_STIL
INFO ONLY: requested entry was not found in STIL.txt.
Definition: stil.h:66
STIL::WRONG_DIR
INFO ONLY: path was not within HVSC base dir.
Definition: stil.h:65
STIL::WRONG_ENTRY
INFO ONLY: section-global comment was asked for with get*Entry().
Definition: stil.h:68
STIL::getErrorStr
const char * getErrorStr() const
Definition: stil.h:268
STIL::STILerror
STILerror
Enum that describes the possible errors this class may encounter.
Definition: stil.h:61
STIL::hasCriticalError
bool hasCriticalError() const
Definition: stil.h:255
STIL::NOT_IN_BUG
INFO ONLY: requested entry was not found in BUGlist.txt.
Definition: stil.h:67
STIL::STILField
STILField
Enum to use for asking for specific fields.
Definition: stil.h:50
STIL::NO_STIL_DIRS
Failed to get sections (subdirs) when parsing STIL.txt.
Definition: stil.h:73
STIL::STIL_OPEN
Failed to open STIL.txt.
Definition: stil.h:71