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"
// #pragma mark - ArgvParser
ArgvParser::ArgvParser(const char* name)
: fFile(0),
fBuffer(NULL),
fPos(-1),
fArgc(0),
fCurrentArgv(0),
fCurrentArgsPos(-1),
fSawBackslash(false),
fEatComment(false),
fInDoubleQuote(false),
fInSingleQuote(false),
fLineNo(0),
fFileName(name)
:
fFile(0),
fBuffer(NULL),
fPos(-1),
fArgc(0),
fCurrentArgv(0),
fCurrentArgsPos(-1),
fSawBackslash(false),
fEatComment(false),
fInDoubleQuote(false),
fInSingleQuote(false),
fLineNo(0),
fFileName(name)
{
fFile = fopen(fFileName, "r");
if (!fFile) {
@@ -103,12 +108,12 @@ ArgvParser::SendArgv(ArgvHandler argvHandlerFunc, void* passThru)
NextArgv();
fCurrentArgv[fArgc] = 0;
const char* result = (argvHandlerFunc)(fArgc, fCurrentArgv, passThru);
if (result) {
if (result != NULL) {
printf("File %s; Line %" B_PRId32 " # %s", fFileName, fLineNo,
result);
}
MakeArgvEmpty();
if (result)
if (result != NULL)
return B_ERROR;
}
@@ -154,6 +159,7 @@ ArgvParser::GetCh()
return EOF;
fPos = 0;
}
return fBuffer[fPos++];
}
@@ -163,6 +169,7 @@ ArgvParser::EachArgv(const char* name, ArgvHandler argvHandlerFunc,
void* passThru)
{
ArgvParser parser(name);
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)
: name(name)
:
name(name)
{
}
@@ -319,12 +330,13 @@ SettingsArgvDispatcher::WriteRectValue(Settings* setting, BRect rect)
Settings::Settings(const char* filename, const char* settingsDirName)
: fFileName(filename),
fSettingsDir(settingsDirName),
fList(0),
fCount(0),
fListSize(30),
fCurrentSettings(0)
:
fFileName(filename),
fSettingsDir(settingsDirName),
fList(0),
fCount(0),
fListSize(30),
fCurrentSettings(0)
{
fList = (SettingsArgvDispatcher**)calloc((size_t)fListSize,
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.
All rights reserved.
*/
#ifndef __SETTINGS_FILE__
#define __SETTINGS_FILE__
#ifndef _SETTINGS_FILE_H
#define _SETTINGS_FILE_H
#include <SupportDefs.h>
@@ -56,6 +56,7 @@ typedef const char* (*ArgvHandler)(int argc, const char* const *argv,
const int32 kBufferSize = 1024;
class ArgvParser {
// this class opens a text file and passes the context in argv
// format to a specified handler
@@ -101,6 +102,7 @@ private:
const char* fFileName;
};
class SettingsArgvDispatcher {
// base class for a single setting item
public:
@@ -127,8 +129,7 @@ protected:
// override this to save the current value of this setting in a
// text format
virtual bool NeedsSaving() const
{ return true; }
virtual bool NeedsSaving() const { return true; }
// override to return false if current value is equal to the default
// and does not need saving
@@ -169,8 +170,9 @@ private:
BFile* fCurrentSettings;
};
}
} // namespace BPrivate
using namespace BPrivate;
#endif // __SETTINGS_FILE__
#endif // _SETTINGS_FILE_H