Tracker: style fixes to SettingsHandler classes

This commit is contained in:
John Scipione
2014-06-20 21:29:34 -04:00
parent 262e7c9368
commit b2ee107be9
2 changed files with 41 additions and 27 deletions
+33 -21
View File
@@ -49,19 +49,24 @@ All rights reserved.
#include "SettingsHandler.h" #include "SettingsHandler.h"
// #pragma mark - ArgvParser
ArgvParser::ArgvParser(const char* name) ArgvParser::ArgvParser(const char* name)
: fFile(0), :
fBuffer(NULL), fFile(0),
fPos(-1), fBuffer(NULL),
fArgc(0), fPos(-1),
fCurrentArgv(0), fArgc(0),
fCurrentArgsPos(-1), fCurrentArgv(0),
fSawBackslash(false), fCurrentArgsPos(-1),
fEatComment(false), fSawBackslash(false),
fInDoubleQuote(false), fEatComment(false),
fInSingleQuote(false), fInDoubleQuote(false),
fLineNo(0), fInSingleQuote(false),
fFileName(name) fLineNo(0),
fFileName(name)
{ {
fFile = fopen(fFileName, "r"); fFile = fopen(fFileName, "r");
if (!fFile) { if (!fFile) {
@@ -103,12 +108,12 @@ ArgvParser::SendArgv(ArgvHandler argvHandlerFunc, void* passThru)
NextArgv(); NextArgv();
fCurrentArgv[fArgc] = 0; fCurrentArgv[fArgc] = 0;
const char* result = (argvHandlerFunc)(fArgc, fCurrentArgv, passThru); const char* result = (argvHandlerFunc)(fArgc, fCurrentArgv, passThru);
if (result) { if (result != NULL) {
printf("File %s; Line %" B_PRId32 " # %s", fFileName, fLineNo, printf("File %s; Line %" B_PRId32 " # %s", fFileName, fLineNo,
result); result);
} }
MakeArgvEmpty(); MakeArgvEmpty();
if (result) if (result != NULL)
return B_ERROR; return B_ERROR;
} }
@@ -154,6 +159,7 @@ ArgvParser::GetCh()
return EOF; return EOF;
fPos = 0; fPos = 0;
} }
return fBuffer[fPos++]; return fBuffer[fPos++];
} }
@@ -163,6 +169,7 @@ ArgvParser::EachArgv(const char* name, ArgvHandler argvHandlerFunc,
void* passThru) void* passThru)
{ {
ArgvParser parser(name); ArgvParser parser(name);
return parser.EachArgvPrivate(name, argvHandlerFunc, passThru); return parser.EachArgvPrivate(name, argvHandlerFunc, passThru);
} }
@@ -256,8 +263,12 @@ ArgvParser::EachArgvPrivate(const char* name, ArgvHandler argvHandlerFunc,
} }
// #pragma mark - SettingsArgvDispatcher
SettingsArgvDispatcher::SettingsArgvDispatcher(const char* name) SettingsArgvDispatcher::SettingsArgvDispatcher(const char* name)
: name(name) :
name(name)
{ {
} }
@@ -319,12 +330,13 @@ SettingsArgvDispatcher::WriteRectValue(Settings* setting, BRect rect)
Settings::Settings(const char* filename, const char* settingsDirName) Settings::Settings(const char* filename, const char* settingsDirName)
: fFileName(filename), :
fSettingsDir(settingsDirName), fFileName(filename),
fList(0), fSettingsDir(settingsDirName),
fCount(0), fList(0),
fListSize(30), fCount(0),
fCurrentSettings(0) fListSize(30),
fCurrentSettings(0)
{ {
fList = (SettingsArgvDispatcher**)calloc((size_t)fListSize, fList = (SettingsArgvDispatcher**)calloc((size_t)fListSize,
sizeof(SettingsArgvDispatcher*)); sizeof(SettingsArgvDispatcher*));
+8 -6
View File
@@ -31,8 +31,8 @@ of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders. names are registered trademarks or trademarks of their respective holders.
All rights reserved. All rights reserved.
*/ */
#ifndef __SETTINGS_FILE__ #ifndef _SETTINGS_FILE_H
#define __SETTINGS_FILE__ #define _SETTINGS_FILE_H
#include <SupportDefs.h> #include <SupportDefs.h>
@@ -56,6 +56,7 @@ typedef const char* (*ArgvHandler)(int argc, const char* const *argv,
const int32 kBufferSize = 1024; const int32 kBufferSize = 1024;
class ArgvParser { class ArgvParser {
// this class opens a text file and passes the context in argv // this class opens a text file and passes the context in argv
// format to a specified handler // format to a specified handler
@@ -101,6 +102,7 @@ private:
const char* fFileName; const char* fFileName;
}; };
class SettingsArgvDispatcher { class SettingsArgvDispatcher {
// base class for a single setting item // base class for a single setting item
public: public:
@@ -127,8 +129,7 @@ protected:
// override this to save the current value of this setting in a // override this to save the current value of this setting in a
// text format // text format
virtual bool NeedsSaving() const virtual bool NeedsSaving() const { return true; }
{ return true; }
// override to return false if current value is equal to the default // override to return false if current value is equal to the default
// and does not need saving // and does not need saving
@@ -169,8 +170,9 @@ private:
BFile* fCurrentSettings; BFile* fCurrentSettings;
}; };
} } // namespace BPrivate
using namespace BPrivate; using namespace BPrivate;
#endif // __SETTINGS_FILE__
#endif // _SETTINGS_FILE_H