Clean up code formatting with clang-format; add a custom clang-format style that tries to approximate the existing OST code style

This commit is contained in:
Brian Cox 2018-03-24 21:28:30 -07:00
parent 184b260d9f
commit ccf8a62fa4
423 changed files with 25182 additions and 25131 deletions

115
.clang-format Normal file
View File

@ -0,0 +1,115 @@
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
RawStringFormats:
- Delimiter: pb
Language: TextProto
BasedOnStyle: google
ReflowComments: false
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 4
UseTab: Never
...

View File

@ -1,2 +1 @@
#define BUILD_NUM _T("0") #define BUILD_NUM _T("0")

View File

@ -200,7 +200,10 @@ int32 cArchive::GetStorageSize(const TSTRING& str)
int64 cArchive::Copy(cArchive* pFrom, int64 amt) int64 cArchive::Copy(cArchive* pFrom, int64 amt)
{ {
enum { BUF_SIZE = 2048 }; enum
{
BUF_SIZE = 2048
};
int8 buf[BUF_SIZE]; int8 buf[BUF_SIZE];
int64 amtLeft = amt; int64 amtLeft = amt;
@ -288,8 +291,7 @@ void cMemMappedArchive::SetNewMap(void* pMap, int64 offset, int64 length) const
// mapped. // mapped.
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
cMemoryArchive::cMemoryArchive(int maxSize) cMemoryArchive::cMemoryArchive(int maxSize) : mMaxAllocatedLen(maxSize)
: mMaxAllocatedLen(maxSize)
{ {
ASSERT(maxSize > 0); ASSERT(maxSize > 0);
mpMemory = 0; mpMemory = 0;
@ -321,11 +323,13 @@ void cMemoryArchive::Seek(int64 offset, SeekFrom from) // throw(eArchive)
offset = mLogicalSize + (int)offset; offset = mLogicalSize + (int)offset;
break; break;
default: default:
ThrowAndAssert(eArchiveSeek(TSS_GetString( cCore, core::STR_MEMARCHIVE_FILENAME), TSS_GetString( cCore, core::STR_MEMARCHIVE_ERRSTR))); ThrowAndAssert(eArchiveSeek(TSS_GetString(cCore, core::STR_MEMARCHIVE_FILENAME),
TSS_GetString(cCore, core::STR_MEMARCHIVE_ERRSTR)));
} }
if (offset > mLogicalSize) if (offset > mLogicalSize)
ThrowAndAssert(eArchiveSeek(TSS_GetString( cCore, core::STR_MEMARCHIVE_FILENAME), TSS_GetString( cCore, core::STR_MEMARCHIVE_ERRSTR))); ThrowAndAssert(eArchiveSeek(TSS_GetString(cCore, core::STR_MEMARCHIVE_FILENAME),
TSS_GetString(cCore, core::STR_MEMARCHIVE_ERRSTR)));
mReadHead = static_cast<int>(offset); mReadHead = static_cast<int>(offset);
} }
@ -464,17 +468,11 @@ public:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// cFixedMemArchive // cFixedMemArchive
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
cFixedMemArchive::cFixedMemArchive() cFixedMemArchive::cFixedMemArchive() : mpMemory(0), mSize(0), mReadHead(0)
: mpMemory (0),
mSize (0),
mReadHead (0)
{ {
} }
cFixedMemArchive::cFixedMemArchive( int8* pMem, int32 size ) cFixedMemArchive::cFixedMemArchive(int8* pMem, int32 size) : mpMemory(0), mSize(0), mReadHead(0)
: mpMemory (0),
mSize (0),
mReadHead (0)
{ {
Attach(pMem, size); Attach(pMem, size);
} }
@ -503,11 +501,13 @@ void cFixedMemArchive::Seek(int64 offset, SeekFrom from) // throw(eArchive)
offset = mSize + (int)offset; offset = mSize + (int)offset;
break; break;
default: default:
ThrowAndAssert(eArchiveSeek(TSS_GetString( cCore, core::STR_MEMARCHIVE_FILENAME), TSS_GetString( cCore, core::STR_MEMARCHIVE_ERRSTR))); ThrowAndAssert(eArchiveSeek(TSS_GetString(cCore, core::STR_MEMARCHIVE_FILENAME),
TSS_GetString(cCore, core::STR_MEMARCHIVE_ERRSTR)));
} }
if (offset > mSize) if (offset > mSize)
ThrowAndAssert(eArchiveSeek(TSS_GetString( cCore, core::STR_MEMARCHIVE_FILENAME), TSS_GetString( cCore, core::STR_MEMARCHIVE_ERRSTR))); ThrowAndAssert(eArchiveSeek(TSS_GetString(cCore, core::STR_MEMARCHIVE_FILENAME),
TSS_GetString(cCore, core::STR_MEMARCHIVE_ERRSTR)));
mReadHead = static_cast<int32>(offset); mReadHead = static_cast<int32>(offset);
} }
@ -566,11 +566,9 @@ int cFixedMemArchive::Write(const void* pDest, int count) // throw(eArchive)
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
//Ctor -- Initialize member variables to 0 or NULL equivalents. //Ctor -- Initialize member variables to 0 or NULL equivalents.
cFileArchive::cFileArchive() : cFileArchive::cFileArchive() : mFileSize(0), mReadHead(0), isWritable(false)
mFileSize(0), {
mReadHead(0), }
isWritable(false)
{}
cFileArchive::~cFileArchive() cFileArchive::~cFileArchive()
{ {
@ -734,13 +732,13 @@ int cFileArchive::Read(void* pDest, int count)
if (pDest != NULL) if (pDest != NULL)
{ {
int nbRead = int nbRead = static_cast<int>(mCurrentFile.Read(pDest, count));
static_cast<int>( mCurrentFile.Read( pDest, count ) );
// 'count' may not be equal to 'nbRead' if the file is open in // 'count' may not be equal to 'nbRead' if the file is open in
// text mode. // text mode.
count = nbRead; count = nbRead;
if(count < 0) count = 0; if (count < 0)
count = 0;
} }
else else
{ {
@ -765,7 +763,6 @@ int cFileArchive::Read(void* pDest, int count)
{ {
throw(eArchiveRead(mCurrentFilename, fileError.GetDescription())); throw(eArchiveRead(mCurrentFilename, fileError.GetDescription()));
} }
} }
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
@ -793,7 +790,7 @@ int cFileArchive::Write(const void* pDest, int count) // throw(eArchive)
// increase the size, if needed // increase the size, if needed
if (mReadHead > mFileSize) if (mReadHead > mFileSize)
{ {
#if 0 // IS_SUNPRO #if 0 // IS_SUNPRO \
// These two lines seem to be all there is between code that crashes and code that works for sunpro // These two lines seem to be all there is between code that crashes and code that works for sunpro
cDebug d("cFileArchive::Write()"); cDebug d("cFileArchive::Write()");
d.TraceDebug(_T("file(%s) adjusted mFileSize = %d mReadHead = %d\n"), mCurrentFilename.c_str(), (int)mFileSize, (int)mReadHead); d.TraceDebug(_T("file(%s) adjusted mFileSize = %d mReadHead = %d\n"), mCurrentFilename.c_str(), (int)mFileSize, (int)mReadHead);
@ -832,7 +829,6 @@ void cFileArchive::Truncate() // throw(eArchive)
} }
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// OpenReadWrite -- Opens the file to be read or written to // OpenReadWrite -- Opens the file to be read or written to
// //
@ -842,7 +838,8 @@ void cLockedTemporaryFileArchive::OpenReadWrite( const TCHAR* filename, uint32 o
{ {
TSTRING strTempFile; TSTRING strTempFile;
try { try
{
ASSERT(!mCurrentFile.IsOpen()); // shouldn't be able to create a new file when we're already open ASSERT(!mCurrentFile.IsOpen()); // shouldn't be able to create a new file when we're already open
if (mCurrentFile.IsOpen()) if (mCurrentFile.IsOpen())
@ -891,7 +888,8 @@ void cLockedTemporaryFileArchive::OpenReadWrite( const TCHAR* filename, uint32 o
#endif #endif
} //try } //try
catch (eFile& fileError) { catch (eFile& fileError)
{
TSTRING errStr = TSS_GetString(cCore, core::STR_BAD_TEMPDIRECTORY); TSTRING errStr = TSS_GetString(cCore, core::STR_BAD_TEMPDIRECTORY);
eArchiveOpen e(strTempFile, errStr); eArchiveOpen e(strTempFile, errStr);
throw e; throw e;
@ -907,4 +905,3 @@ void cLockedTemporaryFileArchive::Close()
// Note: this deletes the file as well // Note: this deletes the file as well
cFileArchive::Close(); cFileArchive::Close();
} }

View File

@ -85,7 +85,9 @@ TSS_EXCEPTION( eArchiveStringTooLong, eArchive );
class cArchive class cArchive
{ {
public: public:
virtual ~cArchive() {} virtual ~cArchive()
{
}
// convenience methods // convenience methods
// //
@ -137,7 +139,8 @@ protected:
class cBidirArchive : public cArchive class cBidirArchive : public cArchive
{ {
public: public:
enum SeekFrom { enum SeekFrom
{
BEGINNING = 0, BEGINNING = 0,
CURRENT = 1, CURRENT = 1,
END = -1 END = -1
@ -155,7 +158,8 @@ public:
class cMemMappedArchive : public cBidirArchive class cMemMappedArchive : public cBidirArchive
{ {
public: public:
enum { enum
{
MAP_TO_EOF = -1 MAP_TO_EOF = -1
}; };
@ -202,7 +206,10 @@ public:
void Truncate(); // set the length to the current pos void Truncate(); // set the length to the current pos
int8* GetMemory() const { return mpMemory; } int8* GetMemory() const
{
return mpMemory;
}
protected: protected:
int8* mpMemory; int8* mpMemory;
@ -238,6 +245,7 @@ public:
virtual int64 CurrentPos() const; virtual int64 CurrentPos() const;
virtual int64 Length() const; virtual int64 Length() const;
virtual bool EndOfFile(); virtual bool EndOfFile();
protected: protected:
//----------------------------------- //-----------------------------------
// cArchive interface // cArchive interface
@ -320,9 +328,12 @@ public:
private: private:
// open for read only makes no sense if we're always creating the file, // open for read only makes no sense if we're always creating the file,
// so disallow read only file opens // so disallow read only file opens
virtual void OpenRead( const TCHAR*, uint32 openFlags = 0 ) { ASSERT( false ); THROW_INTERNAL("archive.h"); } virtual void OpenRead(const TCHAR*, uint32 openFlags = 0)
{
ASSERT(false);
THROW_INTERNAL("archive.h");
}
}; };
#endif #endif

View File

@ -149,5 +149,3 @@ bool cCharUtil::PopNextChar( TSTRING::const_iterator& cur,
return f; return f;
} }

View File

@ -44,8 +44,6 @@
class cCharUtil class cCharUtil
{ {
public: public:
// finds the next whole character in string identified by ['cur'-'end') // finds the next whole character in string identified by ['cur'-'end')
// identifies beginning of char in 'first', then end of character in 'last' // identifies beginning of char in 'first', then end of character in 'last'
// returns 'are there more characters in string?' // returns 'are there more characters in string?'
@ -63,4 +61,3 @@ public:
}; };
#endif //__CHARUTIL_H #endif //__CHARUTIL_H

View File

@ -38,9 +38,7 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// ctor, dotr // ctor, dotr
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
cCmdLineParser::cCmdLineParser() : cCmdLineParser::cCmdLineParser() : mArgTable(HASH_VERY_SMALL), mLastArgInfo(-1, PARAM_NONE)
mArgTable(HASH_VERY_SMALL),
mLastArgInfo(-1, PARAM_NONE)
{ {
} }
@ -51,7 +49,8 @@ cCmdLineParser::~cCmdLineParser()
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// AddArg // AddArg
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void cCmdLineParser::AddArg(int argId, const TSTRING& arg, const TSTRING& alias, ParamCount numParams, bool multipleAllowed) void cCmdLineParser::AddArg(
int argId, const TSTRING& arg, const TSTRING& alias, ParamCount numParams, bool multipleAllowed)
{ {
if (arg.empty() && alias.empty()) if (arg.empty() && alias.empty())
{ {
@ -110,9 +109,7 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
if (!mArgTable.Lookup(TSTRING(&argv[i][1]), argInfo)) if (!mArgTable.Lookup(TSTRING(&argv[i][1]), argInfo))
{ {
// unknown switch! // unknown switch!
throw eCmdLineInvalidArg( throw eCmdLineInvalidArg(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + pCurArg);
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
+ pCurArg );
} }
// //
// make sure this hasn't been specified yet... // make sure this hasn't been specified yet...
@ -124,9 +121,7 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
if (it == mMultipleAllowed.end()) if (it == mMultipleAllowed.end())
{ {
// It wasn't in our list of allowed params, so error. // It wasn't in our list of allowed params, so error.
throw eCmdLineMultiArg( throw eCmdLineMultiArg(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + argv[i]);
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
+ argv[i] );
} }
} }
// //
@ -149,9 +144,7 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
if (argv[j][0] == _T('-')) if (argv[j][0] == _T('-'))
{ {
// >0 parameter passed ! // >0 parameter passed !
throw eCmdLineBadParam( throw eCmdLineBadParam(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + pCurArg);
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
+ pCurArg );
} }
} }
} }
@ -163,9 +156,7 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
if ((i >= argc) || (argv[i][0] == _T('-'))) if ((i >= argc) || (argv[i][0] == _T('-')))
{ {
// zero parameters passed to something that needed one param // zero parameters passed to something that needed one param
throw eCmdLineBadParam( throw eCmdLineBadParam(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + pCurArg);
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
+ pCurArg );
} }
curArg.mParams.push_back(TSTRING(argv[i])); curArg.mParams.push_back(TSTRING(argv[i]));
@ -207,7 +198,6 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
break; break;
default: default:
ASSERT(false); ASSERT(false);
} }
if (!bResult) if (!bResult)
{ {
@ -224,16 +214,12 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
{ {
if (!pCurArg) if (!pCurArg)
{ {
throw eCmdLineBadSwitchPos( throw eCmdLineBadSwitchPos(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + argv[i]);
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
+ argv[i] );
} }
else else
{ {
// there was an extra parameter passed somewhere! // there was an extra parameter passed somewhere!
throw eCmdLineBadArgParam( throw eCmdLineBadArgParam(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + pCurArg);
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
+ pCurArg );
} }
} }
@ -241,10 +227,7 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
curArg.mParams.push_back(TSTRING(argv[i])); curArg.mParams.push_back(TSTRING(argv[i]));
i++; i++;
} }
} }
} }
// it is possible not to process the final command line parameters in the "else" case above // it is possible not to process the final command line parameters in the "else" case above
@ -283,14 +266,10 @@ void cCmdLineParser::TestMutEx()
if (!iter2.Done()) if (!iter2.Done())
{ {
// we have a mutual exclusion violation! // we have a mutual exclusion violation!
throw eCmdLineMutEx( throw eCmdLineMutEx(iter1.ActualParam() + _T(", ") + iter2.ActualParam());
iter1.ActualParam()
+ _T(", ")
+ iter2.ActualParam() );
} }
} }
} }
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -467,6 +446,4 @@ bool cCmdLineIter::SeekToArg(int argId) const
} }
return false; return false;
} }

View File

@ -52,7 +52,8 @@
TSS_EXCEPTION(eCmdLine, eError) TSS_EXCEPTION(eCmdLine, eError)
TSS_EXCEPTION(eCmdLineInvalidArg, eCmdLine) // an arg on the command line is not recognized TSS_EXCEPTION(eCmdLineInvalidArg, eCmdLine) // an arg on the command line is not recognized
TSS_EXCEPTION(eCmdLineBadArgParam, eCmdLine) // wrong number of parameters to an argument TSS_EXCEPTION(eCmdLineBadArgParam, eCmdLine) // wrong number of parameters to an argument
TSS_EXCEPTION( eCmdLineBadParam, eCmdLine ) // wrong number of paramters to the executable (not associated with any arguments) TSS_EXCEPTION(eCmdLineBadParam,
eCmdLine) // wrong number of paramters to the executable (not associated with any arguments)
TSS_EXCEPTION(eCmdLineBadSwitchPos, eCmdLine) // a '-' arg appeared after the final parameter list TSS_EXCEPTION(eCmdLineBadSwitchPos, eCmdLine) // a '-' arg appeared after the final parameter list
TSS_EXCEPTION(eCmdLineMutEx, eCmdLine) // a mutual exclusion error has occured TSS_EXCEPTION(eCmdLineMutEx, eCmdLine) // a mutual exclusion error has occured
TSS_EXCEPTION(eCmdLineDependency, eCmdLine) // a dependency error has occurred. TSS_EXCEPTION(eCmdLineDependency, eCmdLine) // a dependency error has occurred.
@ -102,7 +103,8 @@ public:
PARAM_INVALID // top of enum PARAM_INVALID // top of enum
}; };
void AddArg(int argId, const TSTRING& arg, const TSTRING& alias, ParamCount numParams, bool multipleAllowed = false); void
AddArg(int argId, const TSTRING& arg, const TSTRING& alias, ParamCount numParams, bool multipleAllowed = false);
// this method should be called for each argument that can appear on the // this method should be called for each argument that can appear on the
// command line. // command line.
// argId -- a number that uniquely identifies the argument; no two arguments // argId -- a number that uniquely identifies the argument; no two arguments
@ -158,7 +160,9 @@ private:
int mId; int mId;
ParamCount mNumParams; ParamCount mNumParams;
cArgInfo(int i = -1, ParamCount p = PARAM_INVALID) : mId(i), mNumParams(p) {} cArgInfo(int i = -1, ParamCount p = PARAM_INVALID) : mId(i), mNumParams(p)
{
}
}; };
// for storing parsed argv information // for storing parsed argv information
struct cArgData struct cArgData
@ -167,11 +171,14 @@ private:
std::vector<TSTRING> mParams; std::vector<TSTRING> mParams;
TSTRING mActualParam; // a string representation of what was actually on the command line TSTRING mActualParam; // a string representation of what was actually on the command line
cArgData(int id = -1, const TSTRING& actualParam = TSTRING(_T(""))) : mId(id), mActualParam(actualParam) {} cArgData(int id = -1, const TSTRING& actualParam = TSTRING(_T(""))) : mId(id), mActualParam(actualParam)
{
}
}; };
cHashTable<TSTRING, cArgInfo> mArgTable; cHashTable<TSTRING, cArgInfo> mArgTable;
cArgInfo mLastArgInfo; // info on the argument that comes at the end of the command line (with no associated '-x' or '--x') cArgInfo
mLastArgInfo; // info on the argument that comes at the end of the command line (with no associated '-x' or '--x')
std::list<cArgData> mArgData; std::list<cArgData> mArgData;
std::list<std::pair<int, int> > mMutExList; // all of the mutual exclusions std::list<std::pair<int, int> > mMutExList; // all of the mutual exclusions
std::list<std::pair<std::pair<int, int>, bool> > mDependencyList; // all of the dependencies std::list<std::pair<std::pair<int, int>, bool> > mDependencyList; // all of the dependencies
@ -218,8 +225,7 @@ private:
//############################################################################# //#############################################################################
// inline implementation // inline implementation
//############################################################################# //#############################################################################
inline cCmdLineIter::cCmdLineIter(const cCmdLineParser& parser) : inline cCmdLineIter::cCmdLineIter(const cCmdLineParser& parser) : mList(parser.mArgData)
mList(parser.mArgData)
{ {
SeekBegin(); SeekBegin();
} }
@ -264,4 +270,3 @@ inline const TSTRING& cCmdLineIter::ParamAt(int index) const
#endif #endif

View File

@ -205,7 +205,8 @@ namespace /*Unique*/
d.TraceDebug("ENOMEM: Insufficient storage space is available.\n"); d.TraceDebug("ENOMEM: Insufficient storage space is available.\n");
break; break;
case EINVAL: case EINVAL:
d.TraceDebug( "EINVAL: The conversion specified by fromcode and tocode is not supported by the implementation.\n" ); d.TraceDebug("EINVAL: The conversion specified by fromcode and tocode is not supported by the "
"implementation.\n");
break; break;
default: default:
d.TraceDebug("UNKNOWN: Unknown error.\n"); d.TraceDebug("UNKNOWN: Unknown error.\n");
@ -221,48 +222,34 @@ namespace /*Unique*/
// [EINVAL] Input conversion stopped due to an incomplete character // [EINVAL] Input conversion stopped due to an incomplete character
// [EBADF] The cd argument is not a valid open conversion descriptor. // [EBADF] The cd argument is not a valid open conversion descriptor.
// errno // errno
d.TraceDebug( d.TraceDebug(_T( "iconv failed with: %s\n" ), iFSServices::GetInstance()->GetErrString().c_str());
_T( "iconv failed with: %s\n" ),
iFSServices::GetInstance()->GetErrString().c_str() );
/// RAD: Always throw on error (Let user Catch if they want to go on) /// RAD: Always throw on error (Let user Catch if they want to go on)
switch (errno) switch (errno)
{ {
case EILSEQ: case EILSEQ:
case EINVAL: case EINVAL:
throw throw eConverterFatal(TSS_GetString(cCore, core::STR_ERR_BADCHAR));
eConverterFatal (
TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
break; break;
case E2BIG: case E2BIG:
throw throw eConverterFatal(TSS_GetString(cCore, core::STR_ERR_OVERFLOW));
eConverterFatal(
TSS_GetString(cCore, core::STR_ERR_OVERFLOW ) );
break; break;
case EBADF: case EBADF:
throw throw eConverterUnknownCodepage(TSS_GetString(cCore, core::STR_UNKNOWN));
eConverterUnknownCodepage(
TSS_GetString( cCore, core::STR_UNKNOWN ) );
break; break;
default: default:
throw throw eConverterFatal(TSS_GetString(cCore, core::STR_UNKNOWN));
eConverterFatal(
TSS_GetString( cCore, core::STR_UNKNOWN ) );
} }
return -1; return -1;
} }
template< class BufferT, class SourceT > template<class BufferT, class SourceT> class ByteConvert
class ByteConvert
{ {
public: public:
bool Convert(BufferT** ppBuf, size_t* pnBufferLeft, const SourceT** ppSrc, size_t* pnSourceLeft)
bool
Convert( BufferT** ppBuf, size_t* pnBufferLeft,
const SourceT** ppSrc, size_t* pnSourceLeft )
{ {
cDebug d("ByteConvert::Convert< BufferT, SourceT >()"); cDebug d("ByteConvert::Convert< BufferT, SourceT >()");
@ -285,21 +272,21 @@ namespace /*Unique*/
class UTF8_Util class UTF8_Util
{ {
public: public:
enum { INVALID_VALUE = 0xFF }; enum
{
INVALID_VALUE = 0xFF
};
}; };
// convert to INVALID_VALUE and remember the byte value // convert to INVALID_VALUE and remember the byte value
template< class BufferT, class SourceT > template<class BufferT, class SourceT> class ToUTF8Convert
class ToUTF8Convert
{ {
public: public:
ToUTF8Convert(std::list<byte>& lb) : m_lb(lb)
{
}
ToUTF8Convert( std::list<byte>& lb ) bool Convert(mbchar_t** ppBuf, size_t* pnBufferLeft, const dbchar_t** ppSrc, size_t* pnSourceLeft)
: m_lb( lb ) {}
bool
Convert( mbchar_t** ppBuf, size_t* pnBufferLeft,
const dbchar_t** ppSrc, size_t* pnSourceLeft )
{ {
cDebug d("ToUTF8Convert::Convert< mbchar_t, dbchar_t >()"); cDebug d("ToUTF8Convert::Convert< mbchar_t, dbchar_t >()");
@ -320,9 +307,7 @@ namespace /*Unique*/
return true; return true;
} }
bool bool Convert(mbchar_t** ppBuf, size_t* pnBufferLeft, const mbchar_t** ppSrc, size_t* pnSourceLeft)
Convert( mbchar_t** ppBuf, size_t* pnBufferLeft,
const mbchar_t** ppSrc, size_t* pnSourceLeft )
{ {
cDebug d("ToUTF8Convert::Convert< char, char >()"); cDebug d("ToUTF8Convert::Convert< char, char >()");
@ -344,23 +329,19 @@ namespace /*Unique*/
} }
private: private:
// TODO:Get rid of this guy and just use a vector<BufferT*,BufferT> and // TODO:Get rid of this guy and just use a vector<BufferT*,BufferT> and
// insert them when finished with second step // insert them when finished with second step
std::list<byte>& m_lb; std::list<byte>& m_lb;
}; };
template< class BufferT, class SourceT > template<class BufferT, class SourceT> class FromUTF8Convert
class FromUTF8Convert
{ {
public: public:
FromUTF8Convert(std::list<byte>& lb) : m_lb(lb)
{
}
FromUTF8Convert( std::list<byte>& lb ) bool Convert(dbchar_t** ppBuf, size_t* pnBufferLeft, const mbchar_t** ppSrc, size_t* pnSourceLeft)
: m_lb( lb ) {}
bool
Convert( dbchar_t** ppBuf, size_t* pnBufferLeft,
const mbchar_t** ppSrc, size_t* pnSourceLeft )
{ {
cDebug d("FromUTF8Convert::Convert< dbchar_t, mbchar_t >()"); cDebug d("FromUTF8Convert::Convert< dbchar_t, mbchar_t >()");
@ -395,9 +376,7 @@ namespace /*Unique*/
// Converts a UTF-8 value to corresponding UCS2 char (in the private // Converts a UTF-8 value to corresponding UCS2 char (in the private
// use range) whose value is 0xE000 < x < 0xE0FF in UCS2. // use range) whose value is 0xE000 < x < 0xE0FF in UCS2.
// Must be of the form 11101110 100000xx 10xxxxxx // Must be of the form 11101110 100000xx 10xxxxxx
bool bool Convert(mbchar_t** ppBuf, size_t* pnBufferLeft, const mbchar_t** ppSrc, size_t* pnSourceLeft)
Convert( mbchar_t** ppBuf, size_t* pnBufferLeft,
const mbchar_t** ppSrc, size_t* pnSourceLeft )
{ {
cDebug d("FromUTF8Convert::Convert< mbchar_t, mbchar_t >()"); cDebug d("FromUTF8Convert::Convert< mbchar_t, mbchar_t >()");
/* /*
@ -486,16 +465,12 @@ namespace /*Unique*/
} }
private: private:
// TODO:Get rid of this guy and just use a vector<BufferT*,BufferT> and // TODO:Get rid of this guy and just use a vector<BufferT*,BufferT> and
// insert them when finished with second step // insert them when finished with second step
std::list<byte>& m_lb; std::list<byte>& m_lb;
}; };
bool bool tss_ReverseConvert(iconv_t revConv, const char* pConvertedFrom, size_t nFrom, char* pConvertedTo, size_t nTo)
tss_ReverseConvert( iconv_t revConv,
const char* pConvertedFrom, size_t nFrom,
char* pConvertedTo, size_t nTo )
{ {
cDebug d("tss_ReverseConvert< B, S, C >()"); cDebug d("tss_ReverseConvert< B, S, C >()");
d.TraceDebug("Converted from: %s\n", util_output_bytes((void*)pConvertedFrom, nFrom).c_str()); d.TraceDebug("Converted from: %s\n", util_output_bytes((void*)pConvertedFrom, nFrom).c_str());
@ -538,26 +513,27 @@ namespace /*Unique*/
return true; return true;
} }
template< class CharT > template<class CharT> bool tss_IsFlaggedCharacter(CharT ch)
bool tss_IsFlaggedCharacter( CharT ch )
{ {
return false; return false;
} }
template<> template<> bool tss_IsFlaggedCharacter<dbchar_t>(dbchar_t wch)
bool tss_IsFlaggedCharacter< dbchar_t >( dbchar_t wch )
{ {
return cConvertUtil::ValueInReservedRange(wch); return cConvertUtil::ValueInReservedRange(wch);
} }
template<class BufferT, class SourceT> template<class BufferT, class SourceT>
int int tss_ConvertOneCharacter(iconv_t convForward,
tss_ConvertOneCharacter( iconv_t convForward,
iconv_t convReverse, iconv_t convReverse,
const char** ppSource, size_t* pnSourceLeft, const char** ppSource,
char** ppBuffer, size_t* pnBufferLeft size_t* pnSourceLeft,
char** ppBuffer,
size_t* pnBufferLeft
# if (!SUPPORTS_EXPLICIT_TEMPLATE_FUNC_INST) # if (!SUPPORTS_EXPLICIT_TEMPLATE_FUNC_INST)
, BufferT /*dummy*/, SourceT /*dummy*/ ,
BufferT /*dummy*/,
SourceT /*dummy*/
# endif # endif
) )
{ {
@ -576,9 +552,7 @@ namespace /*Unique*/
//-- Try to find the number of items needed to get a complete character //-- Try to find the number of items needed to get a complete character
size_t nSrcTry; size_t nSrcTry;
for( nSrcTry = sizeof( SourceT ); for (nSrcTry = sizeof(SourceT); nSrcTry <= *pnBufferLeft && nSrcTry <= MB_LEN_MAX; nSrcTry += sizeof(SourceT))
nSrcTry <= *pnBufferLeft && nSrcTry <= MB_LEN_MAX;
nSrcTry += sizeof( SourceT ) )
{ {
size_t nSrcLeft = nSrcTry; size_t nSrcLeft = nSrcTry;
size_t nBufLeft = *pnBufferLeft; // Try to find a character in 'n' items size_t nBufLeft = *pnBufferLeft; // Try to find a character in 'n' items
@ -608,12 +582,7 @@ namespace /*Unique*/
} }
else else
{ {
if( tss_ReverseConvert( if (tss_ReverseConvert(convReverse, *ppSource, pSrc - *ppSource, *ppBuffer, pBuf - *ppBuffer))
convReverse,
*ppSource,
pSrc - *ppSource,
*ppBuffer,
pBuf - *ppBuffer ) )
{ {
// Modify source items to return // Modify source items to return
@ -648,11 +617,12 @@ namespace /*Unique*/
// NOTE: pBuffer should really have (nBufferItems+1) buffer items, because some // NOTE: pBuffer should really have (nBufferItems+1) buffer items, because some
// platforms use the last character to NULL terminate. // platforms use the last character to NULL terminate.
template<class BufferT, class SourceT, class ConvT> template<class BufferT, class SourceT, class ConvT>
int int tss_Converter(iconv_t convForward,
tss_Converter( iconv_t convForward,
iconv_t convReverse, iconv_t convReverse,
BufferT* pBuffer, size_t nBufferItems, BufferT* pBuffer,
const SourceT* pSource, size_t nSourceItems, size_t nBufferItems,
const SourceT* pSource,
size_t nSourceItems,
ConvT& ConvertByte) ConvT& ConvertByte)
{ {
cDebug d("tss_Converter< BufferT, SourceT >()"); cDebug d("tss_Converter< BufferT, SourceT >()");
@ -685,7 +655,8 @@ namespace /*Unique*/
size_t nbIconvSrc = (size_t)nSourceLeft; size_t nbIconvSrc = (size_t)nSourceLeft;
size_t nbIconvDest = (size_t)nBufferLeft; size_t nbIconvDest = (size_t)nBufferLeft;
size_t nConv = iconv( convForward, (ICONV_SOURCE_TYPE**)&pIconvSrc, &nbIconvSrc, (char**)&pIconvDest, &nbIconvDest ); size_t nConv =
iconv(convForward, (ICONV_SOURCE_TYPE**)&pIconvSrc, &nbIconvSrc, (char**)&pIconvDest, &nbIconvDest);
if (nConv == -1) if (nConv == -1)
{ {
@ -704,7 +675,9 @@ namespace /*Unique*/
(char**)&pBuf, (char**)&pBuf,
&nBufferLeft &nBufferLeft
# if (!SUPPORTS_EXPLICIT_TEMPLATE_FUNC_INST) # if (!SUPPORTS_EXPLICIT_TEMPLATE_FUNC_INST)
, BufferT(), SourceT() ,
BufferT(),
SourceT()
# endif # endif
); );
} }
@ -738,11 +711,12 @@ namespace /*Unique*/
} }
} }
d.TraceDebug( "buffer out: %s\n", util_output_bytes( (void*)pBuffer, nBufferItems * sizeof(BufferT) - nBufferLeft ).c_str() ); d.TraceDebug("buffer out: %s\n",
util_output_bytes((void*)pBuffer, nBufferItems * sizeof(BufferT) - nBufferLeft).c_str());
return nBufferItems - (nBufferLeft / sizeof(BufferT)); return nBufferItems - (nBufferLeft / sizeof(BufferT));
} }
}//Unique } // namespace
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// cIconvConverter // cIconvConverter
@ -795,10 +769,7 @@ void cIconvConverter::Init()
icFromDb = cIconvUtil::OpenHandle(cIconvUtil::GetCodePageID(), cIconvUtil::GetIconvDbIdentifier()); icFromDb = cIconvUtil::OpenHandle(cIconvUtil::GetCodePageID(), cIconvUtil::GetIconvDbIdentifier());
} }
int int cIconvConverter::Convert(ntmbs_t pbz, size_t nBytes, const_ntdbs_t pwz, size_t nChars)
cIconvConverter::Convert(
ntmbs_t pbz, size_t nBytes,
const_ntdbs_t pwz, size_t nChars )
{ {
cDebug d("cIconvConverter::Convert( ntdbs_t -> ntmbs_t )"); cDebug d("cIconvConverter::Convert( ntdbs_t -> ntmbs_t )");
@ -823,10 +794,7 @@ cIconvConverter::Convert(
return nConverted; return nConverted;
} }
int int cIconvConverter::Convert(ntdbs_t pwz, size_t nch, const_ntmbs_t pbz, size_t nBytes)
cIconvConverter::Convert(
ntdbs_t pwz, size_t nch,
const_ntmbs_t pbz, size_t nBytes )
{ {
cDebug d("cIconvConverter::Convert( ntmbs to ntdbs )"); cDebug d("cIconvConverter::Convert( ntmbs to ntdbs )");
@ -851,13 +819,6 @@ cIconvConverter::Convert(
} }
/* /*
@ -996,10 +957,7 @@ void cDoubleIconvConverter::Init()
icUTF8ToMb = cIconvUtil::OpenHandle(cIconvUtil::GetCodePageID(), cIconvUtil::GetMiddleIdentifier()); icUTF8ToMb = cIconvUtil::OpenHandle(cIconvUtil::GetCodePageID(), cIconvUtil::GetMiddleIdentifier());
} }
int int cDoubleIconvConverter::Convert(ntmbs_t pbz, size_t nBytes, const_ntdbs_t pwz, size_t nChars)
cDoubleIconvConverter::Convert(
ntmbs_t pbz, size_t nBytes,
const_ntdbs_t pwz, size_t nChars )
{ {
cDebug d("cDoubleIconvConverter::Convert( ntdbs_t -> ntmbs_t )"); cDebug d("cDoubleIconvConverter::Convert( ntdbs_t -> ntmbs_t )");
@ -1057,10 +1015,7 @@ cDoubleIconvConverter::Convert(
return nConverted; return nConverted;
} }
int int cDoubleIconvConverter::Convert(ntdbs_t pwz, size_t nch, const_ntmbs_t pbz, size_t nBytes)
cDoubleIconvConverter::Convert(
ntdbs_t pwz, size_t nch,
const_ntmbs_t pbz, size_t nBytes )
{ {
cDebug d("cDoubleIconvConverter::Convert( ntmbs to ntdbs )"); cDebug d("cDoubleIconvConverter::Convert( ntmbs to ntdbs )");
@ -1172,9 +1127,7 @@ void cIconvUtil::ResetConverter( iconv_t ic )
char* p = 0; char* p = 0;
size_t s = 0; size_t s = 0;
size_t i = iconv( ic, size_t i = iconv(ic, (ICONV_SOURCE_TYPE**)&p, &s, &p, &s);
(ICONV_SOURCE_TYPE**) &p,
&s, &p, &s );
if (i == (size_t)-1) if (i == (size_t)-1)
{ {
ASSERT(false); ASSERT(false);
@ -1215,7 +1168,6 @@ bool cIconvUtil::TestConverter( const char* pTo, const char* pFrom )
#endif //TSS_USE_ICONV_CCONV16 #endif //TSS_USE_ICONV_CCONV16
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// cWcharIs32BitUcs2Converterer // cWcharIs32BitUcs2Converterer
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1224,8 +1176,7 @@ namespace /*Unique*/
{ {
//-- Ensures 1-to-1 mb to wide character mapping by doing a reverse conversion //-- Ensures 1-to-1 mb to wide character mapping by doing a reverse conversion
// and comparing the results // and comparing the results
int int tss_mbtowc(wchar_t* pwch, const mbchar_t* pch, size_t nBytes)
tss_mbtowc( wchar_t* pwch, const mbchar_t* pch, size_t nBytes )
{ {
// convert forward // convert forward
int nNarrow = ::mbtowc(pwch, pch, nBytes); int nNarrow = ::mbtowc(pwch, pch, nBytes);
@ -1239,8 +1190,7 @@ namespace /*Unique*/
return -1; return -1;
// compare... // compare...
if( ( nNarrow > (int)nBytes ) || if ((nNarrow > (int)nBytes) || (0 != memcmp(ach, pch, nNarrow)))
( 0 != memcmp( ach, pch, nNarrow ) ) )
return -1; return -1;
// success! // success!
@ -1249,8 +1199,7 @@ namespace /*Unique*/
//-- Ensures 1-to-1 mb to wide character mapping by doing a reverse conversion //-- Ensures 1-to-1 mb to wide character mapping by doing a reverse conversion
// and comparing the results // and comparing the results
int int tss_wctomb(mbchar_t* pch, wchar_t wch)
tss_wctomb( mbchar_t* pch, wchar_t wch )
{ {
// convert forward // convert forward
int nWide = ::wctomb(pch, wch); int nWide = ::wctomb(pch, wch);
@ -1271,8 +1220,7 @@ namespace /*Unique*/
return nWide; return nWide;
} }
int int tss_wcstombs(ntmbs_t pbz, const_ntwcs_t pwz, size_t nCount)
tss_wcstombs( ntmbs_t pbz, const_ntwcs_t pwz, size_t nCount )
{ {
cDebug d("tss_wcstombs"); cDebug d("tss_wcstombs");
@ -1292,8 +1240,7 @@ namespace /*Unique*/
} }
int int tss_mbstowcs(ntwcs_t pwz, const_ntmbs_t pbz, size_t nBytes)
tss_mbstowcs( ntwcs_t pwz, const_ntmbs_t pbz, size_t nBytes )
{ {
cDebug d("tss_mbstowcs"); cDebug d("tss_mbstowcs");
@ -1305,9 +1252,7 @@ namespace /*Unique*/
N = tss_mbtowc(pwz, pbz, end - pbz); N = tss_mbtowc(pwz, pbz, end - pbz);
if (N == (size_t)-1) if (N == (size_t)-1)
{ {
d.TraceDebug( d.TraceDebug("manually converting %X...\n", cConvertUtil::ConvertNonChar(*pbz));
"manually converting %X...\n",
cConvertUtil::ConvertNonChar( *pbz ) );
*pwz = (wchar_t)cConvertUtil::ConvertNonChar(*pbz); *pwz = (wchar_t)cConvertUtil::ConvertNonChar(*pbz);
N = 1; N = 1;
@ -1316,14 +1261,11 @@ namespace /*Unique*/
return (int)nConv; return (int)nConv;
} }
}//Unique } // namespace
#if WCHAR_IS_32_BITS #if WCHAR_IS_32_BITS
int int cWcharIs32BitUcs2Converterer::Convert(ntmbs_t pbz, size_t nBytes, const_ntdbs_t pwz, size_t nCount)
cWcharIs32BitUcs2Converterer::Convert(
ntmbs_t pbz, size_t nBytes,
const_ntdbs_t pwz, size_t nCount )
{ {
if (pbz == 0 || (pwz == 0 && nCount)) if (pbz == 0 || (pwz == 0 && nCount))
throw eConverterFatal(TSS_GetString(cCore, core::STR_ERR_ISNULL)); throw eConverterFatal(TSS_GetString(cCore, core::STR_ERR_ISNULL));
@ -1354,10 +1296,7 @@ cWcharIs32BitUcs2Converterer::Convert(
return nConv; return nConv;
} }
int int cWcharIs32BitUcs2Converterer::Convert(ntdbs_t pwz, size_t nCount, const_ntmbs_t pbz, size_t nBytes)
cWcharIs32BitUcs2Converterer::Convert(
ntdbs_t pwz, size_t nCount,
const_ntmbs_t pbz, size_t nBytes )
{ {
cDebug d("cWcharIs32BitUcs2Converterer::Convert( ntmbs to ntdbs )"); cDebug d("cWcharIs32BitUcs2Converterer::Convert( ntmbs to ntdbs )");
@ -1402,10 +1341,7 @@ cWcharIs32BitUcs2Converterer::Convert(
#if WCHAR_IS_16_BITS #if WCHAR_IS_16_BITS
int int cWcharIs16BitUcs2Converterer::Convert(ntmbs_t pbz, size_t nbMB, const_ntdbs_t pwz, size_t nch)
cWcharIs16BitUcs2Converterer::Convert(
ntmbs_t pbz, size_t nbMB,
const_ntdbs_t pwz, size_t nch )
{ {
// Validate Input // Validate Input
if (pbz == 0 || (pwz == 0 && nch)) if (pbz == 0 || (pwz == 0 && nch))
@ -1427,10 +1363,7 @@ cWcharIs16BitUcs2Converterer::Convert(
return nConverted; return nConverted;
} }
int int cWcharIs16BitUcs2Converterer::Convert(ntdbs_t pwz, size_t nch, const_ntmbs_t pbz, size_t nBytes)
cWcharIs16BitUcs2Converterer::Convert(
ntdbs_t pwz, size_t nch,
const_ntmbs_t pbz, size_t nBytes )
{ {
// Validate Input // Validate Input
if (pbz == 0 || (pwz == 0 && nch)) if (pbz == 0 || (pwz == 0 && nch))
@ -1450,11 +1383,7 @@ cWcharIs16BitUcs2Converterer::Convert(
#endif // WCHAR_IS_16_BITS #endif // WCHAR_IS_16_BITS
int cGoodEnoughConverterer::Convert(ntmbs_t pbz, size_t nBytes, const_ntdbs_t pwz, size_t nCount)
int
cGoodEnoughConverterer::Convert(
ntmbs_t pbz, size_t nBytes,
const_ntdbs_t pwz, size_t nCount )
{ {
if (pbz == 0 || (pwz == 0 && nCount)) if (pbz == 0 || (pwz == 0 && nCount))
throw eConverterFatal(TSS_GetString(cCore, core::STR_ERR_ISNULL)); throw eConverterFatal(TSS_GetString(cCore, core::STR_ERR_ISNULL));
@ -1485,10 +1414,7 @@ cGoodEnoughConverterer::Convert(
return ((size_t)at - (size_t)pbz); return ((size_t)at - (size_t)pbz);
} }
int int cGoodEnoughConverterer::Convert(ntdbs_t pwz, size_t nCount, const_ntmbs_t pbz, size_t nBytes)
cGoodEnoughConverterer::Convert(
ntdbs_t pwz, size_t nCount,
const_ntmbs_t pbz, size_t nBytes )
{ {
// Validate Input // Validate Input
if (pwz == 0 || (pbz == 0 && nBytes)) if (pwz == 0 || (pbz == 0 && nBytes))
@ -1531,9 +1457,7 @@ dbchar_t cConvertUtil::ConvertNonChar( mbchar_t ch )
dbchar_t wch = (dbchar_t)(tss::util::char_to_size(ch) + TSS_UCS2_RESERVED_START); dbchar_t wch = (dbchar_t)(tss::util::char_to_size(ch) + TSS_UCS2_RESERVED_START);
d.TraceDebug( "Converted 0x%08X to 0x%08X\n", d.TraceDebug("Converted 0x%08X to 0x%08X\n", tss::util::char_to_size(ch), tss::util::char_to_size(wch));
tss::util::char_to_size( ch ),
tss::util::char_to_size( wch ) );
return (wch); return (wch);
} }
@ -1550,9 +1474,7 @@ mbchar_t cConvertUtil::ConvertNonChar( dbchar_t wch )
mbchar_t ch = (mbchar_t)(wch - TSS_UCS2_RESERVED_START); mbchar_t ch = (mbchar_t)(wch - TSS_UCS2_RESERVED_START);
d.TraceDebug( "Converted 0x%08X to 0x%08X\n", d.TraceDebug("Converted 0x%08X to 0x%08X\n", tss::util::char_to_size(wch), tss::util::char_to_size(ch));
tss::util::char_to_size( wch ),
tss::util::char_to_size( ch ) );
return (ch); return (ch);
} }
@ -1560,13 +1482,11 @@ mbchar_t cConvertUtil::ConvertNonChar( dbchar_t wch )
bool cConvertUtil::ValueInReservedRange(dbchar_t wch) bool cConvertUtil::ValueInReservedRange(dbchar_t wch)
{ {
size_t s = tss::util::char_to_size(wch); size_t s = tss::util::char_to_size(wch);
return( ( s >= TSS_UCS2_RESERVED_START ) && return ((s >= TSS_UCS2_RESERVED_START) && (s <= TSS_UCS2_RESERVED_END));
( s <= TSS_UCS2_RESERVED_END ) );
} }
bool cConvertUtil::ValueInReservedRange(mbchar_t ch) bool cConvertUtil::ValueInReservedRange(mbchar_t ch)
{ {
size_t s = tss::util::char_to_size(ch); size_t s = tss::util::char_to_size(ch);
return( ( s >= TSS_HIGH_ASCII_START ) && return ((s >= TSS_HIGH_ASCII_START) && (s <= TSS_HIGH_ASCII_END));
( s <= TSS_HIGH_ASCII_END ) );
} }

View File

@ -91,44 +91,37 @@ TSS_EXCEPTION( eConverterUnknownCodepage, eConverter );
class iCodeConverter class iCodeConverter
{ {
public: public:
static iCodeConverter* GetInstance(); // Singleton static iCodeConverter* GetInstance(); // Singleton
static void Finit(); static void Finit();
/// Subclass Responsibilities /// Subclass Responsibilities
virtual virtual int Convert(ntmbs_t, // NTMBS buffer
int
Convert(
ntmbs_t, // NTMBS buffer
size_t, // Capacity in mbchar_t's (bytes) size_t, // Capacity in mbchar_t's (bytes)
const_ntdbs_t, // null terminated two-byte wide character (UCS2 rep) const_ntdbs_t, // null terminated two-byte wide character (UCS2 rep)
size_t nCount) = 0; // Amount to convert in dbchar_t's size_t nCount) = 0; // Amount to convert in dbchar_t's
// returns number of buffer items converted, -1 on error // returns number of buffer items converted, -1 on error
virtual virtual int Convert(ntdbs_t, // NTDBS (Null-terminated two byte sequence) buf
int
Convert(
ntdbs_t, // NTDBS (Null-terminated two byte sequence) buf
size_t, // Capacity in dbchar_t's size_t, // Capacity in dbchar_t's
const_ntmbs_t, // Null-terminated multi-byte sequence const_ntmbs_t, // Null-terminated multi-byte sequence
size_t) = 0; // Capacity in mbchar_t's (bytes) size_t) = 0; // Capacity in mbchar_t's (bytes)
// returns number of buffer items converted, -1 on error // returns number of buffer items converted, -1 on error
protected: protected:
iCodeConverter()
iCodeConverter() {} {
virtual ~iCodeConverter() {} }
virtual ~iCodeConverter()
{
}
private: private:
static iCodeConverter* CreateConverter(); static iCodeConverter* CreateConverter();
static iCodeConverter* CreateGoodEnoughConverter(); static iCodeConverter* CreateGoodEnoughConverter();
static iCodeConverter* m_pInst; static iCodeConverter* m_pInst;
}; };
@ -149,7 +142,6 @@ class iCodeConverter
class cIconvUtil class cIconvUtil
{ {
public: public:
static const char* GetCodePageID(); // gets code page id for current locale, throws if error static const char* GetCodePageID(); // gets code page id for current locale, throws if error
static bool GetCodePageID(const char** ppCP); static bool GetCodePageID(const char** ppCP);
static const char* GetIconvDbIdentifier(); static const char* GetIconvDbIdentifier();
@ -164,7 +156,6 @@ class cIconvUtil
class cIconvConverter : public iCodeConverter class cIconvConverter : public iCodeConverter
{ {
public: public:
static bool Test(); // is there a conversion for the current codepage? static bool Test(); // is there a conversion for the current codepage?
virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t); virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t);
@ -183,7 +174,6 @@ class cIconvConverter : public iCodeConverter
class cDoubleIconvConverter : public iCodeConverter class cDoubleIconvConverter : public iCodeConverter
{ {
public: public:
static bool Test(); // is there a conversion for the current codepage? static bool Test(); // is there a conversion for the current codepage?
virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t); virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t);
@ -193,7 +183,6 @@ class cDoubleIconvConverter : public iCodeConverter
virtual ~cDoubleIconvConverter(); virtual ~cDoubleIconvConverter();
private: private:
void Init(); void Init();
iconv_t icMbToUTF8; iconv_t icMbToUTF8;
@ -223,7 +212,9 @@ public:
virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t); virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t);
virtual int Convert(ntdbs_t, size_t, const_ntmbs_t, size_t); virtual int Convert(ntdbs_t, size_t, const_ntmbs_t, size_t);
virtual ~cWcharIs32BitUcs2Converterer() {} virtual ~cWcharIs32BitUcs2Converterer()
{
}
}; };
#endif // WCHAR_IS_32_BITS #endif // WCHAR_IS_32_BITS
@ -243,7 +234,9 @@ public:
virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t); virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t);
virtual int Convert(ntdbs_t, size_t, const_ntmbs_t, size_t); virtual int Convert(ntdbs_t, size_t, const_ntmbs_t, size_t);
virtual ~cWcharIs16BitUcs2Converterer() {} virtual ~cWcharIs16BitUcs2Converterer()
{
}
}; };
#endif // WCHAR_IS_16_BITS #endif // WCHAR_IS_16_BITS
@ -256,7 +249,9 @@ public:
virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t); virtual int Convert(ntmbs_t, size_t, const_ntdbs_t, size_t);
virtual int Convert(ntdbs_t, size_t, const_ntmbs_t, size_t); virtual int Convert(ntdbs_t, size_t, const_ntmbs_t, size_t);
virtual ~cGoodEnoughConverterer() {} virtual ~cGoodEnoughConverterer()
{
}
}; };
@ -269,6 +264,7 @@ class cConvertUtil
TSS_HIGH_ASCII_START = 0x0080u, TSS_HIGH_ASCII_START = 0x0080u,
TSS_HIGH_ASCII_END = 0x00FFu TSS_HIGH_ASCII_END = 0x00FFu
}; };
public: public:
static dbchar_t ConvertNonChar(mbchar_t ch); static dbchar_t ConvertNonChar(mbchar_t ch);
static mbchar_t ConvertNonChar(dbchar_t ch); static mbchar_t ConvertNonChar(dbchar_t ch);
@ -279,4 +275,3 @@ public:
#endif //__CODECONVERT_H #endif //__CODECONVERT_H

View File

@ -64,4 +64,3 @@ cCore::~cCore()
{ {
iCodeConverter::Finit(); iCodeConverter::Finit();
} }

View File

@ -52,11 +52,9 @@ TSS_BeginPackage( cCore )
TSS_DECLARE_STRINGTABLE; TSS_DECLARE_STRINGTABLE;
public: public:
cCore(); cCore();
~cCore(); ~cCore();
TSS_EndPackage(cCore) TSS_EndPackage(cCore)
#endif //__CORE_H #endif //__CORE_H

View File

@ -110,7 +110,8 @@ TSS_REGISTER_ERROR( eFSServicesGeneric(),_T("File system error.") )
/// Serializer /// Serializer
TSS_REGISTER_ERROR( eSerializerUnknownType(), _T("Unknown type encountered in file.\nFile format may not be valid for this platform.") ) TSS_REGISTER_ERROR(eSerializerUnknownType(),
_T("Unknown type encountered in file.\nFile format may not be valid for this platform."))
TSS_REGISTER_ERROR(eSerializerInputStreamFmt(), _T("Invalid input stream format.")) TSS_REGISTER_ERROR(eSerializerInputStreamFmt(), _T("Invalid input stream format."))
TSS_REGISTER_ERROR(eSerializerOutputStreamFmt(), _T("Invalid output stream format.")) TSS_REGISTER_ERROR(eSerializerOutputStreamFmt(), _T("Invalid output stream format."))
TSS_REGISTER_ERROR(eSerializerInputStremTypeArray(), _T("A bad index was encountered in file.")) TSS_REGISTER_ERROR(eSerializerInputStremTypeArray(), _T("A bad index was encountered in file."))
@ -163,4 +164,3 @@ TSS_REGISTER_ERROR( eUnknownEscapeEncoding(), _T("Unknown encoding in display
TSS_END_ERROR_REGISTRATION() TSS_END_ERROR_REGISTRATION()

View File

@ -45,4 +45,3 @@ TSS_DECLARE_ERROR_REGISTRATION( core )
#endif //__COREERRORS_H #endif //__COREERRORS_H

View File

@ -44,14 +44,11 @@ TSS_BeginStringtable( cCore )
TSS_StringEntry(core::STR_ERR2_ARCH_CRYPTO_ERR, _T("File could not be decrypted.")), TSS_StringEntry(core::STR_ERR2_ARCH_CRYPTO_ERR, _T("File could not be decrypted.")),
TSS_StringEntry(core::STR_ERR2_BAD_ARG_PARAMS, _T("Argument: ")), TSS_StringEntry(core::STR_ERR2_BAD_ARG_PARAMS, _T("Argument: ")),
TSS_StringEntry(core::STR_ERROR_ERROR, _T("### Error")), TSS_StringEntry(core::STR_ERROR_ERROR, _T("### Error")),
TSS_StringEntry( core::STR_ERROR_WARNING, _T("### Warning") ), TSS_StringEntry(core::STR_ERROR_WARNING, _T("### Warning")), TSS_StringEntry(core::STR_ERROR_COLON, _T(":")),
TSS_StringEntry( core::STR_ERROR_COLON, _T(":") ), TSS_StringEntry(core::STR_ERROR_HEADER, _T("### ")), TSS_StringEntry(core::STR_ERROR_EXITING, _T("Exiting...")),
TSS_StringEntry( core::STR_ERROR_HEADER, _T("### ") ),
TSS_StringEntry( core::STR_ERROR_EXITING, _T("Exiting...") ),
TSS_StringEntry(core::STR_ERROR_CONTINUING, _T("Continuing...")), TSS_StringEntry(core::STR_ERROR_CONTINUING, _T("Continuing...")),
TSS_StringEntry(core::STR_ERR2_FILENAME, _T("Filename: ")), TSS_StringEntry(core::STR_ERR2_FILENAME, _T("Filename: ")),
TSS_StringEntry( core::STR_ERROR_FILENAME, _T("Filename: ") ), TSS_StringEntry(core::STR_ERROR_FILENAME, _T("Filename: ")), TSS_StringEntry(core::STR_UNKNOWN, _T("Unknown")),
TSS_StringEntry( core::STR_UNKNOWN, _T("Unknown") ),
TSS_StringEntry(core::STR_NUMBER_TOO_BIG, _T("Number too big")), TSS_StringEntry(core::STR_NUMBER_TOO_BIG, _T("Number too big")),
TSS_StringEntry(core::STR_SIGNAL, _T("Software interrupt forced exit:")), TSS_StringEntry(core::STR_SIGNAL, _T("Software interrupt forced exit:")),
TSS_StringEntry(core::STR_NEWLINE, _T("\n")), TSS_StringEntry(core::STR_NEWLINE, _T("\n")),
@ -59,7 +56,9 @@ TSS_BeginStringtable( cCore )
TSS_StringEntry(core::STR_MEMARCHIVE_ERRSTR, _T("")), TSS_StringEntry(core::STR_MEMARCHIVE_ERRSTR, _T("")),
TSS_StringEntry(core::STR_ENDOFTIME, _T("Tripwire is not designed to run past the year 2038.\nNow exiting...")), TSS_StringEntry(core::STR_ENDOFTIME, _T("Tripwire is not designed to run past the year 2038.\nNow exiting...")),
TSS_StringEntry(core::STR_UNKNOWN_TIME, _T("Unknown time")), TSS_StringEntry(core::STR_UNKNOWN_TIME, _T("Unknown time")),
TSS_StringEntry( core::STR_BAD_TEMPDIRECTORY, _T("Solution: Check existence/permissions for directory specified by TEMPDIRECTORY in config file") ), TSS_StringEntry(
core::STR_BAD_TEMPDIRECTORY,
_T("Solution: Check existence/permissions for directory specified by TEMPDIRECTORY in config file")),
/// Particularly useful for eCharacter and eCharacterEncoding /// Particularly useful for eCharacter and eCharacterEncoding
TSS_StringEntry(core::STR_ERR_ISNULL, _T("Argument cannot be null.")), TSS_StringEntry(core::STR_ERR_ISNULL, _T("Argument cannot be null.")),
@ -68,6 +67,3 @@ TSS_BeginStringtable( cCore )
TSS_StringEntry(core::STR_ERR_BADCHAR, _T("Input contained an invalid character.")) TSS_StringEntry(core::STR_ERR_BADCHAR, _T("Input contained an invalid character."))
TSS_EndStringtable(cCore) TSS_EndStringtable(cCore)

View File

@ -48,34 +48,16 @@
TSS_BeginStringIds(core) TSS_BeginStringIds(core)
STR_ERR2_ARCH_CRYPTO_ERR, STR_ERR2_ARCH_CRYPTO_ERR,
STR_ERR2_BAD_ARG_PARAMS, STR_ERR2_BAD_ARG_PARAMS, STR_ERROR_ERROR, STR_ERROR_WARNING, STR_ERROR_COLON, STR_ERROR_HEADER, STR_ERROR_EXITING,
STR_ERROR_ERROR, STR_ERROR_CONTINUING, STR_ERR2_FILENAME, STR_ERROR_FILENAME, STR_NUMBER_TOO_BIG, STR_UNKNOWN, STR_SIGNAL,
STR_ERROR_WARNING, STR_NEWLINE, STR_MEMARCHIVE_FILENAME, STR_MEMARCHIVE_ERRSTR, STR_ENDOFTIME, STR_UNKNOWN_TIME, STR_BAD_TEMPDIRECTORY,
STR_ERROR_COLON,
STR_ERROR_HEADER,
STR_ERROR_EXITING,
STR_ERROR_CONTINUING,
STR_ERR2_FILENAME,
STR_ERROR_FILENAME,
STR_NUMBER_TOO_BIG,
STR_UNKNOWN,
STR_SIGNAL,
STR_NEWLINE,
STR_MEMARCHIVE_FILENAME,
STR_MEMARCHIVE_ERRSTR,
STR_ENDOFTIME,
STR_UNKNOWN_TIME,
STR_BAD_TEMPDIRECTORY,
/// Particularly useful for eCharacterSet and eCharacterEncoding /// Particularly useful for eCharacterSet and eCharacterEncoding
STR_ERR_ISNULL, STR_ERR_ISNULL, STR_ERR_OVERFLOW, STR_ERR_UNDERFLOW,
STR_ERR_OVERFLOW,
STR_ERR_UNDERFLOW,
STR_ERR_BADCHAR STR_ERR_BADCHAR
TSS_EndStringIds(core) TSS_EndStringIds(core)
#endif //__CORESTRINGS_H #endif //__CORESTRINGS_H

View File

@ -86,7 +86,6 @@ void cDebug::Trace(int levelNum, const char* format, ...)
va_start(args, format); va_start(args, format);
DoTrace(format, args); DoTrace(format, args);
va_end(args); va_end(args);
} }
@ -231,7 +230,8 @@ bool cDebug::AddOutTarget(OutTarget target)
mOutMask |= OUT_STDOUT; mOutMask |= OUT_STDOUT;
if (target == OUT_TRACE) if (target == OUT_TRACE)
mOutMask |= OUT_TRACE; mOutMask |= OUT_TRACE;
if (target == OUT_FILE) { if (target == OUT_FILE)
{
mOutMask |= OUT_FILE; mOutMask |= OUT_FILE;
return false; return false;
} }
@ -286,10 +286,12 @@ bool cDebug::SetOutputFile(const char* filename)
//make sure info. will not be clobbered. //make sure info. will not be clobbered.
//Should be open now- if not, abort. //Should be open now- if not, abort.
if (!logfile) { if (!logfile)
{
mOutMask ^= OUT_FILE; mOutMask ^= OUT_FILE;
return false; return false;
} else }
else
mOutMask |= OUT_FILE; mOutMask |= OUT_FILE;
return true; return true;
} }
@ -318,4 +320,3 @@ void cDebug::DebugOut( const char* lpOutputString, ... )
////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////
// ASSERT macro support function // ASSERT macro support function
////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////

View File

@ -40,8 +40,6 @@
#include <assert.h> #include <assert.h>
#include <iostream> #include <iostream>
/* Do it in this order, because autoconf checks for <stdarg.h> /* Do it in this order, because autoconf checks for <stdarg.h>
* first i.e. if HAVE_VARARGS_H is defined, it is only because * first i.e. if HAVE_VARARGS_H is defined, it is only because
@ -125,7 +123,6 @@ public:
// Outputs based on levelnum. If levelnum <= global debug, print. // Outputs based on levelnum. If levelnum <= global debug, print.
public: public:
static bool AddOutTarget(OutTarget target); static bool AddOutTarget(OutTarget target);
static bool RemoveOutTarget(OutTarget target); static bool RemoveOutTarget(OutTarget target);
// used to specify the out target.... // used to specify the out target....
@ -144,7 +141,10 @@ public:
// than that will have unpredictable and probably bad results // than that will have unpredictable and probably bad results
private: private:
#ifdef DEBUG #ifdef DEBUG
enum { MAX_LABEL = 128 }; enum
{
MAX_LABEL = 128
};
static int mDebugLevel; static int mDebugLevel;
static uint32 mOutMask; static uint32 mOutMask;
@ -181,29 +181,69 @@ inline int cDebug::GetDebugLevel()
# else // DEBUG # else // DEBUG
inline cDebug::cDebug (const char *) {} inline cDebug::cDebug(const char*)
inline cDebug::~cDebug () {} {
inline cDebug::cDebug (const cDebug&) {} }
inline void cDebug::TraceAlways (const char *, ...) {} inline cDebug::~cDebug()
inline void cDebug::TraceError (const char *, ...) {} {
inline void cDebug::TraceWarning (const char *, ...) {} }
inline void cDebug::TraceDebug (const char *, ...) {} inline cDebug::cDebug(const cDebug&)
inline void cDebug::TraceDetail (const char *, ...) {} {
inline void cDebug::TraceNever (const char *, ...) {} }
inline void cDebug::TraceVaArgs (int, const char *, va_list &) {} inline void cDebug::TraceAlways(const char*, ...)
inline void cDebug::Trace (int, const char*, ...) {} {
inline bool cDebug::AddOutTarget (OutTarget) { return false; } }
inline bool cDebug::RemoveOutTarget (OutTarget) { return false; } inline void cDebug::TraceError(const char*, ...)
inline bool cDebug::HasOutTarget (OutTarget) { return false; } {
inline bool cDebug::SetOutputFile (const char*) { return false; } }
inline void cDebug::SetDebugLevel (int) {} inline void cDebug::TraceWarning(const char*, ...)
inline int cDebug::GetDebugLevel (void) { return 0; } {
inline void cDebug::DebugOut ( const char*, ... ) {} }
inline void cDebug::TraceDebug(const char*, ...)
{
}
inline void cDebug::TraceDetail(const char*, ...)
{
}
inline void cDebug::TraceNever(const char*, ...)
{
}
inline void cDebug::TraceVaArgs(int, const char*, va_list&)
{
}
inline void cDebug::Trace(int, const char*, ...)
{
}
inline bool cDebug::AddOutTarget(OutTarget)
{
return false;
}
inline bool cDebug::RemoveOutTarget(OutTarget)
{
return false;
}
inline bool cDebug::HasOutTarget(OutTarget)
{
return false;
}
inline bool cDebug::SetOutputFile(const char*)
{
return false;
}
inline void cDebug::SetDebugLevel(int)
{
}
inline int cDebug::GetDebugLevel(void)
{
return 0;
}
inline void cDebug::DebugOut(const char*, ...)
{
}
# endif // DEBUG # endif // DEBUG
////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////
// ASSERT macro // ASSERT macro
////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////
@ -226,4 +266,3 @@ inline void cDebug::DebugOut ( const char*, ... ) {}
# endif # endif
#endif //__DEBUG_H #endif //__DEBUG_H

View File

@ -66,8 +66,7 @@
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
inline bool IsSingleTCHAR( TSTRING::const_iterator first, inline bool IsSingleTCHAR(TSTRING::const_iterator first, TSTRING::const_iterator last)
TSTRING::const_iterator last )
{ {
return (first + 1 == last); return (first + 1 == last);
} }
@ -83,23 +82,19 @@ class iCharEncoder
public: public:
virtual ~iCharEncoder(){}; virtual ~iCharEncoder(){};
virtual bool NeedsEncoding( TSTRING::const_iterator first, virtual bool NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const = 0;
TSTRING::const_iterator last ) const = 0;
// Determines if character identified by [first,last) needs encoding. // Determines if character identified by [first,last) needs encoding.
// Returns true if it does. // Returns true if it does.
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const = 0;
TSTRING::const_iterator last ) const = 0;
// Encodes character identified by [first,last) in such a way that it // Encodes character identified by [first,last) in such a way that it
// can be decoded by Decode(). Returns encoded character sequence. // can be decoded by Decode(). Returns encoded character sequence.
virtual TSTRING EncodePretty( TSTRING::const_iterator first, virtual TSTRING EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const = 0;
TSTRING::const_iterator last ) const = 0;
// Encodes character identified by [first,last) in a manner that is not roundtrip, // Encodes character identified by [first,last) in a manner that is not roundtrip,
// but looks good. Returns encoded character sequence. // but looks good. Returns encoded character sequence.
virtual TSTRING Decode( TSTRING::const_iterator* pcur, virtual TSTRING Decode(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end) const = 0;
const TSTRING::const_iterator end ) const = 0;
// Decodes character sequence beginning with '*pcur' and ending before 'end'. // Decodes character sequence beginning with '*pcur' and ending before 'end'.
// Returns decoded character or sequence of characters. Advances *pcur beyond // Returns decoded character or sequence of characters. Advances *pcur beyond
// the last character decoded. // the last character decoded.
@ -107,10 +102,12 @@ class iCharEncoder
virtual TCHAR Identifier() const = 0; virtual TCHAR Identifier() const = 0;
static TCHAR EscapeChar() { return char_escape; } static TCHAR EscapeChar()
{
return char_escape;
}
protected: protected:
static TCHAR char_escape; static TCHAR char_escape;
}; };
@ -118,21 +115,20 @@ class iCharEncoder
class cNonNarrowableCharEncoder : public iCharEncoder class cNonNarrowableCharEncoder : public iCharEncoder
{ {
public: public:
virtual ~cNonNarrowableCharEncoder() {} virtual ~cNonNarrowableCharEncoder()
{
}
virtual bool NeedsEncoding( TSTRING::const_iterator first, virtual bool NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
TSTRING::const_iterator last ) const;
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
TSTRING::const_iterator last ) const;
virtual TSTRING EncodePretty( TSTRING::const_iterator first, virtual TSTRING EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
TSTRING::const_iterator last ) const;
virtual TSTRING Decode( TSTRING::const_iterator* cur, virtual TSTRING Decode(TSTRING::const_iterator* cur, const TSTRING::const_iterator end) const;
const TSTRING::const_iterator end ) const;
virtual TCHAR Identifier() const; virtual TCHAR Identifier() const;
private: private:
static TCHAR char_identifier; static TCHAR char_identifier;
static TCHAR char_replace; static TCHAR char_replace;
@ -142,24 +138,22 @@ class cNonNarrowableCharEncoder : public iCharEncoder
class cNonPrintableCharEncoder : public iCharEncoder class cNonPrintableCharEncoder : public iCharEncoder
{ {
public: public:
cNonPrintableCharEncoder( bool f_allowWS ) cNonPrintableCharEncoder(bool f_allowWS) : m_allowWS(f_allowWS){};
: m_allowWS( f_allowWS ) {};
virtual ~cNonPrintableCharEncoder() {} virtual ~cNonPrintableCharEncoder()
{
}
virtual bool NeedsEncoding( TSTRING::const_iterator first, virtual bool NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
TSTRING::const_iterator last ) const;
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
TSTRING::const_iterator last ) const;
virtual TSTRING EncodePretty( TSTRING::const_iterator first, virtual TSTRING EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
TSTRING::const_iterator last ) const;
virtual TSTRING Decode( TSTRING::const_iterator* cur, virtual TSTRING Decode(TSTRING::const_iterator* cur, const TSTRING::const_iterator end) const;
const TSTRING::const_iterator end ) const;
virtual TCHAR Identifier() const; virtual TCHAR Identifier() const;
private: private:
static TCHAR char_identifier; static TCHAR char_identifier;
static TCHAR char_replace; static TCHAR char_replace;
@ -170,21 +164,20 @@ class cNonPrintableCharEncoder : public iCharEncoder
class cQuoteCharEncoder : public iCharEncoder class cQuoteCharEncoder : public iCharEncoder
{ {
public: public:
virtual ~cQuoteCharEncoder() {} virtual ~cQuoteCharEncoder()
{
}
virtual bool NeedsEncoding( TSTRING::const_iterator first, virtual bool NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
TSTRING::const_iterator last ) const;
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
TSTRING::const_iterator last ) const;
virtual TSTRING EncodePretty( TSTRING::const_iterator first, virtual TSTRING EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
TSTRING::const_iterator last ) const;
virtual TSTRING Decode( TSTRING::const_iterator* cur, virtual TSTRING Decode(TSTRING::const_iterator* cur, const TSTRING::const_iterator end) const;
const TSTRING::const_iterator end ) const;
virtual TCHAR Identifier() const; virtual TCHAR Identifier() const;
private: private:
static TCHAR char_test; static TCHAR char_test;
static TCHAR char_identifier; static TCHAR char_identifier;
@ -195,21 +188,20 @@ class cQuoteCharEncoder : public iCharEncoder
class cBackslashCharEncoder : public iCharEncoder class cBackslashCharEncoder : public iCharEncoder
{ {
public: public:
virtual ~cBackslashCharEncoder() {} virtual ~cBackslashCharEncoder()
{
}
virtual bool NeedsEncoding( TSTRING::const_iterator first, virtual bool NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
TSTRING::const_iterator last ) const;
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
TSTRING::const_iterator last ) const;
virtual TSTRING EncodePretty( TSTRING::const_iterator first, virtual TSTRING EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
TSTRING::const_iterator last ) const;
virtual TSTRING Decode( TSTRING::const_iterator* cur, virtual TSTRING Decode(TSTRING::const_iterator* cur, const TSTRING::const_iterator end) const;
const TSTRING::const_iterator end ) const;
virtual TCHAR Identifier() const; virtual TCHAR Identifier() const;
private: private:
static TCHAR char_test; static TCHAR char_test;
static TCHAR char_identifier; static TCHAR char_identifier;
@ -241,18 +233,13 @@ TCHAR cNonPrintableCharEncoder::char_replace = _T('?');
// TESTS // TESTS
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
bool cNonNarrowableCharEncoder::NeedsEncoding( bool cNonNarrowableCharEncoder::NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const
TSTRING::const_iterator first,
TSTRING::const_iterator last ) const
{ {
return false; // all chars are narrow return false; // all chars are narrow
} }
bool cNonPrintableCharEncoder::NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const
bool cNonPrintableCharEncoder::NeedsEncoding(
TSTRING::const_iterator first,
TSTRING::const_iterator last ) const
{ {
// TODO:BAM -- handle this with mb chars // TODO:BAM -- handle this with mb chars
// std::isprint<wchar_t> does a wctob() on the wchar!!?!?! // std::isprint<wchar_t> does a wctob() on the wchar!!?!?!
@ -284,26 +271,14 @@ bool cNonPrintableCharEncoder::NeedsEncoding(
return cCharEncoderUtil::IsPrintable(*first); return cCharEncoderUtil::IsPrintable(*first);
} }
bool cQuoteCharEncoder::NeedsEncoding( bool cQuoteCharEncoder::NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const
TSTRING::const_iterator first,
TSTRING::const_iterator last ) const
{ {
return( return (IsSingleTCHAR(first, last) && (*first == char_test));
IsSingleTCHAR( first, last )
&&
( *first == char_test )
);
} }
bool cBackslashCharEncoder::NeedsEncoding( bool cBackslashCharEncoder::NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const
TSTRING::const_iterator first,
TSTRING::const_iterator last ) const
{ {
return( return (IsSingleTCHAR(first, last) && (*first == char_test));
IsSingleTCHAR( first, last )
&&
( *first == char_test )
);
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -311,9 +286,7 @@ bool cBackslashCharEncoder::NeedsEncoding(
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
TSTRING cNonNarrowableCharEncoder::EncodeRoundtrip( TSTRING cNonNarrowableCharEncoder::EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const
TSTRING::const_iterator first,
TSTRING::const_iterator last ) const
{ {
TSTRING str; TSTRING str;
@ -325,9 +298,7 @@ TSTRING cNonNarrowableCharEncoder::EncodeRoundtrip(
} }
TSTRING cNonPrintableCharEncoder::EncodeRoundtrip( TSTRING cNonPrintableCharEncoder::EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const
TSTRING::const_iterator first,
TSTRING::const_iterator last ) const
{ {
ASSERT(IsSingleTCHAR(first, last)); // non-prints are single char (see NOTE above) ASSERT(IsSingleTCHAR(first, last)); // non-prints are single char (see NOTE above)
@ -341,9 +312,7 @@ TSTRING cNonPrintableCharEncoder::EncodeRoundtrip(
} }
TSTRING cQuoteCharEncoder::EncodeRoundtrip( TSTRING cQuoteCharEncoder::EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const
TSTRING::const_iterator first,
TSTRING::const_iterator last ) const
{ {
// should just be a quote // should just be a quote
ASSERT(IsSingleTCHAR(first, last)); ASSERT(IsSingleTCHAR(first, last));
@ -358,10 +327,7 @@ TSTRING cQuoteCharEncoder::EncodeRoundtrip(
} }
TSTRING cBackslashCharEncoder::EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const
TSTRING cBackslashCharEncoder::EncodeRoundtrip(
TSTRING::const_iterator first,
TSTRING::const_iterator last ) const
{ {
// should just be a backslash // should just be a backslash
ASSERT(IsSingleTCHAR(first, last)); ASSERT(IsSingleTCHAR(first, last));
@ -380,25 +346,19 @@ TSTRING cBackslashCharEncoder::EncodeRoundtrip(
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
TSTRING cNonNarrowableCharEncoder::EncodePretty( TSTRING cNonNarrowableCharEncoder::EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const
TSTRING::const_iterator first,
TSTRING::const_iterator last ) const
{ {
return EncodeRoundtrip(first, last); return EncodeRoundtrip(first, last);
} }
TSTRING cNonPrintableCharEncoder::EncodePretty( TSTRING cNonPrintableCharEncoder::EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const
TSTRING::const_iterator first,
TSTRING::const_iterator last ) const
{ {
return EncodeRoundtrip(first, last); return EncodeRoundtrip(first, last);
} }
TSTRING cQuoteCharEncoder::EncodePretty( TSTRING cQuoteCharEncoder::EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const
TSTRING::const_iterator first,
TSTRING::const_iterator last ) const
{ {
// should just be a quote // should just be a quote
ASSERT(IsSingleTCHAR(first, last)); ASSERT(IsSingleTCHAR(first, last));
@ -408,9 +368,7 @@ TSTRING cQuoteCharEncoder::EncodePretty(
} }
TSTRING cBackslashCharEncoder::EncodePretty( TSTRING cBackslashCharEncoder::EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const
TSTRING::const_iterator first,
TSTRING::const_iterator last ) const
{ {
// should just be a backslash // should just be a backslash
ASSERT(IsSingleTCHAR(first, last)); ASSERT(IsSingleTCHAR(first, last));
@ -424,8 +382,7 @@ TSTRING cBackslashCharEncoder::EncodePretty(
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
TSTRING cNonNarrowableCharEncoder::Decode( TSTRING::const_iterator* pcur, TSTRING cNonNarrowableCharEncoder::Decode(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end) const
const TSTRING::const_iterator end ) const
{ {
// check preconditions // check preconditions
if ((*pcur) >= end || *(*pcur) != Identifier()) if ((*pcur) >= end || *(*pcur) != Identifier())
@ -435,8 +392,7 @@ TSTRING cNonNarrowableCharEncoder::Decode( TSTRING::const_iterator* pcur,
} }
TSTRING cNonPrintableCharEncoder::Decode( TSTRING::const_iterator* pcur, TSTRING cNonPrintableCharEncoder::Decode(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end) const
const TSTRING::const_iterator end ) const
{ {
// check preconditions // check preconditions
if ((*pcur) >= end || *(*pcur) != Identifier()) if ((*pcur) >= end || *(*pcur) != Identifier())
@ -446,8 +402,7 @@ TSTRING cNonPrintableCharEncoder::Decode( TSTRING::const_iterator* pcur,
} }
TSTRING cQuoteCharEncoder::Decode( TSTRING::const_iterator* pcur, TSTRING cQuoteCharEncoder::Decode(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end) const
const TSTRING::const_iterator end ) const
{ {
if ((*pcur) >= end || *(*pcur) != Identifier()) if ((*pcur) >= end || *(*pcur) != Identifier())
ThrowAndAssert(eBadDecoderInput()); ThrowAndAssert(eBadDecoderInput());
@ -458,8 +413,7 @@ TSTRING cQuoteCharEncoder::Decode( TSTRING::const_iterator* pcur,
} }
TSTRING cBackslashCharEncoder::Decode( TSTRING::const_iterator* pcur, TSTRING cBackslashCharEncoder::Decode(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end) const
const TSTRING::const_iterator end ) const
{ {
if ((*pcur) >= end || *(*pcur) != Identifier()) if ((*pcur) >= end || *(*pcur) != Identifier())
ThrowAndAssert(eBadDecoderInput()); ThrowAndAssert(eBadDecoderInput());
@ -502,11 +456,7 @@ TCHAR cBackslashCharEncoder::Identifier() const
bool cCharEncoderUtil::IsWhiteSpace(TCHAR ch) bool cCharEncoderUtil::IsWhiteSpace(TCHAR ch)
{ {
return ( ch == '\r' || return (ch == '\r' || ch == '\n' || ch == '\t' || ch == '\v' || ch == ' ');
ch == '\n' ||
ch == '\t' ||
ch == '\v' ||
ch == ' ' );
} }
bool cCharEncoderUtil::IsPrintable(TCHAR ch) bool cCharEncoderUtil::IsPrintable(TCHAR ch)
@ -549,8 +499,7 @@ TSTRING cCharEncoderUtil::HexValueToCharString( const TSTRING& str )
return strOut; return strOut;
} }
TCHAR cCharEncoderUtil::hex_to_char( TSTRING::const_iterator first, TCHAR cCharEncoderUtil::hex_to_char(TSTRING::const_iterator first, TSTRING::const_iterator last)
TSTRING::const_iterator last )
{ {
static const TCHAR max_char = std::numeric_limits<TCHAR>::max(); static const TCHAR max_char = std::numeric_limits<TCHAR>::max();
static const TCHAR min_char = std::numeric_limits<TCHAR>::min(); static const TCHAR min_char = std::numeric_limits<TCHAR>::min();
@ -586,22 +535,17 @@ TSTRING cCharEncoderUtil::char_to_hex( TCHAR ch )
ss << tss::util::char_to_size(ch); ss << tss::util::char_to_size(ch);
if( ss.bad() || ss.fail() || if (ss.bad() || ss.fail() || ss.str().length() != TCHAR_AS_HEX__IN_TCHARS)
ss.str().length() != TCHAR_AS_HEX__IN_TCHARS )
ThrowAndAssert(eBadHexConversion(TSTRING(1, ch))); ThrowAndAssert(eBadHexConversion(TSTRING(1, ch)));
return ss.str(); return ss.str();
} }
TSTRING cCharEncoderUtil::DecodeHexToChar( TSTRING::const_iterator* pcur, TSTRING cCharEncoderUtil::DecodeHexToChar(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end)
const TSTRING::const_iterator end )
{ {
// get hex numbers -- 2 chars // get hex numbers -- 2 chars
TSTRING str; TSTRING str;
size_t n = 0; size_t n = 0;
for( (*pcur)++; for ((*pcur)++; n < TCHAR_AS_HEX__IN_TCHARS && (*pcur) != end; n++, (*pcur)++)
n < TCHAR_AS_HEX__IN_TCHARS &&
(*pcur) != end;
n++, (*pcur)++ )
{ {
str += *(*pcur); str += *(*pcur);
} }
@ -618,8 +562,7 @@ TSTRING cCharEncoderUtil::DecodeHexToChar( TSTRING::const_iterator* pcur,
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
cEncoder::cEncoder( int e, int f ) cEncoder::cEncoder(int e, int f) : m_fFlags(f)
: m_fFlags( f )
{ {
// add encodings // add encodings
if (e & NON_NARROWABLE) if (e & NON_NARROWABLE)
@ -632,14 +575,10 @@ cEncoder::cEncoder( int e, int f )
m_encodings.push_back(new cQuoteCharEncoder); m_encodings.push_back(new cQuoteCharEncoder);
// assert that we weren't passed anything freaky // assert that we weren't passed anything freaky
ASSERT( 0 == ( e & ~( NON_NARROWABLE | ASSERT(0 == (e & ~(NON_NARROWABLE | NON_PRINTABLE | BACKSLASH | DBL_QUOTE)));
NON_PRINTABLE |
BACKSLASH |
DBL_QUOTE ) ) );
// add flags // add flags
ASSERT( ! ( ( m_fFlags & ROUNDTRIP ) && ASSERT(!((m_fFlags & ROUNDTRIP) && (m_fFlags & NON_ROUNDTRIP)));
( m_fFlags & NON_ROUNDTRIP ) ) );
#ifdef TSS_DO_SCHEMA_VALIDATION #ifdef TSS_DO_SCHEMA_VALIDATION
@ -647,7 +586,6 @@ cEncoder::cEncoder( int e, int f )
ValidateSchema(); ValidateSchema();
#endif #endif
} }
@ -689,9 +627,7 @@ void cEncoder::Encode( TSTRING& strIn ) const
sack_type::const_iterator atE; sack_type::const_iterator atE;
// for all encoders // for all encoders
for( atE = m_encodings.begin(); for (atE = m_encodings.begin(); atE != m_encodings.end(); atE++)
atE != m_encodings.end();
atE++ )
{ {
// does char need encoding? // does char need encoding?
if ((*atE)->NeedsEncoding(first, last)) if ((*atE)->NeedsEncoding(first, last))
@ -713,9 +649,8 @@ void cEncoder::Encode( TSTRING& strIn ) const
strIn = strOut; strIn = strOut;
} }
TSTRING cEncoder::Encode( TSTRING::const_iterator first, TSTRING
TSTRING::const_iterator last, cEncoder::Encode(TSTRING::const_iterator first, TSTRING::const_iterator last, sack_type::const_iterator encoding) const
sack_type::const_iterator encoding ) const
{ {
// encode it // encode it
if (RoundTrip()) if (RoundTrip())
@ -739,8 +674,7 @@ void cEncoder::Decode( TSTRING& strIn ) const
while (cCharUtil::PopNextChar(cur, end, first, last)) while (cCharUtil::PopNextChar(cur, end, first, last))
{ {
// is this char the escape character? // is this char the escape character?
if( IsSingleTCHAR( first, last ) && if (IsSingleTCHAR(first, last) && *first == iCharEncoder::EscapeChar())
*first == iCharEncoder::EscapeChar() )
{ {
// get to identifier // get to identifier
if (!cCharUtil::PopNextChar(cur, end, first, last)) if (!cCharUtil::PopNextChar(cur, end, first, last))
@ -755,9 +689,7 @@ void cEncoder::Decode( TSTRING& strIn ) const
// determine to which encoding the identifier belongs // determine to which encoding the identifier belongs
bool fFoundEncoding = false; bool fFoundEncoding = false;
sack_type::const_iterator atE; sack_type::const_iterator atE;
for( atE = m_encodings.begin(); for (atE = m_encodings.begin(); atE != m_encodings.end(); atE++)
atE != m_encodings.end();
atE++ )
{ {
// is this the right encoding? // is this the right encoding?
if (*first == (*atE)->Identifier()) if (*first == (*atE)->Identifier())
@ -823,8 +755,7 @@ bool cEncoder::OnlyOneCatagoryPerChar() const
} }
} }
ch++; ch++;
} } while (ch != std::numeric_limits<TCHAR>::max());
while( ch != std::numeric_limits<TCHAR>::max() );
} }
return true; return true;
} }
@ -857,9 +788,7 @@ bool cEncoder::AllTestsRunOnEncodedString( const TSTRING& s ) const
while (cCharUtil::PopNextChar(cur, end, first, last)) while (cCharUtil::PopNextChar(cur, end, first, last))
{ {
sack_type::const_iterator atE; sack_type::const_iterator atE;
for( atE = m_encodings.begin(); for (atE = m_encodings.begin(); atE != m_encodings.end(); atE++)
atE != m_encodings.end();
atE++ )
{ {
if ((*atE)->NeedsEncoding(first, last)) if ((*atE)->NeedsEncoding(first, last))
{ {
@ -877,14 +806,7 @@ bool cEncoder::AllTestsRunOnEncodedString( const TSTRING& s ) const
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
cDisplayEncoder::cDisplayEncoder( Flags f ) cDisplayEncoder::cDisplayEncoder(Flags f) : cEncoder(NON_NARROWABLE | NON_PRINTABLE | BACKSLASH | DBL_QUOTE, f)
: cEncoder(
NON_NARROWABLE |
NON_PRINTABLE |
BACKSLASH |
DBL_QUOTE,
f
)
{ {
} }
@ -898,4 +820,3 @@ bool cDisplayEncoder::Decode( TSTRING& str ) const
cEncoder::Decode(str); cEncoder::Decode(str);
return true; // TODO:BAM -- throw error! return true; // TODO:BAM -- throw error!
} }

View File

@ -89,9 +89,8 @@ class cEncoder
private: private:
typedef std::vector<iCharEncoder*> sack_type; typedef std::vector<iCharEncoder*> sack_type;
TSTRING Encode( TSTRING::const_iterator first, TSTRING
TSTRING::const_iterator last, Encode(TSTRING::const_iterator first, TSTRING::const_iterator last, sack_type::const_iterator encoding) const;
sack_type::const_iterator encoding ) const;
bool RoundTrip() const; bool RoundTrip() const;
bool AllowWhiteSpace() const; bool AllowWhiteSpace() const;
@ -128,11 +127,9 @@ class cDisplayEncoder : public cEncoder
}; };
class cCharEncoderUtil class cCharEncoderUtil
{ {
public: public:
static bool IsPrintable(TCHAR ch); static bool IsPrintable(TCHAR ch);
static bool IsWhiteSpace(TCHAR ch); static bool IsWhiteSpace(TCHAR ch);
@ -140,13 +137,11 @@ class cCharEncoderUtil
static TSTRING HexValueToCharString(const TSTRING& str); static TSTRING HexValueToCharString(const TSTRING& str);
static TCHAR hex_to_char( TSTRING::const_iterator first, static TCHAR hex_to_char(TSTRING::const_iterator first, TSTRING::const_iterator last);
TSTRING::const_iterator last );
static TSTRING char_to_hex(TCHAR ch); static TSTRING char_to_hex(TCHAR ch);
static TSTRING DecodeHexToChar( TSTRING::const_iterator* pcur, static TSTRING DecodeHexToChar(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end);
const TSTRING::const_iterator end );
enum enum
@ -241,4 +236,3 @@ typedef cDisplayEncoder_<TCHAR> cDisplayEncoder;
#endif //__DISPLAYENCODER_H #endif //__DISPLAYENCODER_H
*/ */

View File

@ -96,5 +96,3 @@ TSTRING cDisplayUtil::FormatMultiLineString( const TSTRING& str, int nOffset, in
return (sstr.str()); return (sstr.str());
} }

View File

@ -98,4 +98,3 @@ public:
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#endif // #ifndef __DISPLAYUTIL_H #endif // #ifndef __DISPLAYUTIL_H

View File

@ -64,4 +64,3 @@ bool CheckEpoch()
return false; return false;
#endif #endif
} }

View File

@ -42,4 +42,3 @@
bool CheckEpoch(); bool CheckEpoch();
#endif #endif

View File

@ -47,5 +47,3 @@ uint32 eError::CalcHash( const char* name )
crcFinit(crc); crcFinit(crc);
return crc.crc; return crc.crc;
} }

View File

@ -42,7 +42,6 @@
class eError class eError
{ {
public: public:
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Construction and Assignment // Construction and Assignment
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@ -138,19 +137,24 @@ protected:
class except : public base \ class except : public base \
{ \ { \
public: \ public: \
except( const TSTRING& msg, uint32 flags = 0 ) \ except(const TSTRING& msg, uint32 flags = 0) : base(msg, flags) \
: base( msg, flags ) {} \ { \
TSS_BEGIN_EXCEPTION_EXPLICIT except( const except& rhs ) \ } \
: base( rhs ) {} \ TSS_BEGIN_EXCEPTION_EXPLICIT except(const except& rhs) : base(rhs) \
explicit except() : base() {} \ { \
} \
explicit except() : base() \
{ \
} \
\ \
virtual uint32 GetID() const \ virtual uint32 GetID() const \
{ \ { \
return CalcHash(#except); \ return CalcHash(#except); \
}\ }
#define TSS_END_EXCEPTION() \ #define TSS_END_EXCEPTION() \
}; } \
;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// TSS_BEGIN_EXCEPTION_NO_CTOR // TSS_BEGIN_EXCEPTION_NO_CTOR
@ -161,12 +165,14 @@ protected:
class except : public base \ class except : public base \
{ \ { \
public: \ public: \
explicit except() : base() {} \ explicit except() : base() \
{ \
} \
\ \
virtual uint32 GetID() const \ virtual uint32 GetID() const \
{ \ { \
return CalcHash(#except); \ return CalcHash(#except); \
}\ }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// TSS_EXCEPTION // TSS_EXCEPTION
@ -189,31 +195,22 @@ protected:
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// eError // eError
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
inline eError::eError( const TSTRING& msg, uint32 flags ) inline eError::eError(const TSTRING& msg, uint32 flags) : mMsg(msg), mFlags(flags)
: mMsg ( msg ),
mFlags ( flags )
{ {
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// eError // eError
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
inline eError::eError( const eError& rhs ) inline eError::eError(const eError& rhs) : mMsg(rhs.mMsg), mFlags(rhs.mFlags)
: mMsg ( rhs.mMsg ),
mFlags ( rhs.mFlags )
{ {
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// eError // eError
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
inline eError::eError( ) inline eError::eError() : mMsg(_T("")), mFlags(0)
: mMsg ( _T("") ),
mFlags ( 0 )
{ {
} }
@ -231,7 +228,6 @@ inline void eError::operator=( const eError& rhs )
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
inline eError::~eError() inline eError::~eError()
{ {
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -275,7 +271,6 @@ inline void eError::SetFatality(bool fatal)
inline bool eError::IsFatal() const inline bool eError::IsFatal() const
{ {
return (mFlags & (uint32)NON_FATAL) == 0; return (mFlags & (uint32)NON_FATAL) == 0;
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -298,6 +293,4 @@ inline bool eError::SupressThird() const
} }
#endif //__ERROR_H #endif //__ERROR_H

View File

@ -57,7 +57,9 @@ class cErrorBucket
{ {
public: public:
cErrorBucket(); cErrorBucket();
virtual ~cErrorBucket() {} virtual ~cErrorBucket()
{
}
virtual void AddError(const eError& error); virtual void AddError(const eError& error);
// add an error to the bucket // add an error to the bucket
@ -81,8 +83,7 @@ protected:
/////////////////// ///////////////////
// cErrorBucket // cErrorBucket
/////////////////// ///////////////////
inline cErrorBucket::cErrorBucket() : inline cErrorBucket::cErrorBucket() : mpChild(0)
mpChild(0)
{ {
} }
@ -99,4 +100,3 @@ inline cErrorBucket* cErrorBucket::SetChild(cErrorBucket* pNewChild)
} }
#endif #endif

View File

@ -52,9 +52,7 @@ void cErrorBucket::AddError(const eError& error)
//############################################################################# //#############################################################################
void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra) void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
{ {
cDisplayEncoder e( cDisplayEncoder e((cDisplayEncoder::Flags)(cDisplayEncoder::NON_ROUNDTRIP | cDisplayEncoder::ALLOW_WHITESPACE));
(cDisplayEncoder::Flags) ( cDisplayEncoder::NON_ROUNDTRIP |
cDisplayEncoder::ALLOW_WHITESPACE ) );
TSTRING errStr; TSTRING errStr;
// //
@ -74,8 +72,7 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
return; return;
// "First Part" header // "First Part" header
errStr = TSS_GetString( cCore, error.IsFatal() ? core::STR_ERROR_ERROR errStr = TSS_GetString(cCore, error.IsFatal() ? core::STR_ERROR_ERROR : core::STR_ERROR_WARNING);
: core::STR_ERROR_WARNING );
if (errStr.empty()) if (errStr.empty())
{ {
@ -136,7 +133,8 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
break; break;
} }
TSTRING::size_type lastSpace = currentStr.find_last_of(SPACE, currentStr.length() >= WIDTH - 1 ? WIDTH - 1 : TSTRING::npos); TSTRING::size_type lastSpace =
currentStr.find_last_of(SPACE, currentStr.length() >= WIDTH - 1 ? WIDTH - 1 : TSTRING::npos);
if (lastSpace == TSTRING::npos) if (lastSpace == TSTRING::npos)
{ {
// can't find space to break at so this string will just have to be longer than screen width. // can't find space to break at so this string will just have to be longer than screen width.
@ -148,15 +146,11 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
lastSpace = currentStr.length(); lastSpace = currentStr.length();
} }
TCERR << TSS_GetString( cCore, core::STR_ERROR_HEADER ) TCERR << TSS_GetString(cCore, core::STR_ERROR_HEADER) << currentStr.substr(0, lastSpace) << std::endl;
<< currentStr.substr( 0, lastSpace )
<< std::endl;
currentStr.erase(0, lastSpace + 1); currentStr.erase(0, lastSpace + 1);
} } while (!currentStr.empty());
while ( !currentStr.empty() ); } while (!errStr.empty());
}
while ( !errStr.empty() );
} }
// "Third Part" print 'exiting' or 'continuing' // "Third Part" print 'exiting' or 'continuing'
@ -165,11 +159,8 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
if ((error.GetFlags() & eError::SUPRESS_THIRD_MSG) == 0) if ((error.GetFlags() & eError::SUPRESS_THIRD_MSG) == 0)
{ {
TCERR << TSS_GetString(cCore, core::STR_ERROR_HEADER) TCERR << TSS_GetString(cCore, core::STR_ERROR_HEADER)
<< TSS_GetString( << TSS_GetString(cCore, error.IsFatal() ? core::STR_ERROR_EXITING : core::STR_ERROR_CONTINUING)
cCore, << std::endl;
error.IsFatal()
? core::STR_ERROR_EXITING
: core::STR_ERROR_CONTINUING ) << std::endl;
} }
} }
@ -185,9 +176,7 @@ void cErrorTracer::HandleError(const eError& error)
{ {
cDebug d("cErrorTracer::HandleError"); cDebug d("cErrorTracer::HandleError");
d.TraceError( _T("%s : %s\n"), d.TraceError(_T("%s : %s\n"), cErrorTable::GetInstance()->Get(error.GetID()).c_str(), error.GetMsg().c_str());
cErrorTable::GetInstance()->Get( error.GetID() ).c_str(),
error.GetMsg().c_str() );
} }
//############################################################################# //#############################################################################
@ -210,14 +199,12 @@ void cErrorQueue::HandleError(const eError& error)
mList.push_back(ePoly(error)); mList.push_back(ePoly(error));
} }
cErrorQueueIter::cErrorQueueIter(cErrorQueue& queue) : cErrorQueueIter::cErrorQueueIter(cErrorQueue& queue) : mList(queue.mList)
mList(queue.mList)
{ {
SeekBegin(); SeekBegin();
} }
cErrorQueueIter::cErrorQueueIter(const cErrorQueue& queue) cErrorQueueIter::cErrorQueueIter(const cErrorQueue& queue) : mList(((cErrorQueue*)&queue)->mList)
: mList( ((cErrorQueue*)&queue)->mList )
{ {
SeekBegin(); SeekBegin();
} }
@ -267,7 +254,6 @@ void cErrorQueue::Read(iSerializer* pSerializer, int32 version)
mList.push_back(ePoly(errorNumber, errorString, flags)); mList.push_back(ePoly(errorNumber, errorString, flags));
} }
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -283,7 +269,6 @@ void cErrorQueue::Write(iSerializer* pSerializer) const
pSerializer->WriteString((*i).GetMsg()); pSerializer->WriteString((*i).GetMsg());
pSerializer->WriteInt32((*i).GetFlags()); pSerializer->WriteInt32((*i).GetFlags());
} }
} }
@ -303,4 +288,3 @@ void cErrorQueue::TraceContents(int dl) const
d.Trace(dl, _T("Error[%d]: num = %x string = %s\n"), counter, (*i).GetID(), (*i).GetMsg().c_str()); d.Trace(dl, _T("Error[%d]: num = %x string = %s\n"), counter, (*i).GetID(), (*i).GetMsg().c_str());
} }
} }

View File

@ -100,6 +100,7 @@ protected:
class cErrorQueue : public cErrorBucket, public iTypedSerializable class cErrorQueue : public cErrorBucket, public iTypedSerializable
{ {
friend class cErrorQueueIter; friend class cErrorQueueIter;
public: public:
void Clear(); void Clear();
// remove all errors from the queue // remove all errors from the queue
@ -119,6 +120,7 @@ public:
protected: protected:
virtual void HandleError(const eError& error); virtual void HandleError(const eError& error);
private: private:
typedef std::list<ePoly> ListType; typedef std::list<ePoly> ListType;
ListType mList; ListType mList;
@ -131,7 +133,9 @@ class cErrorQueueIter
public: public:
cErrorQueueIter(cErrorQueue& queue); cErrorQueueIter(cErrorQueue& queue);
cErrorQueueIter(const cErrorQueue& queue); cErrorQueueIter(const cErrorQueue& queue);
~cErrorQueueIter() {} ~cErrorQueueIter()
{
}
// iteration methods // iteration methods
void SeekBegin(); void SeekBegin();
@ -153,9 +157,14 @@ private:
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
class cErrorBucketNull : public cErrorBucket class cErrorBucketNull : public cErrorBucket
{ {
virtual void AddError(const eError& ) {} virtual void AddError(const eError&)
{
}
protected: protected:
virtual void HandleError(const eError& ) {} virtual void HandleError(const eError&)
{
}
}; };
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
@ -165,10 +174,10 @@ protected:
class cErrorBucketPassThru : public cErrorBucket class cErrorBucketPassThru : public cErrorBucket
{ {
protected: protected:
virtual void HandleError(const eError& ) {} virtual void HandleError(const eError&)
{
}
}; };
#endif #endif

View File

@ -46,4 +46,3 @@ TSS_EXCEPTION( eBadCmdLine, eErrorGeneral );
TSS_EXCEPTION(eBadModeSwitch, eErrorGeneral); TSS_EXCEPTION(eBadModeSwitch, eErrorGeneral);
#endif //#ifndef __ERRORGENERAL_H #endif //#ifndef __ERRORGENERAL_H

View File

@ -72,10 +72,10 @@ void cErrorTable::AssertMsgValidity(const TCHAR* msg)
// Sunpro got stuck in an infinite loop when we called GetString from this func; // Sunpro got stuck in an infinite loop when we called GetString from this func;
TSTRING::size_type errorSize = 9; TSTRING::size_type errorSize = 9;
TSTRING::size_type warningSize = 10; TSTRING::size_type warningSize = 10;
TSTRING::size_type maxHeaderSize = (errorSize > warningSize ? errorSize : warningSize) + 6; // Add 6 to account for "### ' and ': ' TSTRING::size_type maxHeaderSize =
(errorSize > warningSize ? errorSize : warningSize) + 6; // Add 6 to account for "### ' and ': '
# endif # endif
ASSERT(maxHeaderSize + errSize < 80); ASSERT(maxHeaderSize + errSize < 80);
} }
#endif #endif

View File

@ -113,12 +113,9 @@ inline void cErrorTable::Put( const eError& e, const TCHAR* msg )
RegisterErrors##pkgName::RegisterErrors##pkgName() \ RegisterErrors##pkgName::RegisterErrors##pkgName() \
{ {
#define TSS_REGISTER_ERROR( err, str ) \ # define TSS_REGISTER_ERROR(err, str) cErrorTable::GetInstance()->Put(err, str);
cErrorTable::GetInstance()->Put \
( err, str );
#define TSS_END_ERROR_REGISTRATION() \ # define TSS_END_ERROR_REGISTRATION() }
}
//=================== //===================
// h file macros // h file macros
@ -132,9 +129,7 @@ inline void cErrorTable::Put( const eError& e, const TCHAR* msg )
//=================== //===================
// package init macros // package init macros
//=================== //===================
#define TSS_REGISTER_PKG_ERRORS( pkgName ) \ # define TSS_REGISTER_PKG_ERRORS(pkgName) RegisterErrors##pkgName register##pkgName;
RegisterErrors##pkgName register##pkgName;
#endif //__ERRORTABLE_H #endif //__ERRORTABLE_H

View File

@ -47,10 +47,9 @@ namespace //unique
snprintf(string, size, "%d", value); snprintf(string, size, "%d", value);
return string; return string;
} }
} } // namespace
eInternal::eInternal(TCHAR* sourceFile, int lineNum) eInternal::eInternal(TCHAR* sourceFile, int lineNum) : eError(_T(""))
: eError(_T(""))
{ {
TCHAR buf[256]; TCHAR buf[256];
@ -81,4 +80,3 @@ TSTRING cErrorUtil::MakeFileError( const TSTRING& msg, const TSTRING& fileName )
return ret; return ret;
} }

View File

@ -108,7 +108,11 @@ public:
// TODO: ASSERT is always fatal in Unix, perhaps we could #ifdef the ASSERT // TODO: ASSERT is always fatal in Unix, perhaps we could #ifdef the ASSERT
// to echo to cout the line number the exception occured at? // to echo to cout the line number the exception occured at?
#define ThrowAndAssert(exception) { ASSERT(false); throw exception; } #define ThrowAndAssert(exception) \
{ \
ASSERT(false); \
throw exception; \
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -118,11 +122,8 @@ public:
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// ePoly // ePoly
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
inline ePoly::ePoly( uint32 id, const TSTRING& msg, uint32 flags ) inline ePoly::ePoly(uint32 id, const TSTRING& msg, uint32 flags) : eError(msg, flags), mID(id)
: eError( msg, flags ),
mID( id )
{ {
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -136,11 +137,8 @@ inline ePoly::ePoly( const eError& rhs )
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// ePoly // ePoly
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
inline ePoly::ePoly() inline ePoly::ePoly() : eError(_T("")), mID(0)
: eError( _T("") ),
mID( 0 )
{ {
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -170,4 +168,3 @@ inline void ePoly::SetID( uint32 id )
} }
#endif //__ERRORUTIL_H #endif //__ERRORUTIL_H

View File

@ -88,8 +88,10 @@ public:
// note that reading from the file is implicit // note that reading from the file is implicit
OPEN_READ = 0x00000001, // not needed, but makes calls nice... OPEN_READ = 0x00000001, // not needed, but makes calls nice...
OPEN_WRITE = 0x00000002, // we will be writing to the file OPEN_WRITE = 0x00000002, // we will be writing to the file
OPEN_LOCKED_TEMP = 0x00000004, // the file should not be readable by other processes and should be removed when closed OPEN_LOCKED_TEMP =
OPEN_TRUNCATE = 0x00000008, // opens an empty file. creates it if it doesn't exist. Doesn't make much sense without OF_WRITE 0x00000004, // the file should not be readable by other processes and should be removed when closed
OPEN_TRUNCATE =
0x00000008, // opens an empty file. creates it if it doesn't exist. Doesn't make much sense without OF_WRITE
OPEN_CREATE = 0x00000010, // create the file if it doesn't exist; this is implicit if OF_TRUNCATE is set OPEN_CREATE = 0x00000010, // create the file if it doesn't exist; this is implicit if OF_TRUNCATE is set
OPEN_TEXT = 0x00000020, OPEN_TEXT = 0x00000020,
OPEN_EXCLUSIVE = 0x00000040, // Use O_CREAT | O_EXCL OPEN_EXCLUSIVE = 0x00000040, // Use O_CREAT | O_EXCL
@ -183,4 +185,3 @@ public:
#endif //__FILE_H #endif //__FILE_H

View File

@ -82,9 +82,9 @@ struct cFile_i
}; };
//Ctor //Ctor
cFile_i::cFile_i() : cFile_i::cFile_i() : m_fd(-1), mpCurrStream(NULL), mFlags(0)
m_fd(-1), mpCurrStream(NULL), mFlags(0) {
{} }
//Dtor //Dtor
cFile_i::~cFile_i() cFile_i::~cFile_i()
@ -113,8 +113,7 @@ cFile_i::~cFile_i()
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
cFile::cFile() : cFile::cFile() : mpData(NULL), isWritable(false)
mpData(NULL), isWritable(false)
{ {
mpData = new cFile_i; mpData = new cFile_i;
} }
@ -174,7 +173,8 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
mode = _T("rb"); mode = _T("rb");
} }
if (flags & OPEN_EXCLUSIVE) { if (flags & OPEN_EXCLUSIVE)
{
perm |= O_CREAT | O_EXCL; perm |= O_CREAT | O_EXCL;
openmode = (mode_t)0600; // Make sure only root can read the file openmode = (mode_t)0600; // Make sure only root can read the file
} }
@ -257,7 +257,6 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
ioctl(fh, VX_SETCACHE, VX_SEQ | VX_NOREUSE); ioctl(fh, VX_SETCACHE, VX_SEQ | VX_NOREUSE);
} }
#endif #endif
} }
@ -351,14 +350,19 @@ cFile::File_t cFile::Read( void* buffer, File_t nBytes ) const //throw(eFile)
if (nBytes == 0) if (nBytes == 0)
return 0; return 0;
if (mpData->mFlags & OPEN_DIRECT) { if (mpData->mFlags & OPEN_DIRECT)
{
iBytesRead = read(mpData->m_fd, buffer, nBytes); iBytesRead = read(mpData->m_fd, buffer, nBytes);
if (iBytesRead<0) { if (iBytesRead < 0)
{
throw eFileRead(mpData->mFileName, iFSServices::GetInstance()->GetErrString()); throw eFileRead(mpData->mFileName, iFSServices::GetInstance()->GetErrString());
} }
} else { }
else
{
iBytesRead = fread(buffer, sizeof(byte), nBytes, mpData->mpCurrStream); iBytesRead = fread(buffer, sizeof(byte), nBytes, mpData->mpCurrStream);
if( ferror( mpData->mpCurrStream ) != 0 ) { if (ferror(mpData->mpCurrStream) != 0)
{
throw eFileRead(mpData->mFileName, iFSServices::GetInstance()->GetErrString()); throw eFileRead(mpData->mFileName, iFSServices::GetInstance()->GetErrString());
} }
} }

View File

@ -37,8 +37,7 @@
#include "corestrings.h" #include "corestrings.h"
// TODO: Make this use MakeFileError() for consistency // TODO: Make this use MakeFileError() for consistency
eFileError::eFileError( const TSTRING& filename, const TSTRING& description, uint32 flags ) eFileError::eFileError(const TSTRING& filename, const TSTRING& description, uint32 flags) : eError(_T(""), flags)
: eError( _T(""), flags )
{ {
mFilename = filename; mFilename = filename;
mMsg = description; mMsg = description;
@ -73,4 +72,3 @@ TSTRING eFileError::GetDescription() const
return ret; return ret;
} }

View File

@ -58,10 +58,13 @@ private:
public: public:
eFileError(const TSTRING& filename, const TSTRING& description, uint32 flags = 0); eFileError(const TSTRING& filename, const TSTRING& description, uint32 flags = 0);
explicit eFileError( const eFileError& rhs ) explicit eFileError(const eFileError& rhs) : eError(rhs)
: eError( rhs ) { mFilename = rhs.mFilename; } {
eFileError( const TSTRING& msg, uint32 flags = 0 ) mFilename = rhs.mFilename;
: eError( msg, flags ) {} }
eFileError(const TSTRING& msg, uint32 flags = 0) : eError(msg, flags)
{
}
TSTRING GetFilename() const; TSTRING GetFilename() const;
@ -72,9 +75,9 @@ TSS_END_EXCEPTION()
# define TSS_FILE_EXCEPTION(except, base) \ # define TSS_FILE_EXCEPTION(except, base) \
TSS_BEGIN_EXCEPTION(except, base) \ TSS_BEGIN_EXCEPTION(except, base) \
except( const TSTRING& filename, const TSTRING& msg, uint32 flags = 0 ) \ except(const TSTRING& filename, const TSTRING& msg, uint32 flags = 0) : base(filename, msg, flags) \
: base( filename, msg, flags ) {} \ { \
} \
TSS_END_EXCEPTION() TSS_END_EXCEPTION()
#endif #endif

View File

@ -79,9 +79,7 @@ void cFileHeaderID::operator=( const cFileHeaderID& rhs )
int cFileHeaderID::operator==(const cFileHeaderID& rhs) const int cFileHeaderID::operator==(const cFileHeaderID& rhs) const
{ {
return return (mIDLen == rhs.mIDLen) && (::memcmp(mID, rhs.mID, mIDLen * sizeof(char)) == 0);
( mIDLen == rhs.mIDLen ) &&
( ::memcmp( mID, rhs.mID, mIDLen * sizeof(char) ) == 0 );
} }
void cFileHeaderID::Read(iSerializer* pSerializer, int32 /*version*/) // throw (eSerializer, eArchive) void cFileHeaderID::Read(iSerializer* pSerializer, int32 /*version*/) // throw (eSerializer, eArchive)
@ -108,8 +106,7 @@ void cFileHeaderID::Write(iSerializer* pSerializer) const // throw (eSerializer,
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// class cFileHeader // class cFileHeader
cFileHeader::cFileHeader() cFileHeader::cFileHeader() : mVersion(0)
: mVersion(0)
{ {
#ifdef DEBUG #ifdef DEBUG
mEncoding = LAST_ENCODING; // set to invalid value so we can assert on write mEncoding = LAST_ENCODING; // set to invalid value so we can assert on write
@ -119,20 +116,14 @@ cFileHeader::cFileHeader()
} }
cFileHeader::cFileHeader(const cFileHeader& rhs) cFileHeader::cFileHeader(const cFileHeader& rhs)
: iSerializable(), : iSerializable(), mID(rhs.mID), mVersion(rhs.mVersion), mEncoding(rhs.mEncoding)
mID(rhs.mID),
mVersion(rhs.mVersion),
mEncoding(rhs.mEncoding)
{ {
if (rhs.mBaggage.Length() > 0) if (rhs.mBaggage.Length() > 0)
{ {
mBaggage.MapArchive(0, rhs.mBaggage.Length()); mBaggage.MapArchive(0, rhs.mBaggage.Length());
rhs.mBaggage.MapArchive(0, rhs.mBaggage.Length()); rhs.mBaggage.MapArchive(0, rhs.mBaggage.Length());
::memcpy( ::memcpy(mBaggage.GetMap(), rhs.mBaggage.GetMap(), static_cast<size_t>(rhs.mBaggage.Length()));
mBaggage.GetMap(),
rhs.mBaggage.GetMap(),
static_cast<size_t>( rhs.mBaggage.Length() ) );
mBaggage.MapArchive(0, 0); mBaggage.MapArchive(0, 0);
rhs.mBaggage.MapArchive(0, 0); rhs.mBaggage.MapArchive(0, 0);
@ -250,4 +241,3 @@ void cFileHeader::Write(iSerializer* pSerializer) const // throw (eSerializer, e
pSerializer->WriteBlob(mBaggage.GetMap(), len); pSerializer->WriteBlob(mBaggage.GetMap(), len);
} }
} }

View File

@ -70,7 +70,10 @@ private:
// the program is the only person who will see them. // the program is the only person who will see them.
int16 mIDLen; int16 mIDLen;
enum { MAXBYTES = 256 }; enum
{
MAXBYTES = 256
};
char mID[MAXBYTES]; char mID[MAXBYTES];
}; };
@ -84,9 +87,7 @@ inline cFileHeaderID::cFileHeaderID(const TCHAR* id)
*this = id; *this = id;
} }
inline inline cFileHeaderID::cFileHeaderID(const cFileHeaderID& rhs) : iSerializable(), mIDLen(rhs.mIDLen)
cFileHeaderID::cFileHeaderID( const cFileHeaderID& rhs ) :
iSerializable(), mIDLen( rhs.mIDLen )
{ {
memcpy(mID, rhs.mID, MAXBYTES); memcpy(mID, rhs.mID, MAXBYTES);
} }
@ -163,4 +164,3 @@ inline const cMemoryArchive& cFileHeader::GetBaggage() const
} }
#endif #endif

View File

@ -48,4 +48,3 @@
#define fixed_basic_ofstream std::basic_ofstream #define fixed_basic_ofstream std::basic_ofstream
#endif //__FIXED_FILEBUF_H #endif //__FIXED_FILEBUF_H

View File

@ -43,5 +43,3 @@ iFSServices* iFSServices::mpInstance = 0;
//############################################################################# //#############################################################################
// eFSServices // eFSServices
//############################################################################# //#############################################################################

View File

@ -122,8 +122,10 @@ typedef int64 cFSType;
// this class is used only to pass arguments to iFSServices // this class is used only to pass arguments to iFSServices
// it is the union of MAX(elem) for all the file systems that we support // it is the union of MAX(elem) for all the file systems that we support
struct cFSStatArgs { struct cFSStatArgs
enum FileType { {
enum FileType
{
TY_INVALID, // lazy evaluation TY_INVALID, // lazy evaluation
TY_FILE, TY_FILE,
TY_DIR, TY_DIR,
@ -164,7 +166,6 @@ struct cFSStatArgs {
}; };
//========================================================================= //=========================================================================
// //
// eFSServices -- exception class // eFSServices -- exception class
@ -185,7 +186,9 @@ TSS_FILE_EXCEPTION( eFSServicesGeneric, eFSServices );
class iFSServices class iFSServices
{ {
public: public:
virtual ~iFSServices() {} virtual ~iFSServices()
{
}
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// ENUMS // ENUMS
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
@ -357,4 +360,3 @@ inline void iFSServices::SetInstance( iFSServices* pInst )
#endif #endif

View File

@ -47,7 +47,10 @@ public:
size_t mSize; size_t mSize;
int8* mpData; int8* mpData;
cHeap( size_t size ) : mSize( size ), mpData( new int8[size] ) { ASSERT(mpData != 0); } cHeap(size_t size) : mSize(size), mpData(new int8[size])
{
ASSERT(mpData != 0);
}
// Note: The above ASSERT should never occur! If the new failed we should have thrown a bad_alloc(). // Note: The above ASSERT should never occur! If the new failed we should have thrown a bad_alloc().
}; };
typedef std::vector<cHeap> HeapList; typedef std::vector<cHeap> HeapList;
@ -59,7 +62,10 @@ public:
size_t mCurOff; size_t mCurOff;
cGrowHeap_i(size_t initialSize, size_t growBy, const TCHAR* name); cGrowHeap_i(size_t initialSize, size_t growBy, const TCHAR* name);
~cGrowHeap_i() { Clear(); } ~cGrowHeap_i()
{
Clear();
}
size_t AlignSizeRequest(size_t size, size_t alignSize); size_t AlignSizeRequest(size_t size, size_t alignSize);
void* Malloc(size_t size); void* Malloc(size_t size);
@ -68,10 +74,7 @@ public:
cGrowHeap_i::cGrowHeap_i(size_t initialSize, size_t growBy, const TCHAR* name) cGrowHeap_i::cGrowHeap_i(size_t initialSize, size_t growBy, const TCHAR* name)
: mInitialSize( initialSize ), : mInitialSize(initialSize), mGrowBy(growBy), mName(name), mCurOff(0)
mGrowBy ( growBy ),
mName ( name ),
mCurOff ( 0 )
{ {
// assure that initial size and growby are aligned // assure that initial size and growby are aligned
ASSERT(0 == (initialSize % BYTE_ALIGN)); ASSERT(0 == (initialSize % BYTE_ALIGN));
@ -168,10 +171,9 @@ void cGrowHeap_i::Clear()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// cGrowHeap // cGrowHeap
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
cGrowHeap::cGrowHeap( size_t initialSize, size_t growBy, const TCHAR* name ) : cGrowHeap::cGrowHeap(size_t initialSize, size_t growBy, const TCHAR* name)
mpData( new cGrowHeap_i( initialSize, growBy, name ) ) : mpData(new cGrowHeap_i(initialSize, growBy, name))
{ {
} }
cGrowHeap::~cGrowHeap() cGrowHeap::~cGrowHeap()
@ -191,4 +193,3 @@ void cGrowHeap::Clear()
{ {
mpData->Clear(); mpData->Clear();
} }

View File

@ -69,4 +69,3 @@ private:
#endif #endif

View File

@ -32,5 +32,3 @@
//hashtable.cpp : implementation for hashtable which maps const TCHAR*'s to void*'s //hashtable.cpp : implementation for hashtable which maps const TCHAR*'s to void*'s
#include "stdcore.h" #include "stdcore.h"
#include "hashtable.h" #include "hashtable.h"

View File

@ -67,8 +67,7 @@
// equality. There is also a specialization for TSTRINGS. If neither of these // equality. There is also a specialization for TSTRINGS. If neither of these
// fit your needs, you must pass the hash table your own fn pointer or class // fit your needs, you must pass the hash table your own fn pointer or class
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template<class T> template<class T> class cDefaultCompare
class cDefaultCompare
{ {
public: public:
bool operator()(const T& lhs, const T& rhs) bool operator()(const T& lhs, const T& rhs)
@ -79,8 +78,7 @@ public:
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
// specialization for TSTRINGS // specialization for TSTRINGS
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
template<> template<> inline bool cDefaultCompare<TSTRING>::operator()(const TSTRING& lhs, const TSTRING& rhs)
inline bool cDefaultCompare<TSTRING>::operator()(const TSTRING& lhs, const TSTRING& rhs)
{ {
return (lhs.compare(rhs) == 0); return (lhs.compare(rhs) == 0);
} }
@ -90,8 +88,7 @@ inline bool cDefaultCompare<TSTRING>::operator()(const TSTRING& lhs, const TSTRI
// into a byte* and a key length (for hashing purposes). The default implementation // into a byte* and a key length (for hashing purposes). The default implementation
// just does a cast. A specialization is also provided for TSTRINGs. // just does a cast. A specialization is also provided for TSTRINGs.
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template<class T> template<class T> class cDefaultConvert
class cDefaultConvert
{ {
public: public:
const byte* operator()(const T& obj, int* const pcbKeyLen) const byte* operator()(const T& obj, int* const pcbKeyLen)
@ -104,8 +101,7 @@ public:
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
// specialization for TSTRINGS // specialization for TSTRINGS
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
template<> template<> inline const byte* cDefaultConvert<TSTRING>::operator()(const TSTRING& obj, int* const pcbKeyLen)
inline const byte* cDefaultConvert<TSTRING>::operator()(const TSTRING& obj, int* const pcbKeyLen )
{ {
*pcbKeyLen = sizeof(TCHAR) * obj.length(); *pcbKeyLen = sizeof(TCHAR) * obj.length();
return (byte*)obj.c_str(); return (byte*)obj.c_str();
@ -123,7 +119,8 @@ inline const byte* cDefaultConvert<TSTRING>::operator()(const TSTRING& obj, int*
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// these were moved outside of the class because it sucks to have to name the class with template parameters // these were moved outside of the class because it sucks to have to name the class with template parameters
// ie -- mTable(cHashTable<TSTRING, int>::MEDIUM // ie -- mTable(cHashTable<TSTRING, int>::MEDIUM
enum cHashTable_TableSize { enum cHashTable_TableSize
{
HASH_VERY_SMALL = 17, HASH_VERY_SMALL = 17,
HASH_SMALL = 2007, HASH_SMALL = 2007,
HASH_MEDIUM = 6007, HASH_MEDIUM = 6007,
@ -132,17 +129,25 @@ enum cHashTable_TableSize {
}; };
// forward declaration // forward declaration
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP = cDefaultCompare<KEY_TYPE>, class CONVERTER = cDefaultConvert<KEY_TYPE> > template<class KEY_TYPE,
class VAL_TYPE,
class COMPARE_OP = cDefaultCompare<KEY_TYPE>,
class CONVERTER = cDefaultConvert<KEY_TYPE> >
class cHashTableIter; class cHashTableIter;
//General version of cHashTable template: //General version of cHashTable template:
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP = cDefaultCompare<KEY_TYPE>, class CONVERTER = cDefaultConvert<KEY_TYPE> > template<class KEY_TYPE,
class VAL_TYPE,
class COMPARE_OP = cDefaultCompare<KEY_TYPE>,
class CONVERTER = cDefaultConvert<KEY_TYPE> >
class cHashTable class cHashTable
{ {
friend class cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>; friend class cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>;
public: public:
//structure for hash table nodes. //structure for hash table nodes.
struct node { struct node
{
KEY_TYPE nKey; KEY_TYPE nKey;
VAL_TYPE nData; VAL_TYPE nData;
node* next; node* next;
@ -169,7 +174,10 @@ public:
bool IsEmpty(void) const; bool IsEmpty(void) const;
uint32 Hash(const KEY_TYPE& key) const; uint32 Hash(const KEY_TYPE& key) const;
//The hashing function, taken from old Tripwire //The hashing function, taken from old Tripwire
int32 GetNumValues() const { return mValuesInTable; }; int32 GetNumValues() const
{
return mValuesInTable;
};
// returns number of table entries filled // returns number of table entries filled
#ifdef DEBUG #ifdef DEBUG
@ -190,8 +198,7 @@ private:
// cHashTableIter // cHashTableIter
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER> template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER> class cHashTableIter
class cHashTableIter
{ {
public: public:
cHashTableIter(const cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>& hashTbl); cHashTableIter(const cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>& hashTbl);
@ -214,7 +221,6 @@ private:
}; };
//############################################################################# //#############################################################################
// implementation // implementation
@ -222,8 +228,9 @@ private:
// iterator // iterator
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER> template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
inline cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::cHashTableIter( const cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>& hashTbl) : inline cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::cHashTableIter(
mHashTable(hashTbl) const cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>& hashTbl)
: mHashTable(hashTbl)
{ {
SeekBegin(); SeekBegin();
} }
@ -334,7 +341,8 @@ bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Insert(KEY_TYPE key,
COMPARE_OP compare; COMPARE_OP compare;
int hindex = Hash(key); int hindex = Hash(key);
if (mTable[hindex] == NULL) { if (mTable[hindex] == NULL)
{
//open index, perform insert //open index, perform insert
mTable[hindex] = new node; mTable[hindex] = new node;
(mTable[hindex])->nKey = key; (mTable[hindex])->nKey = key;
@ -393,19 +401,20 @@ bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Insert(KEY_TYPE key,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// General Version: // General Version:
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER> template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
bool bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Lookup(KEY_TYPE key, VAL_TYPE& d_out) const
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Lookup(KEY_TYPE key, VAL_TYPE& d_out) const
{ {
COMPARE_OP compare; COMPARE_OP compare;
int hindex = Hash(key); int hindex = Hash(key);
if (mTable[hindex] == NULL) if (mTable[hindex] == NULL)
return false; return false;
else { else
{
node* nodeptr = mTable[hindex]; node* nodeptr = mTable[hindex];
while (nodeptr != NULL) while (nodeptr != NULL)
{ {
if( compare(nodeptr->nKey, key)) { if (compare(nodeptr->nKey, key))
{
d_out = nodeptr->nData; d_out = nodeptr->nData;
return true; return true;
} }
@ -421,21 +430,23 @@ cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Lookup(KEY_TYPE key, VAL_
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// General Version - // General Version -
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER> template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
bool bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Remove(KEY_TYPE key)
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Remove(KEY_TYPE key)
{ {
COMPARE_OP compare; COMPARE_OP compare;
int hindex = Hash(key); int hindex = Hash(key);
if (mTable[hindex] == NULL) { if (mTable[hindex] == NULL)
{
delete (mTable[hindex]); delete (mTable[hindex]);
mTable[hindex] = NULL; mTable[hindex] = NULL;
return true; return true;
} }
else { else
{
node* nodeptr = mTable[hindex]; node* nodeptr = mTable[hindex];
node* prev; node* prev;
while(nodeptr != NULL) { while (nodeptr != NULL)
{
prev = nodeptr; prev = nodeptr;
if (compare(mTable[hindex]->nKey, key)) if (compare(mTable[hindex]->nKey, key))
{ {
@ -456,15 +467,16 @@ cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Remove(KEY_TYPE key)
// Clear -- Clears entire hash table so that all indices are NULL // Clear -- Clears entire hash table so that all indices are NULL
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER> template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
bool bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Clear(void)
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Clear(void)
{ {
for (int i = 0; i < mTableSize; ++i) for (int i = 0; i < mTableSize; ++i)
{ {
if (mTable[i] != NULL) { if (mTable[i] != NULL)
{
node* curr = mTable[i]; node* curr = mTable[i];
node* del; node* del;
while(curr != NULL) { while (curr != NULL)
{
del = curr; del = curr;
curr = curr->next; curr = curr->next;
delete del; delete del;
@ -482,8 +494,7 @@ cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Clear(void)
// IsEmpty -- // IsEmpty --
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER> template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
bool bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::IsEmpty(void) const
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::IsEmpty(void) const
{ {
bool ret = true; bool ret = true;
for (int i = 0; i < mTableSize; ++i) for (int i = 0; i < mTableSize; ++i)
@ -538,12 +549,15 @@ void cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::TraceDiagnostics() c
d.TraceDebug("---------------Hash Table Statisics---------------\n"); d.TraceDebug("---------------Hash Table Statisics---------------\n");
d.TraceDebug("-- Number of slots: %d\n", mTableSize); d.TraceDebug("-- Number of slots: %d\n", mTableSize);
d.TraceDebug("-- Number of items: %d\n", numItems); d.TraceDebug("-- Number of items: %d\n", numItems);
d.TraceDebug("-- Slots filled: %d (%lf %%)\n",slotsFilled, ((double)slotsFilled / (double)mTableSize) * 100.0); d.TraceDebug("-- Slots filled: %d (%lf %%)\n",
d.TraceDebug("-- Slots with >1 item: %d (%lf %%)\n",numMultiSlot, ((double)numMultiSlot / (double)slotsFilled) * 100.0); slotsFilled,
((double)slotsFilled / (double)mTableSize) * 100.0);
d.TraceDebug("-- Slots with >1 item: %d (%lf %%)\n",
numMultiSlot,
((double)numMultiSlot / (double)slotsFilled) * 100.0);
d.TraceDebug("--------------------------------------------------\n"); d.TraceDebug("--------------------------------------------------\n");
} }
# endif // DEBUG # endif // DEBUG
#endif //__HASHTABLE_H #endif //__HASHTABLE_H

View File

@ -66,11 +66,20 @@
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#if (WCHAR_IS_16_BITS) #if (WCHAR_IS_16_BITS)
namespace tss { typedef std::wstring dbstring; } namespace tss
{
typedef std::wstring dbstring;
}
#elif (WCHAR_IS_32_BITS) #elif (WCHAR_IS_32_BITS)
namespace std { template <> struct char_traits< dbchar_t >; } namespace std
namespace tss { typedef std::basic_string<dbchar_t> dbstring; } {
template<> struct char_traits<dbchar_t>;
}
namespace tss
{
typedef std::basic_string<dbchar_t> dbstring;
}
#else #else
# error "wchar_t is not correctly factored!" # error "wchar_t is not correctly factored!"
@ -84,8 +93,7 @@
// specialize *std*::char_traits!!! // specialize *std*::char_traits!!!
template<> template<> struct std::char_traits<dbchar_t>
struct std::char_traits< dbchar_t >
{ {
typedef dbchar_t char_type; typedef dbchar_t char_type;
typedef wint_t int_type; typedef wint_t int_type;
@ -98,23 +106,22 @@ struct std::char_traits< dbchar_t >
typedef int state_type; // Shame on you KAI! This is ANSI-C! typedef int state_type; // Shame on you KAI! This is ANSI-C!
# endif # endif
static static void assign(char_type& lhs, const char_type& rhs)
void assign( char_type& lhs, const char_type& rhs ) { {
lhs = rhs; lhs = rhs;
} }
static static bool eq(const char_type& lhs, const char_type& rhs)
bool eq( const char_type& lhs, const char_type& rhs ) { {
return lhs == rhs; return lhs == rhs;
} }
static static bool lt(const char_type& lhs, const char_type& rhs)
bool lt( const char_type& lhs, const char_type& rhs ) { {
return lhs < rhs; return lhs < rhs;
} }
static static int compare(const char_type* lhs, const char_type* rhs, size_t N)
int compare( const char_type* lhs, const char_type* rhs, size_t N )
{ {
for (; N; ++lhs, ++rhs, --N) for (; N; ++lhs, ++rhs, --N)
if (*lhs != *rhs) if (*lhs != *rhs)
@ -123,21 +130,20 @@ struct std::char_traits< dbchar_t >
return 0; return 0;
} }
static static size_t length(const char_type* psz)
size_t length( const char_type* psz )
{ {
if (psz == 0) if (psz == 0)
return 0; return 0;
else else
{ {
const char_type* end; const char_type* end;
for ( end = psz; *end; end++ ); for (end = psz; *end; end++)
;
return (size_t)(end - psz); return (size_t)(end - psz);
} }
} }
static static char_type* copy(char_type* lhs, const char_type* rhs, size_t N)
char_type* copy( char_type* lhs, const char_type* rhs, size_t N )
{ {
for (char_type* at = lhs; N; ++at, ++rhs, --N) for (char_type* at = lhs; N; ++at, ++rhs, --N)
*at = *rhs; *at = *rhs;
@ -145,9 +151,7 @@ struct std::char_traits< dbchar_t >
return lhs; return lhs;
} }
static static const char_type* find(const char_type* psz, size_t N, const char_type& ch)
const char_type*
find( const char_type* psz, size_t N, const char_type& ch )
{ {
for (; N; ++psz, --N) for (; N; ++psz, --N)
if (*psz == ch) if (*psz == ch)
@ -156,40 +160,35 @@ struct std::char_traits< dbchar_t >
return 0; return 0;
} }
static static char_type* move(char_type* lhs, const char_type* rhs, size_t N)
char_type* move( char_type* lhs, const char_type* rhs, size_t N ) { {
return (char_type*)memmove(lhs, rhs, N * sizeof(char_type)); return (char_type*)memmove(lhs, rhs, N * sizeof(char_type));
} }
static static char_type* assign(char_type* lhs, size_t N, char_type ch)
char_type* assign( char_type* lhs, size_t N, char_type ch )
{ {
for (char_type* at = lhs; N; ++at, --N) for (char_type* at = lhs; N; ++at, --N)
*at = ch; *at = ch;
return lhs; return lhs;
} }
static static int_type not_eof(const int_type& ch)
int_type not_eof( const int_type& ch ) { {
return int_type(!eq(ch, eof()) ? ch : ~ch); return int_type(!eq(ch, eof()) ? ch : ~ch);
} }
static static char_type to_char_type(const int_type& ch)
char_type to_char_type( const int_type& ch )
{ {
return return eq_int_type(ch, to_int_type(ch)) ? ch : char_type(0);
eq_int_type( ch, to_int_type( ch ) )
? ch
: char_type(0);
} }
static static int_type to_int_type(const char_type& ch)
int_type to_int_type( const char_type& ch ) { {
return (int_type)ch; return (int_type)ch;
} }
static static bool eq_int_type(const int_type& lhs, const int_type& rhs)
bool eq_int_type( const int_type& lhs, const int_type& rhs ) { {
return lhs == rhs; return lhs == rhs;
} }
@ -198,31 +197,31 @@ struct std::char_traits< dbchar_t >
// CAUTION:RAD -- Extra members required by Modena!! // CAUTION:RAD -- Extra members required by Modena!!
# ifdef MBSTATE_T_DEFINED // This is ANSI-C *not* ANSI-C++!! # ifdef MBSTATE_T_DEFINED // This is ANSI-C *not* ANSI-C++!!
static static state_type get_state(pos_type pos)
state_type get_state( pos_type pos ) { {
return pos.state(); return pos.state();
} }
static static pos_type get_pos(pos_type pos, state_type state)
pos_type get_pos( pos_type pos, state_type state ) { {
return pos_type(pos.offset(), state); return pos_type(pos.offset(), state);
} }
# endif //MBSTATE_T_DEFINED # endif //MBSTATE_T_DEFINED
static static char_type newline()
char_type newline() { {
return L'\n'; return L'\n';
} }
static static char_type eos()
char_type eos() { {
return 0; return 0;
} }
# endif //IS_STDLIB_MODENA # endif //IS_STDLIB_MODENA
static static int_type eof()
int_type eof() { {
return (wint_t)(0xFFFF); return (wint_t)(0xFFFF);
} }
}; };
@ -231,4 +230,3 @@ struct std::char_traits< dbchar_t >
#endif //__NTDBS_H #endif //__NTDBS_H

View File

@ -47,13 +47,11 @@
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#ifndef TSS_Raise // Should add file and line info in DEBUG mode!!!! #ifndef TSS_Raise // Should add file and line info in DEBUG mode!!!!
#define TSS_Raise( Xcpt, pkg, ids ) \ # define TSS_Raise(Xcpt, pkg, ids) throw Xcpt(TSS_GetString(pkg, ids))
throw Xcpt( TSS_GetString( pkg, ids ) )
#endif //TSS_Raise #endif //TSS_Raise
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// NTMBS Utils -- Definition // NTMBS Utils -- Definition
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -134,8 +132,7 @@ tss::mbsdec( const_ntmbs_t beg, const_ntmbs_t curr )
* POSTCONDITIONS: * POSTCONDITIONS:
* Returns non-const pointer after moving it. * Returns non-const pointer after moving it.
*/ */
ntmbs_t ntmbs_t tss::mbsinc(const_ntmbs_t psz)
tss::mbsinc( const_ntmbs_t psz )
{ {
cDebug dbg("tss::mbsinc -"); cDebug dbg("tss::mbsinc -");
@ -153,10 +150,7 @@ tss::mbsinc( const_ntmbs_t psz )
} }
dbg.TraceDebug("Incorrectly Formed, Cannot Normalize!\n"); dbg.TraceDebug("Incorrectly Formed, Cannot Normalize!\n");
TSS_Raise( TSS_Raise(eCharacterEncoding, cCore, core::STR_ERR_BADCHAR);
eCharacterEncoding,
cCore,
core::STR_ERR_BADCHAR );
} }
return (((ntmbs_t)psz) + nBytes); return (((ntmbs_t)psz) + nBytes);
@ -180,8 +174,7 @@ tss::mbsinc( const_ntmbs_t psz )
* POSTCONDITIONS: * POSTCONDITIONS:
* Returns size_t value indicating bytes in the range of [0,nCount). * Returns size_t value indicating bytes in the range of [0,nCount).
*/ */
size_t size_t tss::mbsbytes(const_ntmbs_t psz, size_t nCount)
tss::mbsbytes( const_ntmbs_t psz, size_t nCount )
{ {
const_ntmbs_t at = psz; const_ntmbs_t at = psz;
while (nCount--) while (nCount--)
@ -192,21 +185,19 @@ tss::mbsbytes( const_ntmbs_t psz, size_t nCount )
/// To Null terminator /// To Null terminator
size_t size_t tss::mbsbytes(const_ntmbs_t psz)
tss::mbsbytes( const_ntmbs_t psz )
{ {
if (psz == 0) if (psz == 0)
throw eCharacter(TSS_GetString(cCore, core::STR_ERR_ISNULL)); throw eCharacter(TSS_GetString(cCore, core::STR_ERR_ISNULL));
const_ntmbs_t at; const_ntmbs_t at;
for ( at = psz; *at; ++at ); for (at = psz; *at; ++at)
;
return (size_t)((char*)at - (char*)psz); return (size_t)((char*)at - (char*)psz);
} }
/* /*
* TSS::mbscount * TSS::mbscount
* *
@ -224,25 +215,22 @@ tss::mbsbytes( const_ntmbs_t psz )
* POSTCONDITIONS: * POSTCONDITIONS:
* Returns size_t value indicating characters in the range of [psz + 0, psz + nBytes). * Returns size_t value indicating characters in the range of [psz + 0, psz + nBytes).
*/ */
size_t size_t tss_mbscount(const_ntmbs_t psz, size_t nBytes)
tss_mbscount( const_ntmbs_t psz, size_t nBytes )
{ {
size_t nCount = 0; size_t nCount = 0;
const_ntmbs_t at = psz; const_ntmbs_t at = psz;
const_ntmbs_t end = psz + nBytes; const_ntmbs_t end = psz + nBytes;
for ( ; at < end; nCount++, at = tss::mbsinc( at ) ); for (; at < end; nCount++, at = tss::mbsinc(at))
;
return nCount; return nCount;
} }
/// To Null terminator /// To Null terminator
size_t size_t tss::mbscount(const_ntmbs_t psz)
tss::mbscount( const_ntmbs_t psz )
{ {
size_t nCount = 0; size_t nCount = 0;
for ( ; *psz; psz = tss::mbsinc( psz ), nCount++ ); for (; *psz; psz = tss::mbsinc(psz), nCount++)
;
return nCount; return nCount;
} }

View File

@ -78,7 +78,6 @@
#endif //NTWCS_T_DEFINED #endif //NTWCS_T_DEFINED
/// NOTE: Size Specific (2 [double] or 4 [quad] byte wide characters) /// NOTE: Size Specific (2 [double] or 4 [quad] byte wide characters)
//--Null-terminated double(2)-byte Character Sequence //--Null-terminated double(2)-byte Character Sequence
@ -109,7 +108,6 @@
#endif //NTQBS_T_DEFINED #endif //NTQBS_T_DEFINED
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// NTMBS Manipulators // NTMBS Manipulators
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -131,10 +129,11 @@ namespace tss
size_t mbsbytes(const_ntmbs_t); size_t mbsbytes(const_ntmbs_t);
size_t mbscount(const_ntmbs_t); size_t mbscount(const_ntmbs_t);
inline size_t mbslen( const_ntmbs_t psz ) { // RAD: Yeesh! inline size_t mbslen(const_ntmbs_t psz)
{ // RAD: Yeesh!
return tss::mbscount(psz); return tss::mbscount(psz);
} }
}//tss:: } // namespace tss
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -149,9 +148,8 @@ namespace tss
//--DEC //--DEC
template< class CT > template<class CT> inline CT* strdec(const CT*, const CT* psz)
inline {
CT* strdec( const CT*, const CT* psz ) {
return const_cast<CT*>(psz - 1); return const_cast<CT*>(psz - 1);
} }
@ -166,33 +164,25 @@ namespace tss
//--INC //--INC
template< class CT > template<class CT> inline CT* strinc(const CT* psz)
inline
CT* strinc( const CT* psz )
{ {
ASSERT(psz); ASSERT(psz);
return const_cast<CT*>((*psz ? psz + 1 : psz)); return const_cast<CT*>((*psz ? psz + 1 : psz));
} }
template< class CT, class SIZET > template<class CT, class SIZET> inline CT* strinc(const CT* psz, SIZET N)
inline
CT* strinc( const CT* psz, SIZET N )
{ {
ASSERT(psz); ASSERT(psz);
return const_cast<CT*>((*psz ? psz + N : psz)); return const_cast<CT*>((*psz ? psz + N : psz));
} }
template<> template<> inline ntmbs_t strinc(const_ntmbs_t psz)
inline
ntmbs_t strinc( const_ntmbs_t psz )
{ {
return tss::mbsinc(psz); return tss::mbsinc(psz);
} }
template<> template<> inline ntmbs_t strinc(const_ntmbs_t psz, size_t N)
inline
ntmbs_t strinc( const_ntmbs_t psz, size_t N )
{ {
ntmbs_t at = const_cast<ntmbs_t>(psz); ntmbs_t at = const_cast<ntmbs_t>(psz);
while (N--) while (N--)
@ -206,52 +196,50 @@ namespace tss
//--BYTES //--BYTES
template< class CT > template<class CT> size_t strsize(const CT* psz)
size_t strsize( const CT* psz )
{ {
const CT* at = psz; const CT* at = psz;
while ( *at ) at++; while (*at)
at++;
return (size_t)((char*)at - (char*)psz); return (size_t)((char*)at - (char*)psz);
} }
template< class CT > template<class CT> size_t strsize(const CT*, size_t N)
size_t strsize( const CT*, size_t N )
{ {
return N * sizeof(CT); return N * sizeof(CT);
} }
template<> template<> inline size_t strsize(const_ntmbs_t psz)
inline size_t strsize( const_ntmbs_t psz ) { {
return mbsbytes(psz); return mbsbytes(psz);
} }
template<> template<> inline size_t strsize(const_ntmbs_t psz, size_t N)
inline size_t strsize( const_ntmbs_t psz, size_t N ) { {
return mbsbytes(psz, N); return mbsbytes(psz, N);
} }
//--COUNT //--COUNT
template< class CT > template<class CT> size_t strcount(const CT* psz)
size_t strcount( const CT* psz )
{ {
const CT* at = psz; const CT* at = psz;
while ( *at ) at++; while (*at)
at++;
return (size_t)(at - psz); return (size_t)(at - psz);
} }
template< class CT > template<class CT> size_t strcount(const CT*, size_t N)
size_t strcount( const CT*, size_t N )
{ {
return N; return N;
} }
template<> template<> inline size_t strcount(const_ntmbs_t psz)
inline size_t strcount( const_ntmbs_t psz ) { {
return mbscount(psz); return mbscount(psz);
} }
template<> template<> inline size_t strcount(const_ntmbs_t psz, size_t N)
inline size_t strcount( const_ntmbs_t psz, size_t N ) { {
return mbscount(psz, N); return mbscount(psz, N);
} }
@ -274,23 +262,21 @@ done with it */
//--FIND_FIRST: ITER //--FIND_FIRST: ITER
template< class InputT, class E > template<class InputT, class E> InputT find_first(InputT beg, InputT end, const E& item)
InputT
find_first( InputT beg, InputT end, const E& item )
{ {
for ( ; beg < end && *beg != item; beg = (InputT)tss::strinc( beg ) ); for (; beg < end && *beg != item; beg = (InputT)tss::strinc(beg))
;
return beg; return beg;
} }
//--FIND_LAST: ITER //--FIND_LAST: ITER
template< class InputT, class E > template<class InputT, class E> InputT find_last(InputT beg, InputT end, const E& item)
InputT
find_last( InputT beg, InputT end, const E& item )
{ {
InputT at = end; InputT at = end;
for ( ; beg < end ; beg = (InputT)tss::strinc( beg ) ); for (; beg < end; beg = (InputT)tss::strinc(beg))
;
if (*beg == item) if (*beg == item)
at = beg; at = beg;
@ -300,12 +286,9 @@ done with it */
//--FIND_FIRST: STRING //--FIND_FIRST: STRING
template< class StrT > template<class StrT> StrT::size_type find_first(const StrT& sin, StrT::const_reference item)
StrT::size_type
find_first( const StrT& sin, StrT::const_reference item )
{ {
StrT::const_iterator StrT::const_iterator beg = sin.begin();
beg = sin.begin();
end = sin.end(); end = sin.end();
StrT::size_type N; StrT::size_type N;
@ -319,17 +302,15 @@ done with it */
//--FIND_LAST: STRING //--FIND_LAST: STRING
template< class StrT > template<class StrT> StrT::size_type find_last(const StrT& sin, StrT::const_reference item)
StrT::size_type
find_last( const StrT& sin, StrT::const_reference item )
{ {
StrT::size_type N = 0; StrT::size_type N = 0;
StrT::size_type nResult = StrT::npos; StrT::size_type nResult = StrT::npos;
StrT::const_iterator StrT::const_iterator beg = sin.begin();
beg = sin.begin();
end = sin.end(); end = sin.end();
for ( ; beg < end ; beg = (InputT)tss::strinc( beg ) ); for (; beg < end; beg = (InputT)tss::strinc(beg))
;
if (*beg == item) if (*beg == item)
nResult = N; nResult = N;
@ -339,16 +320,11 @@ done with it */
//--FIND_FIRST_OF: ITER //--FIND_FIRST_OF: ITER
template< class InputT > template<class InputT> InputT find_first_of(InputT beg, InputT end, InputT setbeg, InputT setend)
InputT
find_first_of(
InputT beg,
InputT end,
InputT setbeg,
InputT setend )
{ {
InputT at; InputT at;
for ( ; beg < end; beg = (InputT)tss::strinc( beg ) ); for (; beg < end; beg = (InputT)tss::strinc(beg))
;
for (at = setbeg; setbeg < setend; at = (InputT)tss::strinc(at)) for (at = setbeg; setbeg < setend; at = (InputT)tss::strinc(at))
if (*beg == *at) if (*beg == *at)
return beg; return beg;
@ -359,9 +335,7 @@ done with it */
//--FIND_FIRST_OF: STRING (SAFE!!!) //--FIND_FIRST_OF: STRING (SAFE!!!)
template< class StrT > template<class StrT> StrT::size_type find_first_of(const StrT& sin, StrT::const_iterator set)
StrT::size_type
find_first_of( const StrT& sin, StrT::const_iterator set )
{ {
// Point to beg of input // Point to beg of input
StrT::iterator beg = sin.begin(); StrT::iterator beg = sin.begin();
@ -380,12 +354,7 @@ done with it */
//--FIND_FIRST_OF: STRING (NOT SAFE!!!) //--FIND_FIRST_OF: STRING (NOT SAFE!!!)
template<class StrT> template<class StrT>
StrT::size_type StrT::size_type find_first_of(const StrT& sin, StrT::const_iterator set, StrT::size_type nPos, StrT::size_type nCount)
find_first_of(
const StrT& sin,
StrT::const_iterator set,
StrT::size_type nPos,
StrT::size_type nCount )
{ {
ASSERT( nPos < tss::strcount( sin.begin() ); ASSERT( nPos < tss::strcount( sin.begin() );
@ -393,7 +362,8 @@ done with it */
{ {
ASSERT(nCount > tss::strcount(set)); ASSERT(nCount > tss::strcount(set));
StrT::const_iterator endset; // Get end of set StrT::const_iterator endset; // Get end of set
while ( nCount-- ) endset++; while (nCount--)
endset++;
// Advance to nPos // Advance to nPos
StrT::const_iterator at = tss::strinc(sin.begin(), nPos); StrT::const_iterator at = tss::strinc(sin.begin(), nPos);
@ -415,13 +385,11 @@ done with it */
//--FIND_LAST_OF: ITER //--FIND_LAST_OF: ITER
template<class InputT1, class InputT2> template<class InputT1, class InputT2>
InputT InputT find_last_of(const InputT1 beg, const InputT1 end, const InputT2 setbeg, const InputT2 setend)
find_last_of(
const InputT1 beg, const InputT1 end,
const InputT2 setbeg, const InputT2 setend )
{ {
const InputT1 ans = end; const InputT1 ans = end;
for ( ; beg < end; beg = tss::strinc( beg ) ); for (; beg < end; beg = tss::strinc(beg))
;
for (InputT2 at = setbeg; setbeg != setend; at = tss::strinc(at)) for (InputT2 at = setbeg; setbeg != setend; at = tss::strinc(at))
if (*beg == *at) if (*beg == *at)
ans = beg; ans = beg;
@ -432,9 +400,7 @@ done with it */
//--FIND_LAST_OF: STRING (SAFE!!!) //--FIND_LAST_OF: STRING (SAFE!!!)
template< class StrT > template<class StrT> StrT::size_type find_last_of(const StrT& sin, StrT::const_iterator set)
StrT::size_type
find_last_of( const StrT& sin, StrT::const_iterator set )
{ {
StrT::size_type nResult = StrT::npos; StrT::size_type nResult = StrT::npos;
StrT::size_type N = 0; StrT::size_type N = 0;
@ -450,17 +416,11 @@ done with it */
template<class StrT> template<class StrT>
StrT::size_type StrT::size_type find_last_of(const StrT& sin, StrT::const_iterator set, StrT::size_type nStart, StrT::size_type nCount)
find_last_of(
const StrT& sin,
StrT::const_iterator set,
StrT::size_type nStart,
StrT::size_type nCount )
{ {
if (nCount > 0 && sin.size()) if (nCount > 0 && sin.size())
{ {
for ( StrT::const_iterator at = sin.begin() for (StrT::const_iterator at = sin.begin() + (nStart < _Len ? nStart : _Len - 1);; --_U)
+ (nStart < _Len ? nStart : _Len - 1); ; --_U)
if (_Tr::find(set, nCount, *_U) != 0) if (_Tr::find(set, nCount, *_U) != 0)
return (_U - _Ptr); return (_U - _Ptr);
else if (_U == _Ptr) else if (_U == _Ptr)
@ -479,10 +439,7 @@ done with it */
{ {
// Preserves bit values when enlarging a type to a size_t // Preserves bit values when enlarging a type to a size_t
// Good for preventing sign extension // Good for preventing sign extension
template< class E > template<class E> inline size_t char_to_size(E ch)
inline
size_t
char_to_size( E ch )
{ {
// if this fails, 'ch' can't be cast to a // if this fails, 'ch' can't be cast to a
// size_t and preserve bit values // size_t and preserve bit values
@ -498,15 +455,12 @@ done with it */
} }
inline inline size_t char_to_size(char ch)
size_t
char_to_size( char ch )
{ {
return (size_t)(unsigned char)ch; return (size_t)(unsigned char)ch;
} }
} } // namespace util
}//tss:: } // namespace tss
#endif //__NTMBS_H #endif //__NTMBS_H

View File

@ -91,12 +91,9 @@
//--PACKAGE Helpers //--PACKAGE Helpers
#define TSS_Package( pkg ) \ #define TSS_Package(pkg) pkg::GetInstance() // Access "the" Package obj
pkg::GetInstance() // Access "the" Package obj
#define TSS_Dependency( pkg ) \
TSS_Package( pkg ) // Declare a Package Depend.
#define TSS_Dependency(pkg) TSS_Package(pkg) // Declare a Package Depend.
#define TSS_BeginPackage(pkg) \ #define TSS_BeginPackage(pkg) \
@ -107,7 +104,8 @@
#define TSS_EndPackage(pkg) \ #define TSS_EndPackage(pkg) \
}; } \
;
#define TSS_ImplementPackage(pkg) \ #define TSS_ImplementPackage(pkg) \
pkg& pkg::GetInstance() \ pkg& pkg::GetInstance() \
@ -123,21 +121,19 @@
} }
//--STRINGTABLE Helperfs //--STRINGTABLE Helperfs
#define TSS_GetString( pkg, id ) \ #define TSS_GetString(pkg, id) TSS_Package(pkg).GetString(id) // Access the Message String
TSS_Package( pkg ).GetString( id ) // Access the Message String
#define TSS_DECLARE_STRINGTABLE \ #define TSS_DECLARE_STRINGTABLE \
public: \ public: \
Messages::String \ Messages::String GetString(Messages::ConstKeyRef id) const \
GetString( \ { \
Messages::ConstKeyRef id ) const { \ return m_messages.Get(id); \
return m_messages.Get( id ); } \ } \
void LoadStrings(); \ void LoadStrings(); \
\
private: \ private: \
Messages m_messages // Decare a Stringtable Messages m_messages // Decare a Stringtable
@ -145,30 +141,36 @@
#ifdef DEBUG #ifdef DEBUG
# define TSS_BeginStringtable(pkg) \ # define TSS_BeginStringtable(pkg) \
void pkg::LoadStrings() \ void pkg::LoadStrings() \
{ cDebug d( #pkg "::LoadStrings()" ); \ { \
cDebug d(#pkg "::LoadStrings()"); \
d.TraceDebug("Loading strings for " #pkg " package.\n"); \ d.TraceDebug("Loading strings for " #pkg " package.\n"); \
Messages::Pair astr[] = { // Define a Stringtable Messages::Pair astr[] = { // Define a Stringtable
#else // DEBUG #else // DEBUG
# define TSS_BeginStringtable(pkg) \ # define TSS_BeginStringtable(pkg) \
void pkg::LoadStrings() \ void pkg::LoadStrings() \
{ Messages::Pair astr[] = { // Define a Stringtable { \
Messages::Pair astr[] = { // Define a Stringtable
#endif // DEBUG #endif // DEBUG
#define TSS_EndStringtable(pkg) \ #define TSS_EndStringtable(pkg) \
}; m_messages.Put( \ } \
astr, astr + countof(astr) ); } // End define Strintable ; \
m_messages.Put(astr, astr + countof(astr)); \
} // End define Strintable
#define TSS_StringEntry( id, s ) \ #define TSS_StringEntry(id, s) Messages::Pair(id, s) // Stringtable Entry
Messages::Pair( id, s ) // Stringtable Entry
#define TSS_BeginStringIds(pns) \ #define TSS_BeginStringIds(pns) \
namespace pns { \ namespace pns \
enum { // Define String IDs { \
enum \
{ // Define String IDs
#define TSS_EndStringIds(pns) \ #define TSS_EndStringIds(pns) \
}; } // End define String IDs } \
; \
} // End define String IDs
//============================================================================= //=============================================================================
@ -194,11 +196,9 @@
// //
// //
template< class CharT > template<class CharT> class cPackageBase_
class cPackageBase_
{ {
public: public:
typedef cMessages_<int, CharT> Messages; typedef cMessages_<int, CharT> Messages;
void LoadStrings() void LoadStrings()
@ -208,4 +208,3 @@ class cPackageBase_
#endif //__PACKAGE_H #endif //__PACKAGE_H

View File

@ -249,7 +249,6 @@
# endif # endif
/* XXX: COMP may now not resolve, because autoconf may /* XXX: COMP may now not resolve, because autoconf may
* detect GCC. This is done in the hopes that all * detect GCC. This is done in the hopes that all
* COMP detections, and indeed both OS & COMP detechtions * COMP detections, and indeed both OS & COMP detechtions
@ -293,7 +292,9 @@
// complier detection // complier detection
#define IS_KAI (COMP == COMP_KAI_GCC || COMP == COMP_KAI_SUNPRO || COMP == COMP_KAI_GLIBC || COMP == COMP_KAI_VISUALAGE || COMP == COMP_KAI_HPANSIC || COMP == COMP_KAI_IRIX || COMP == COMP_KAI_OSF1ALPHA) # define IS_KAI \
(COMP == COMP_KAI_GCC || COMP == COMP_KAI_SUNPRO || COMP == COMP_KAI_GLIBC || COMP == COMP_KAI_VISUALAGE || \
COMP == COMP_KAI_HPANSIC || COMP == COMP_KAI_IRIX || COMP == COMP_KAI_OSF1ALPHA)
# define IS_MSVC (COMP == COMP_MSVC) # define IS_MSVC (COMP == COMP_MSVC)
# define IS_SUNPRO (COMP == COMP_SUNPRO) # define IS_SUNPRO (COMP == COMP_SUNPRO)
@ -306,9 +307,12 @@
# define IS_KAI_3_4 (IS_KAI && (COMP == COMP_KAI_IRIX || COMP == COMP_KAI_OSF1ALPHA || COMP == COMP_KAI_GLIBC)) # define IS_KAI_3_4 (IS_KAI && (COMP == COMP_KAI_IRIX || COMP == COMP_KAI_OSF1ALPHA || COMP == COMP_KAI_GLIBC))
// Used in twlocale // Used in twlocale
#define USE_STD_CPP_LOCALE_WORKAROUND (IS_SUNPRO || (IS_KAI && !IS_KAI_3_4)) // TODO:BAM -- name this something more general. # define USE_STD_CPP_LOCALE_WORKAROUND \
(IS_SUNPRO || (IS_KAI && !IS_KAI_3_4)) // TODO:BAM -- name this something more general.
# define USE_CLIB_LOCALE IS_KAI || HAVE_GCC # define USE_CLIB_LOCALE IS_KAI || HAVE_GCC
#define USES_CLIB_DATE_FUNCTION ( USE_CLIB_LOCALE || IS_SUNPRO || IS_MSVC ) // if we use clib, can't use C++ time_put, and SUNPRO and MSVC add characters # define USES_CLIB_DATE_FUNCTION \
(USE_CLIB_LOCALE || IS_SUNPRO || \
IS_MSVC) // if we use clib, can't use C++ time_put, and SUNPRO and MSVC add characters
//#define USE_CLIB_LOCALE (IS_ALPHA || IS_IRIX || (IS_KAI && !IS_KAI_3_4)) //#define USE_CLIB_LOCALE (IS_ALPHA || IS_IRIX || (IS_KAI && !IS_KAI_3_4))
// Threading API // Threading API
@ -375,7 +379,4 @@ typedef unsigned long ptr_size_type; // true for all of our current platforms
# endif # endif
#endif // __PLATFORM_H #endif // __PLATFORM_H

View File

@ -149,4 +149,3 @@ void cRefCountObj::Delete() const
{ {
delete this; delete this;
} }

View File

@ -67,7 +67,10 @@ public:
virtual void AddRef() const; virtual void AddRef() const;
virtual void Release() const; virtual void Release() const;
int GetRefCount() const { return mRefCount; } int GetRefCount() const
{
return mRefCount;
}
// sometimes it is useful to know an object's refrence // sometimes it is useful to know an object's refrence
protected: protected:
virtual ~cRefCountObj(); virtual ~cRefCountObj();
@ -82,6 +85,7 @@ private:
static int objectCounter; static int objectCounter;
static int referenceCounter; static int referenceCounter;
friend void TestRefCountObj(); friend void TestRefCountObj();
public: public:
static bool AllRefCountObjDestoryed() static bool AllRefCountObjDestoryed()
{ {
@ -91,4 +95,3 @@ public:
}; };
#endif #endif

View File

@ -51,7 +51,6 @@
#include "error.h" // for: eInternal #include "error.h" // for: eInternal
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Classes Declared in this module // Classes Declared in this module
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -75,19 +74,15 @@ template< class KEY, class CHR > class cMessages_;
// INVARIANTS: // INVARIANTS:
// //
// //
template< class KeyT, class RscT > template<class KeyT, class RscT> class cResources_
class cResources_
{ {
//--Type Definitions //--Type Definitions
private: private:
typedef std::map<KeyT, RscT> Table; // Storage Rep
typedef
std::map< KeyT, RscT > Table; // Storage Rep
public: public:
// Type definitions // Type definitions
typedef KeyT Key; // The resource id typedef KeyT Key; // The resource id
@ -101,11 +96,9 @@ class cResources_
typedef typename Table::value_type Pair; typedef typename Table::value_type Pair;
//--Interface. //--Interface.
public: public:
// Observers // Observers
ConstValueRef Get(ConstKeyRef) const; ConstValueRef Get(ConstKeyRef) const;
@ -120,16 +113,13 @@ class cResources_
//--Implementation. //--Implementation.
protected: protected:
static ConstValueRef DefaultValueRef(); // NOTE: static ConstValueRef DefaultValueRef(); // NOTE:
private: private:
Table m_table; Table m_table;
}; };
//============================================================================= //=============================================================================
// cMessages_<KEY,CHAR> -- Specialization of Resources_ for message strings // cMessages_<KEY,CHAR> -- Specialization of Resources_ for message strings
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -168,19 +158,14 @@ class cResources_
// must be a valid character type as defined by the STDCPP standard. // must be a valid character type as defined by the STDCPP standard.
// //
// //
template< class KeyT, class CharT > template<class KeyT, class CharT> class cMessages_ : public cResources_<KeyT, const CharT*>
class cMessages_ : public cResources_< KeyT, const CharT* >
{ {
//--Type definitions //--Type definitions
protected: protected:
typedef cResources_<KeyT, const CharT*> Resources;
typedef
cResources_<KeyT, const CharT* >
Resources;
public: public:
typedef std::basic_string<CharT> String; typedef std::basic_string<CharT> String;
typedef const KeyT& ConstKeyRef; typedef const KeyT& ConstKeyRef;
@ -188,7 +173,6 @@ class cMessages_ : public cResources_< KeyT, const CharT* >
//--Interface. //--Interface.
public: public:
String Get(ConstKeyRef) const; String Get(ConstKeyRef) const;
std::string GetAnsi(ConstKeyRef) const; std::string GetAnsi(ConstKeyRef) const;
#if SUPPORTS_WCHART #if SUPPORTS_WCHART
@ -197,7 +181,6 @@ class cMessages_ : public cResources_< KeyT, const CharT* >
}; };
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// IMPLEMENTATION: cResources_<KEY_TYPE, RESOURCE_TYPE> // IMPLEMENTATION: cResources_<KEY_TYPE, RESOURCE_TYPE>
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -208,8 +191,7 @@ class cMessages_ : public cResources_< KeyT, const CharT* >
#define Resource_Class cResources_<KeyT, RscT> #define Resource_Class cResources_<KeyT, RscT>
Resource_Template Resource_Template void Resource_Class::Put(const Pair* beg, const Pair* end)
void Resource_Class::Put( const Pair* beg, const Pair* end )
{ {
for (const Pair* at = beg; at != end; ++at) for (const Pair* at = beg; at != end; ++at)
{ {
@ -222,9 +204,7 @@ void Resource_Class::Put( const Pair* beg, const Pair* end )
} }
// By value allows the user to Resource_table.Put( 6, "Literal" ); // By value allows the user to Resource_table.Put( 6, "Literal" );
Resource_Template Resource_Template inline void Resource_Class::Put(ConstKeyRef id, Value sResource)
inline
void Resource_Class::Put( ConstKeyRef id, Value sResource )
{ {
if (m_table.insert(Pair(id, sResource)).second == false) if (m_table.insert(Pair(id, sResource)).second == false)
{ {
@ -233,9 +213,7 @@ void Resource_Class::Put( ConstKeyRef id, Value sResource )
} }
} }
Resource_Template Resource_Template typename Resource_Class::ConstValueRef Resource_Class::Get(ConstKeyRef id) const
typename Resource_Class::ConstValueRef
Resource_Class::Get( ConstKeyRef id ) const
{ {
typename Table::const_iterator at = m_table.find(id); typename Table::const_iterator at = m_table.find(id);
@ -253,9 +231,7 @@ Resource_Class::Get( ConstKeyRef id ) const
} }
} }
Resource_Template Resource_Template typename Resource_Class::ConstValueRef Resource_Class::DefaultValueRef()
typename Resource_Class::ConstValueRef
Resource_Class::DefaultValueRef()
{ {
static Value _default; static Value _default;
return _default; return _default;
@ -266,7 +242,6 @@ Resource_Class::DefaultValueRef()
#undef Resource_Class //Resources_<KeyT,RscT> #undef Resource_Class //Resources_<KeyT,RscT>
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// IMPLEMENTATION: cMessages_<KEY_TYPE, RESOURCE_TYPE> // IMPLEMENTATION: cMessages_<KEY_TYPE, RESOURCE_TYPE>
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -277,16 +252,10 @@ Resource_Class::DefaultValueRef()
#define Message_Class cMessages_<KeyT, CharT> #define Message_Class cMessages_<KeyT, CharT>
Message_Template Message_Template inline typename Message_Class::String Message_Class::Get(ConstKeyRef id) const
inline
typename Message_Class::String
Message_Class::Get( ConstKeyRef id ) const
{ {
typename Message_Class::Value msg = Resources::Get(id); typename Message_Class::Value msg = Resources::Get(id);
return return (msg == this->DefaultValueRef()) ? String() : String(msg);
( msg == this->DefaultValueRef() )
? String()
: String( msg );
} }
@ -299,25 +268,18 @@ namespace tss
/* WARNING:RAD -- Cannot use StringUtil or CodeConvert since /* WARNING:RAD -- Cannot use StringUtil or CodeConvert since
these use ErrorMessages and String Resources! */ these use ErrorMessages and String Resources! */
inline inline void ToNTMBS(std::string& nbs, const std::string& src)
void
ToNTMBS( std::string& nbs, const std::string& src )
{ {
nbs.assign(src); nbs.assign(src);
} }
#if SUPPORTS_WCHART #if SUPPORTS_WCHART
inline inline void ToNTMBS(std::string& nbs, const std::wstring& wcs)
void
ToNTMBS( std::string& nbs, const std::wstring& wcs )
{ {
nbs.resize(MB_CUR_MAX * wcs.size()); nbs.resize(MB_CUR_MAX * wcs.size());
size_t nWrote = size_t nWrote = ::wcstombs(const_cast<char*>(nbs.c_str()), wcs.c_str(), nbs.size() + 1);
::wcstombs(
const_cast< char * >( nbs.c_str() ),
wcs.c_str(), nbs.size() + 1 );
if (nWrote == (size_t)-1) if (nWrote == (size_t)-1)
{ {
@ -328,23 +290,16 @@ namespace tss
nbs.resize(nWrote); nbs.resize(nWrote);
} }
inline inline void ToNTWCS(std::wstring& dst, const std::wstring& src)
void
ToNTWCS( std::wstring& dst, const std::wstring& src )
{ {
dst.assign(src); dst.assign(src);
} }
inline inline void ToNTWCS(std::wstring& wcs, const std::string& nbs)
void
ToNTWCS( std::wstring& wcs, const std::string& nbs )
{ {
wcs.resize(nbs.size()); wcs.resize(nbs.size());
size_t nWrote = size_t nWrote = ::mbstowcs(const_cast<wchar_t*>(wcs.c_str()), nbs.c_str(), wcs.size() + 1);
::mbstowcs(
const_cast< wchar_t * >( wcs.c_str() ),
nbs.c_str(), wcs.size() + 1 );
if (nWrote == (size_t)-1) if (nWrote == (size_t)-1)
{ {
@ -355,14 +310,11 @@ namespace tss
wcs.resize(nWrote); wcs.resize(nWrote);
} }
#endif //SUPPORTS_WCHART #endif //SUPPORTS_WCHART
}//rsc:: } // namespace rsc
}//tss:: } // namespace tss
Message_Template Message_Template inline std::string Message_Class::GetAnsi(ConstKeyRef id) const
inline
std::string
Message_Class::GetAnsi( ConstKeyRef id ) const
{ {
typename Message_Class::Value msg = Resources::Get(id); typename Message_Class::Value msg = Resources::Get(id);
@ -381,10 +333,7 @@ Message_Class::GetAnsi( ConstKeyRef id ) const
#if SUPPORTS_WCHART #if SUPPORTS_WCHART
Message_Template Message_Template inline std::wstring Message_Class::GetWide(ConstKeyRef id) const
inline
std::wstring
Message_Class::GetWide( ConstKeyRef id ) const
{ {
Value msg = Resources::Get(id); Value msg = Resources::Get(id);
@ -409,7 +358,6 @@ Message_Class::GetWide( ConstKeyRef id ) const
#endif //__RESOURCES_H #endif //__RESOURCES_H
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// OLD CODE * OLD CODE * OLD CODE * OLD CODE * OLD CODE * OLD CODE * OLD CODE // OLD CODE * OLD CODE * OLD CODE * OLD CODE * OLD CODE * OLD CODE * OLD CODE
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -431,18 +379,12 @@ Message_Class::GetWide( ConstKeyRef id ) const
# define ENUM_TYPE const int # define ENUM_TYPE const int
#endif #endif
template<> template<> class cMessages_<ENUM_TYPE, char> : public cResources_<ENUM_TYPE, const char*>
class cMessages_<ENUM_TYPE, char> :
public cResources_< ENUM_TYPE, const char* >
{ {
protected: protected:
typedef cResources_<ENUM_TYPE, const char*> Resources;
typedef
cResources_< ENUM_TYPE, const char* >
Resources;
public: public:
typedef std::string String; typedef std::string String;
typedef int ConstKeyRef; // Better than <const int&> typedef int ConstKeyRef; // Better than <const int&>
@ -450,9 +392,7 @@ class cMessages_<ENUM_TYPE, char> :
String Get(ConstKeyRef id) const String Get(ConstKeyRef id) const
{ {
Value msg = Resources::Get(id); Value msg = Resources::Get(id);
return ( msg != DefaultValueRef() ) return (msg != DefaultValueRef()) ? String(msg) : String();
? String( msg )
: String();
} }
String GetAnsi(ConstKeyRef id) const String GetAnsi(ConstKeyRef id) const
@ -471,8 +411,7 @@ class cMessages_<ENUM_TYPE, char> :
} }
else else
{ {
String::size_type String::size_type N = String::traits_type::length(msg);
N = String::traits_type::length( msg );
std::wstring dst(N, 0x00); std::wstring dst(N, 0x00);
std::ctype<wchar_t>().widen(msg, msg + N, dst.begin()); std::ctype<wchar_t>().widen(msg, msg + N, dst.begin());
@ -485,18 +424,12 @@ class cMessages_<ENUM_TYPE, char> :
#if SUPPORTS_WCHART #if SUPPORTS_WCHART
template<> template<> class cMessages_<const int, wchar_t> : public cResources_<const int, const wchar_t*>
class cMessages_<const int, wchar_t> :
public cResources_< const int, const wchar_t* >
{ {
protected: protected:
typedef cResources_<const int, const wchar_t*> Resources;
typedef
cResources_<const int, const wchar_t* >
Resources;
public: public:
typedef std::wstring String; typedef std::wstring String;
typedef int ConstKeyRef; // Better than <const int&> typedef int ConstKeyRef; // Better than <const int&>
@ -520,8 +453,7 @@ class cMessages_<const int, wchar_t> :
} }
else else
{ {
String::size_type String::size_type N = String::traits_type::length(msg);
N = String::traits_type::length( msg );
std::string dst(N, 0x00); std::string dst(N, 0x00);
std::ctype<CharT>().narrow(msg, msg + N, '?', dst.begin()); std::ctype<CharT>().narrow(msg, msg + N, '?', dst.begin());
@ -539,5 +471,3 @@ class cMessages_<const int, wchar_t> :
# endif //SUPPORTS_WCHART # endif //SUPPORTS_WCHART
#endif //RAD_OLDCODE #endif //RAD_OLDCODE

View File

@ -36,8 +36,13 @@
#include "serializable.h" #include "serializable.h"
#if IS_SUNPRO #if IS_SUNPRO
iTypedSerializable::~iTypedSerializable() {} iTypedSerializable::~iTypedSerializable()
iSerializable::~iSerializable() {} {
iTyped::~iTyped() {} }
iSerializable::~iSerializable()
{
}
iTyped::~iTyped()
{
}
#endif #endif

View File

@ -82,7 +82,9 @@ public:
virtual void Write(iSerializer* pSerializer) const = 0; // throw (eSerializer, eArchive) virtual void Write(iSerializer* pSerializer) const = 0; // throw (eSerializer, eArchive)
// objects implement these methods to read and write themselves to a serializer. // objects implement these methods to read and write themselves to a serializer.
virtual ~iSerializable() {} virtual ~iSerializable()
{
}
}; };
class iTypedSerializable : public iTyped, public iSerializable class iTypedSerializable : public iTyped, public iSerializable
@ -95,11 +97,22 @@ public:
// Return the current version of that this serializable object writes. // Return the current version of that this serializable object writes.
// As a convention version number should be (major_version << 16) | minor_version. // As a convention version number should be (major_version << 16) | minor_version.
static int32 MkVersion(int16 major, int16 minor) { return (int32)(((uint32)major << 16) | (uint32)minor); } static int32 MkVersion(int16 major, int16 minor)
static int16 MajorVersion(int32 version) { return (int16)((uint32)version >> 16); } {
static int16 MinorVersion(int32 version) { return (int16)version; } return (int32)(((uint32)major << 16) | (uint32)minor);
}
static int16 MajorVersion(int32 version)
{
return (int16)((uint32)version >> 16);
}
static int16 MinorVersion(int32 version)
{
return (int16)version;
}
virtual ~iTypedSerializable() {} virtual ~iTypedSerializable()
{
}
}; };
////////////////////////////// //////////////////////////////
@ -122,4 +135,3 @@ public: \
} }
#endif // __SERIALIZABLE_H #endif // __SERIALIZABLE_H

View File

@ -48,7 +48,8 @@ class iSerializable;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
TSS_BEGIN_EXCEPTION_NO_CTOR(eSerializer, eError) TSS_BEGIN_EXCEPTION_NO_CTOR(eSerializer, eError)
// TODO: What else to add to this enumeration? Locked File? Temp file? // TODO: What else to add to this enumeration? Locked File? Temp file?
enum DataSourceType { enum DataSourceType
{
TY_UNDEFINED = 0, TY_UNDEFINED = 0,
TY_FILE, TY_FILE,
TY_TEMPFILE, TY_TEMPFILE,
@ -58,10 +59,9 @@ TSS_BEGIN_EXCEPTION_NO_CTOR( eSerializer, eError )
}; };
eSerializer(const TSTRING& msg, const TSTRING& dataSource = _T(""), DataSourceType paramType = TY_UNDEFINED) eSerializer(const TSTRING& msg, const TSTRING& dataSource = _T(""), DataSourceType paramType = TY_UNDEFINED)
: eError( msg ), : eError(msg), mDataSource(dataSource), mSourceType(paramType)
mDataSource( dataSource ), {
mSourceType( paramType ) }
{}
virtual TSTRING GetMsg() const; virtual TSTRING GetMsg() const;
@ -78,8 +78,7 @@ TSS_END_EXCEPTION();
#define TSS_SERIALIZER_EXCEPTION(except) \ #define TSS_SERIALIZER_EXCEPTION(except) \
TSS_BEGIN_EXCEPTION_NO_CTOR(except, eSerializer) \ TSS_BEGIN_EXCEPTION_NO_CTOR(except, eSerializer) \
except(const TSTRING& msg, const TSTRING& dataSource = _T(""), DataSourceType paramType = TY_UNDEFINED) \ except(const TSTRING& msg, const TSTRING& dataSource = _T(""), DataSourceType paramType = TY_UNDEFINED) \
: eSerializer( msg, dataSource, paramType ) \ : eSerializer(msg, dataSource, paramType){}; \
{}; \
TSS_END_EXCEPTION() TSS_END_EXCEPTION()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -139,7 +138,10 @@ public:
virtual void WriteString(const TSTRING& s) = 0; virtual void WriteString(const TSTRING& s) = 0;
virtual void WriteBlob(const void* pBlob, int count) = 0; virtual void WriteBlob(const void* pBlob, int count) = 0;
virtual TSTRING GetFileName() const { return _T(""); } virtual TSTRING GetFileName() const
{
return _T("");
}
// derived classes can implement this to return the file name associated with the serializer. // derived classes can implement this to return the file name associated with the serializer.
// it is only used in error reporting. // it is only used in error reporting.
@ -156,10 +158,10 @@ public:
E_NUMITEMS E_NUMITEMS
}; };
virtual ~iSerializer() {} virtual ~iSerializer()
{
}
}; };
#endif #endif

View File

@ -79,11 +79,8 @@ static uint32 util_GetCRC( const cType& type )
//############################################################################# //#############################################################################
// class cSerializerImpl // class cSerializerImpl
//############################################################################# //#############################################################################
cSerializerImpl::cSerializerImpl(cArchive& archive, Mode action, const TSTRING& fileName) : cSerializerImpl::cSerializerImpl(cArchive& archive, Mode action, const TSTRING& fileName)
mpArchive(&archive), : mpArchive(&archive), mMode(action), mbInit(false), mFileName(fileName)
mMode(action),
mbInit(false),
mFileName( fileName )
{ {
} }
@ -235,7 +232,6 @@ void cSerializerImpl::WriteObjectDynCreate(const iTypedSerializable* pObj)
mpArchive->WriteInt32(0); mpArchive->WriteInt32(0);
// ... then write the object. // ... then write the object.
pObj->Write(this); pObj->Write(this);
} }
} }
@ -320,7 +316,10 @@ iTypedSerializable* cSerializerImpl::ReadObjectDynCreate()
else else
{ {
// already serialized; just return this object. // already serialized; just return this object.
d.TraceDetail("Adding refrence to previously serialized object [%d] %s(%p)\n", objIdx, pObj->GetType().AsString(), pObj); d.TraceDetail("Adding refrence to previously serialized object [%d] %s(%p)\n",
objIdx,
pObj->GetType().AsString(),
pObj);
pObj->AddRef(); pObj->AddRef();
} }
@ -495,4 +494,3 @@ TSTRING cSerializerImpl::GetFileName() const
{ {
return mFileName; return mFileName;
} }

View File

@ -60,7 +60,11 @@ class cArchive;
class cSerializerImpl : public iSerializer class cSerializerImpl : public iSerializer
{ {
public: public:
enum Mode { S_READ, S_WRITE }; enum Mode
{
S_READ,
S_WRITE
};
cSerializerImpl(cArchive& archive, Mode action, const TSTRING& fileName = _T("")); cSerializerImpl(cArchive& archive, Mode action, const TSTRING& fileName = _T(""));
// fileName is only used for error reporting purposes // fileName is only used for error reporting purposes
virtual ~cSerializerImpl(); virtual ~cSerializerImpl();
@ -128,7 +132,4 @@ private:
}; };
#endif #endif

View File

@ -35,11 +35,14 @@
#include "archive.h" #include "archive.h"
#include "serializer.h" #include "serializer.h"
namespace { namespace
template<class FROM, class TO>
int64 CopyImpl(TO* pTo, FROM* pFrom, int64 amt)
{ {
enum { BUF_SIZE = 8192 }; template<class FROM, class TO> int64 CopyImpl(TO* pTo, FROM* pFrom, int64 amt)
{
enum
{
BUF_SIZE = 8192
};
int8 buf[BUF_SIZE]; int8 buf[BUF_SIZE];
int64 amtLeft = amt; int64 amtLeft = amt;
@ -58,7 +61,7 @@ int64 CopyImpl(TO* pTo, FROM* pFrom, int64 amt)
// return the amount copied ... // return the amount copied ...
return (amt - amtLeft); return (amt - amtLeft);
} }
} } // namespace
int64 cSerializerUtil::Copy(iSerializer* pDest, cArchive* pSrc, int64 amt) int64 cSerializerUtil::Copy(iSerializer* pDest, cArchive* pSrc, int64 amt)
@ -70,4 +73,3 @@ int64 cSerializerUtil::Copy( cArchive* pDest, iSerializer* pSrc, int64 amt )
{ {
return CopyImpl(pDest, pSrc, amt); return CopyImpl(pDest, pSrc, amt);
} }

View File

@ -51,4 +51,3 @@ public:
}; };
#endif #endif

View File

@ -69,4 +69,3 @@ void cSerializableWString::Write(iSerializer* pSerializer) const
pSerializer->WriteInt32(len); pSerializer->WriteInt32(len);
pSerializer->WriteBlob(mString.data(), len); pSerializer->WriteBlob(mString.data(), len);
} }

View File

@ -81,4 +81,3 @@ public:
typedef cSerializableNString cSerializableTSTRING; typedef cSerializableNString cSerializableTSTRING;
#endif #endif

View File

@ -42,4 +42,3 @@
iSerRefCountObj::~iSerRefCountObj() iSerRefCountObj::~iSerRefCountObj()
{ {
} }

View File

@ -59,7 +59,6 @@ public:
protected: protected:
virtual ~iSerRefCountObj(); virtual ~iSerRefCountObj();
}; };
////////////////////////////// //////////////////////////////
@ -83,4 +82,3 @@ public: \
#endif #endif

View File

@ -154,4 +154,3 @@ cSerRefCountTableMap::~cSerRefCountTableMap()
} }
} }
*/ */

View File

@ -89,4 +89,3 @@ public:
}; };
*/ */
#endif #endif

View File

@ -36,5 +36,3 @@
// //
#include "stdcore.h" #include "stdcore.h"

View File

@ -114,7 +114,6 @@
//--Include Platform Specific Declarations //--Include Platform Specific Declarations
//--Include Common Core Declarations //--Include Common Core Declarations
#include "./tchar.h" #include "./tchar.h"
@ -124,4 +123,3 @@
#endif //__STDCORE_H #endif //__STDCORE_H

View File

@ -75,7 +75,6 @@
#include "hashtable.h" #include "hashtable.h"
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// String Cache // String Cache
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -103,19 +102,14 @@ public:
namespace /* Module Local */ namespace /* Module Local */
{ {
typedef typedef cHashTable<wc16_string, TSTRING, tss_hash_key_compare, tss_hash_key_convert> hashtable_t;
cHashTable< wc16_string,
TSTRING,
tss_hash_key_compare,
tss_hash_key_convert >
hashtable_t;
hashtable_t& tss_GetHashTable() hashtable_t& tss_GetHashTable()
{ {
static hashtable_t s_table; static hashtable_t s_table;
return s_table; return s_table;
} }
}//Anon. } // namespace
inline void tss_insert_in_hash(const wc16_string& lhs, const TSTRING& rhs) inline void tss_insert_in_hash(const wc16_string& lhs, const TSTRING& rhs)
@ -134,8 +128,7 @@ inline bool tss_find_in_hash( const wc16_string& lhs, TSTRING& rhs )
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*static*/ /*static*/
std::string::const_iterator std::string::const_iterator cStringUtil::Convert(std::string& nbs, const wc16_string& dbs)
cStringUtil::Convert( std::string& nbs, const wc16_string& dbs )
{ {
#if IS_AROS #if IS_AROS
nbs.resize(dbs.length()); nbs.resize(dbs.length());
@ -169,10 +162,8 @@ cStringUtil::Convert( std::string& nbs, const wc16_string& dbs )
nbs.resize(dbs.size() * MB_CUR_MAX); nbs.resize(dbs.size() * MB_CUR_MAX);
int nWrote = int nWrote = iCodeConverter::GetInstance()->Convert(
iCodeConverter::GetInstance()->Convert( (char*)nbs.c_str(), nbs.size(), dbs.c_str(), dbs.size()); // c_str() because must be null terminated
(char*)nbs.c_str(), nbs.size(),
dbs.c_str(), dbs.size() ); // c_str() because must be null terminated
d.TraceDetail(_T("iCodeConverter returned %d\n"), nWrote); d.TraceDetail(_T("iCodeConverter returned %d\n"), nWrote);
@ -189,8 +180,7 @@ cStringUtil::Convert( std::string& nbs, const wc16_string& dbs )
} }
/*static*/ /*static*/
wc16_string::const_iterator wc16_string::const_iterator cStringUtil::Convert(wc16_string& dbs, const std::string& nbs)
cStringUtil::Convert( wc16_string& dbs, const std::string& nbs )
{ {
#if IS_AROS #if IS_AROS
dbs.resize(nbs.length()); dbs.resize(nbs.length());
@ -206,10 +196,8 @@ cStringUtil::Convert( wc16_string& dbs, const std::string& nbs )
// d.TraceDebug( "converting <%s>\n", nbs.c_str() ); // d.TraceDebug( "converting <%s>\n", nbs.c_str() );
int nWrote = int nWrote = iCodeConverter::GetInstance()->Convert(
iCodeConverter::GetInstance()->Convert( (WCHAR16*)dbs.c_str(), dbs.length(), nbs.c_str(), nbs.size()); // c_str() because must be null terminated
(WCHAR16*)dbs.c_str(), dbs.length(),
nbs.c_str(), nbs.size() ); // c_str() because must be null terminated
d.TraceDetail(_T("iCodeConverter returned %d\n"), nWrote); d.TraceDetail(_T("iCodeConverter returned %d\n"), nWrote);
@ -237,8 +225,7 @@ cStringUtil::Convert( wc16_string& dbs, const std::string& nbs )
#if SUPPORTS_WCHART && WCHAR_REP_IS_UCS2 #if SUPPORTS_WCHART && WCHAR_REP_IS_UCS2
/*static*/ /*static*/
std::wstring::const_iterator std::wstring::const_iterator cStringUtil::Convert(std::wstring& wcs, const wc16_string& dbs)
cStringUtil::Convert( std::wstring& wcs, const wc16_string& dbs )
{ {
if (dbs.size() != 0) if (dbs.size() != 0)
{ {
@ -257,8 +244,7 @@ cStringUtil::Convert( std::wstring& wcs, const wc16_string& dbs )
} }
/*static*/ /*static*/
wc16_string::const_iterator wc16_string::const_iterator cStringUtil::Convert(wc16_string& dbs, const std::wstring& wcs)
cStringUtil::Convert( wc16_string& dbs, const std::wstring& wcs )
{ {
if (wcs.size() != 0) if (wcs.size() != 0)
{ {
@ -272,8 +258,7 @@ cStringUtil::Convert( wc16_string& dbs, const std::wstring& wcs )
} }
/*static*/ /*static*/
std::wstring::const_iterator std::wstring::const_iterator cStringUtil::Convert(std::wstring& wcs, const std::string& nbs)
cStringUtil::Convert( std::wstring& wcs, const std::string& nbs )
{ {
if (nbs.size() != 0) if (nbs.size() != 0)
{ {
@ -292,8 +277,7 @@ cStringUtil::Convert( std::wstring& wcs, const std::string& nbs )
} }
/*static*/ /*static*/
std::string::const_iterator std::string::const_iterator cStringUtil::Convert(std::string& nbs, const std::wstring& wcs)
cStringUtil::Convert( std::string& nbs, const std::wstring& wcs )
{ {
if (wcs.size() != 0) if (wcs.size() != 0)
{ {
@ -324,8 +308,7 @@ cStringUtil::Convert( std::string& nbs, const std::wstring& wcs )
// TstrToStr // TstrToStr
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
std::string std::string cStringUtil::TstrToStr(const TSTRING& tstr)
cStringUtil::TstrToStr( const TSTRING& tstr )
{ {
std::string s; std::string s;
cStringUtil::Convert(s, tstr); cStringUtil::Convert(s, tstr);

View File

@ -59,9 +59,7 @@ namespace cStringUtil
/// Handle Like-Types (xstring to xstring) /// Handle Like-Types (xstring to xstring)
inline inline const char* Convert(std::string& lhs, const std::string& rhs)
const char *
Convert( std::string& lhs, const std::string& rhs )
{ {
lhs = rhs; lhs = rhs;
return lhs.c_str(); return lhs.c_str();
@ -69,33 +67,25 @@ namespace cStringUtil
/// Specialize Everything Else /// Specialize Everything Else
std::string::const_iterator std::string::const_iterator Convert(std::string&, const wc16_string&);
Convert( std::string&, const wc16_string& );
wc16_string::const_iterator wc16_string::const_iterator Convert(wc16_string&, const std::string&);
Convert( wc16_string&, const std::string& );
#if SUPPORTS_WCHART && WCHAR_REP_IS_UCS2 #if SUPPORTS_WCHART && WCHAR_REP_IS_UCS2
inline inline std::wstring::const_iterator Convert(std::wstring& lhs, const std::wstring& rhs)
std::wstring::const_iterator
Convert( std::wstring& lhs, const std::wstring& rhs )
{ {
lhs = rhs; lhs = rhs;
return lhs.c_str(); return lhs.c_str();
} }
std::wstring::const_iterator std::wstring::const_iterator Convert(std::wstring&, const wc16_string&);
Convert( std::wstring&, const wc16_string& );
std::wstring::const_iterator std::wstring::const_iterator Convert(std::wstring&, const std::string&);
Convert( std::wstring&, const std::string& );
std::string::const_iterator std::string::const_iterator Convert(std::string&, const std::wstring&);
Convert( std::string&, const std::wstring& );
wc16_string::const_iterator wc16_string::const_iterator Convert(wc16_string&, const std::wstring&);
Convert( wc16_string&, const std::wstring& );
#endif //SUPPORTS_WCHART #endif //SUPPORTS_WCHART
@ -115,16 +105,15 @@ namespace cStringUtil
// convert a TSTRING to a wc16_string // convert a TSTRING to a wc16_string
template <class IterT> template<class IterT> void splitstring(IterT& iter, const TSTRING& str, const TSTRING& delims)
void splitstring(IterT& iter, {
const TSTRING& str,
const TSTRING& delims) {
TSTRING::size_type where; TSTRING::size_type where;
TSTRING tmpStr; TSTRING tmpStr;
TSTRING workingString = str; TSTRING workingString = str;
while (workingString.length() > 0) { while (workingString.length() > 0)
{
where = workingString.find_first_of(delims, 0); where = workingString.find_first_of(delims, 0);
@ -138,14 +127,11 @@ namespace cStringUtil
workingString.erase(0, where + 1); workingString.erase(0, where + 1);
iter.push_back(tmpStr); iter.push_back(tmpStr);
} }
} }
} // namespace cStringUtil
}//cStringUtil::
/* /*
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -203,4 +189,3 @@ namespace std
*/ */
#endif //__STRINGUTIL_H #endif //__STRINGUTIL_H

View File

@ -57,7 +57,9 @@ class cTaskTimer
public: public:
cTaskTimer(const TSTRING& name) : mName(name), mTotalTime(0), mStartTime(0), mNumStarts(0) {} cTaskTimer(const TSTRING& name) : mName(name), mTotalTime(0), mStartTime(0), mNumStarts(0)
{
}
inline ~cTaskTimer() inline ~cTaskTimer()
{ {
@ -86,20 +88,33 @@ public:
mStartTime = 0; mStartTime = 0;
} }
bool IsRunning() { return (mStartTime != 0); } bool IsRunning()
void Reset() { mNumStarts = mStartTime = mTotalTime = 0; } {
uint32 GetTotalTime() const { return mTotalTime; } return (mStartTime != 0);
uint32 GetNumTimesStarted() const { return mNumStarts; } }
const std::string& GetName() const { return mName; } void Reset()
{
mNumStarts = mStartTime = mTotalTime = 0;
}
uint32 GetTotalTime() const
{
return mTotalTime;
}
uint32 GetNumTimesStarted() const
{
return mNumStarts;
}
const std::string& GetName() const
{
return mName;
}
private: private:
TSTRING mName; TSTRING mName;
uint32 mTotalTime; uint32 mTotalTime;
uint32 mStartTime; uint32 mStartTime;
uint32 mNumStarts; uint32 mNumStarts;
}; };
#endif #endif

View File

@ -126,4 +126,3 @@ typedef std::ifstream TIFSTREAM;
# endif # endif
#endif // __TCHAR_H #endif // __TCHAR_H

View File

@ -83,5 +83,3 @@ int64 cTimeUtil::GetTime()
{ {
return time(NULL); return time(NULL);
} }

View File

@ -73,4 +73,3 @@ public:
}; };
#endif //__TIMECONVERT_H #endif //__TIMECONVERT_H

View File

@ -83,8 +83,7 @@ void util_SignalHandler( int sig )
void tw_psignal(int sig, const TCHAR* str) void tw_psignal(int sig, const TCHAR* str)
{ {
const TCHAR *siglist[NSIG] = { const TCHAR* siglist[NSIG] = {_T("Unknown Signal"),
_T("Unknown Signal"),
_T("Hangup"), _T("Hangup"),
_T("Interrupt"), _T("Interrupt"),
_T("Quit"), _T("Quit"),
@ -114,10 +113,7 @@ void tw_psignal(int sig, const TCHAR *str)
_T("Stopped (tty input)"), _T("Stopped (tty input)"),
_T("Stopped (tty output)"), _T("Stopped (tty output)"),
_T("Urgent Socket Condition"), _T("Urgent Socket Condition"),
_T("File Lock Lost") _T("File Lock Lost")};
};
_ftprintf(stderr, _T("%s %s\n"), str, sig < NSIG ? siglist[sig] : siglist[0]); _ftprintf(stderr, _T("%s %s\n"), str, sig < NSIG ? siglist[sig] : siglist[0]);
} }

View File

@ -45,7 +45,8 @@
#include <bits/signum.h> #include <bits/signum.h>
#endif #endif
extern "C" { extern "C"
{
typedef void (*tw_sighandler_t)(int); typedef void (*tw_sighandler_t)(int);
} }
@ -64,4 +65,3 @@ tw_sighandler_t tw_HandleSignal( int sig );
#endif //__TW_SIGNAL_H #endif //__TW_SIGNAL_H

View File

@ -96,4 +96,3 @@ bool cInterpretInt::InterpretInt( const TSTRING& str, int* pi )
return fFormatOK; return fFormatOK;
} }

View File

@ -86,11 +86,19 @@ private:
// //
// private functionality // private functionality
// //
virtual int GetMax() { return LIMIT_MAX; }; virtual int GetMax()
virtual int GetMin() { return LIMIT_MIN; }; {
return LIMIT_MAX;
};
virtual int GetMin()
{
return LIMIT_MIN;
};
public: public:
virtual ~cInterpretInt() {} virtual ~cInterpretInt()
{
}
}; };
/////////////////////////////////////////////// ///////////////////////////////////////////////
@ -105,11 +113,19 @@ private:
LIMIT_MAX = 1000000 LIMIT_MAX = 1000000
}; };
virtual int GetMax() { return LIMIT_MAX; }; virtual int GetMax()
virtual int GetMin() { return LIMIT_MIN; }; {
return LIMIT_MAX;
};
virtual int GetMin()
{
return LIMIT_MIN;
};
public: public:
virtual ~cSeverityLimits() {} virtual ~cSeverityLimits()
{
}
}; };
/////////////////////////////////////////////// ///////////////////////////////////////////////
@ -124,12 +140,19 @@ private:
LIMIT_MAX = 1000000 LIMIT_MAX = 1000000
}; };
virtual int GetMax() { return LIMIT_MAX; }; virtual int GetMax()
virtual int GetMin() { return LIMIT_MIN; }; {
return LIMIT_MAX;
};
virtual int GetMin()
{
return LIMIT_MIN;
};
public: public:
virtual ~cRecurseDepthLimits() {} virtual ~cRecurseDepthLimits()
{
}
}; };
#endif //__TWLIMITS_H #endif //__TWLIMITS_H

View File

@ -101,7 +101,6 @@ void cTWLocale::InitGlobalLocale()
std::locale::global(l); std::locale::global(l);
d.TraceDebug("locale changed to the system default std::locale (C++): <%s>\n", l.name().c_str()); d.TraceDebug("locale changed to the system default std::locale (C++): <%s>\n", l.name().c_str());
#endif #endif
} }
/* /*
@ -128,11 +127,9 @@ TSTRING cTWLocale::FormatNumberAsHex( int32 i )
} }
*/ */
template< class numT, class CharT > template<class numT, class CharT> class cFormatNumberUtil
class cFormatNumberUtil
{ {
public: public:
// TODO:BAM -- these functions should really maybe take a stringstream that has been // TODO:BAM -- these functions should really maybe take a stringstream that has been
// already set up for formatting (basefield, locale, etc.) that way we can merge // already set up for formatting (basefield, locale, etc.) that way we can merge
//. the FormatNumberAsHex function as well //. the FormatNumberAsHex function as well
@ -143,9 +140,7 @@ public:
// cFormatNumberUtil::FormatNumber( const std::basic_string< CharT >& s, bool fCStyleFormatting = false ) // cFormatNumberUtil::FormatNumber( const std::basic_string< CharT >& s, bool fCStyleFormatting = false )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// EFFECTS: Does all actual formatting for FormatNumber methods // EFFECTS: Does all actual formatting for FormatNumber methods
static static numT Format(const std::basic_string<CharT>& s, bool fCStyleFormatting)
numT
Format( const std::basic_string< CharT >& s, bool fCStyleFormatting )
{ {
static const std::num_get<CharT>* png; static const std::num_get<CharT>* png;
std::basic_istringstream<CharT> ss(s); std::basic_istringstream<CharT> ss(s);
@ -155,12 +150,7 @@ public:
if (fCStyleFormatting) if (fCStyleFormatting)
ss.imbue(std::locale::classic()); ss.imbue(std::locale::classic());
tss::GetFacet( ss.getloc(), png ).get( tss::GetFacet(ss.getloc(), png).get(ss, std::istreambuf_iterator<CharT>(), ss, state, n);
ss,
std::istreambuf_iterator< CharT >(),
ss,
state,
n );
if ((state & std::ios_base::failbit) != 0) if ((state & std::ios_base::failbit) != 0)
@ -175,9 +165,7 @@ public:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// EFFECTS: Does all actual formatting for FormatNumber methods // EFFECTS: Does all actual formatting for FormatNumber methods
// //
static static std::basic_string<CharT>& Format(numT n, std::basic_string<CharT>& sBuf, bool fCStyleFormatting = false)
std::basic_string< CharT >&
Format( numT n, std::basic_string< CharT >& sBuf, bool fCStyleFormatting = false )
{ {
static const std::num_put<CharT>* pnp; static const std::num_put<CharT>* pnp;
std::basic_ostringstream<CharT> ss; std::basic_ostringstream<CharT> ss;
@ -315,7 +303,8 @@ TSTRING& util_FormatTimeC( struct tm* ptm, TSTRING& strBuf )
TCHAR achTimeBuf[256]; TCHAR achTimeBuf[256];
/* XXX: This should check (#ifdef) for strftime - PH */ /* XXX: This should check (#ifdef) for strftime - PH */
size_t nbWritten = _tcsftime( achTimeBuf, countof( achTimeBuf ), size_t nbWritten = _tcsftime(achTimeBuf,
countof(achTimeBuf),
#if IS_MSVC // MSVC uses proprietary '#' #if IS_MSVC // MSVC uses proprietary '#'
_T("%#c"), _T("%#c"),
@ -331,4 +320,3 @@ TSTRING& util_FormatTimeC( struct tm* ptm, TSTRING& strBuf )
return strBuf; return strBuf;
} }

View File

@ -111,11 +111,10 @@ namespace tss
#if USE_STD_CPP_LOCALE_WORKAROUND #if USE_STD_CPP_LOCALE_WORKAROUND
return std::use_facet(l, pf); return std::use_facet(l, pf);
#else #else
return std::use_facet< FacetT >( l ); (void)pf; // This is C++ standard return std::use_facet<FacetT>(l);
(void)pf; // This is C++ standard
#endif #endif
} }
} } // namespace tss
#endif //__TWLOCALE_H #endif //__TWLOCALE_H

View File

@ -42,4 +42,3 @@ enum Languages
}; };
#endif #endif

View File

@ -49,6 +49,7 @@ public:
const TCHAR* AsString() const; const TCHAR* AsString() const;
bool operator==(const cType& rhs) const; bool operator==(const cType& rhs) const;
bool operator!=(const cType& rhs) const; bool operator!=(const cType& rhs) const;
private: private:
TSTRING mString; TSTRING mString;
}; };
@ -62,7 +63,9 @@ public:
// (b) returning that object in their implementation of GetType() // (b) returning that object in their implementation of GetType()
// You can use the macros below to simplify the process // You can use the macros below to simplify the process
virtual ~iTyped() {} virtual ~iTyped()
{
}
}; };
////////////////////////////////////////////// //////////////////////////////////////////////
@ -116,8 +119,7 @@ const cType& CLASS::GetType() const\
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// inline implementation // inline implementation
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
inline cType::cType(const TCHAR* name) : inline cType::cType(const TCHAR* name) : mString(name)
mString(name)
{ {
ASSERT(!mString.empty()); ASSERT(!mString.empty());
} }
@ -140,4 +142,3 @@ inline bool cType::operator!=(const cType& rhs) const
#endif //__TYPED_H #endif //__TYPED_H

View File

@ -41,7 +41,6 @@
#endif #endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// standard TSS types // standard TSS types
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -157,27 +156,19 @@ inline int16 SWAPBYTES16(int16 i)
{ {
return ((uint16)i >> 8) | ((uint16)i << 8); return ((uint16)i >> 8) | ((uint16)i << 8);
} }
inline int32 SWAPBYTES32(int32 i) inline int32 SWAPBYTES32(int32 i)
{ {
return ((uint32)i >> 24) | return ((uint32)i >> 24) | (((uint32)i & 0x00ff0000) >> 8) | (((uint32)i & 0x0000ff00) << 8) | ((uint32)i << 24);
(((uint32)i & 0x00ff0000) >> 8) |
(((uint32)i & 0x0000ff00) << 8) |
((uint32)i << 24);
} }
inline int64 SWAPBYTES64(int64 i) inline int64 SWAPBYTES64(int64 i)
{ {
return ((uint64)i >> 56) | return ((uint64)i >> 56) | (((uint64)i & 0x00ff000000000000ULL) >> 40) |
(((uint64)i & 0x00ff000000000000ULL) >> 40) | (((uint64)i & 0x0000ff0000000000ULL) >> 24) | (((uint64)i & 0x000000ff00000000ULL) >> 8) |
(((uint64)i & 0x0000ff0000000000ULL) >> 24) | (((uint64)i & 0x00000000ff000000ULL) << 8) | (((uint64)i & 0x0000000000ff0000ULL) << 24) |
(((uint64)i & 0x000000ff00000000ULL) >> 8) | (((uint64)i & 0x000000000000ff00ULL) << 40) | ((uint64)i << 56);
(((uint64)i & 0x00000000ff000000ULL) << 8) |
(((uint64)i & 0x0000000000ff0000ULL) << 24) |
(((uint64)i & 0x000000000000ff00ULL) << 40) |
((uint64)i << 56);
} }
@ -210,7 +201,4 @@ inline int64 SWAPBYTES64(int64 i)
# endif # endif
#endif // __TYPES_H #endif // __TYPES_H

View File

@ -38,8 +38,7 @@
#include <errno.h> #include <errno.h>
// TODO: JEB: make this look like eFileError // TODO: JEB: make this look like eFileError
eUnix::eUnix( const TCHAR* szFunctionName, const TCHAR* szObjectName, bool fCallGetLastError) eUnix::eUnix(const TCHAR* szFunctionName, const TCHAR* szObjectName, bool fCallGetLastError) : eError(_T(""))
: eError( _T(""))
{ {
ASSERT(szFunctionName || szObjectName || fCallGetLastError); ASSERT(szFunctionName || szObjectName || fCallGetLastError);
// //

View File

@ -53,6 +53,4 @@ TSS_BEGIN_EXCEPTION( eUnix, eError )
TSS_END_EXCEPTION() TSS_END_EXCEPTION()
#endif //__unixexcept_H #endif //__unixexcept_H

View File

@ -108,7 +108,6 @@
#endif //HAVE_SYS_STATFS_H #endif //HAVE_SYS_STATFS_H
//========================================================================= //=========================================================================
// DEFINES AND MACROS // DEFINES AND MACROS
//========================================================================= //=========================================================================
@ -143,10 +142,12 @@ template< typename T > static inline void util_ZeroMemory( T& obj );
//========================================================================= //=========================================================================
cUnixFSServices::cUnixFSServices() : mResolveNames(true) cUnixFSServices::cUnixFSServices() : mResolveNames(true)
{} {
}
cUnixFSServices::~cUnixFSServices() cUnixFSServices::~cUnixFSServices()
{} {
}
//========================================================================= //=========================================================================
// *** VIRTUAL FUNCTION CODE *** // *** VIRTUAL FUNCTION CODE ***
@ -177,7 +178,6 @@ void cUnixFSServices::GetHostID( TSTRING& name ) const
#else #else
ret << 999999; ret << 999999;
#endif #endif
} }
// returns "/" for unix and "\\" for win32 // returns "/" for unix and "\\" for win32
@ -272,9 +272,12 @@ TSTRING& cUnixFSServices::MakeTempFilename( TSTRING& strName ) const
#ifdef HAVE_MKSTEMP #ifdef HAVE_MKSTEMP
// create temp filename and check to see if mkstemp failed // create temp filename and check to see if mkstemp failed
if ((fd = mkstemp( szTemplate )) == -1) { if ((fd = mkstemp(szTemplate)) == -1)
{
throw eFSServicesGeneric(strName); throw eFSServicesGeneric(strName);
} else { }
else
{
close(fd); close(fd);
} }
pchTempFileName = szTemplate; pchTempFileName = szTemplate;
@ -284,7 +287,8 @@ TSTRING& cUnixFSServices::MakeTempFilename( TSTRING& strName ) const
pchTempFileName = mktemp(szTemplate); pchTempFileName = mktemp(szTemplate);
//check to see if mktemp failed //check to see if mktemp failed
if ( pchTempFileName == NULL || strlen(pchTempFileName) == 0) { if (pchTempFileName == NULL || strlen(pchTempFileName) == 0)
{
throw eFSServicesGeneric(strName); throw eFSServicesGeneric(strName);
} }
#endif #endif
@ -304,7 +308,8 @@ void cUnixFSServices::GetTempDirName( TSTRING& strName ) const
strName = mTempPath; strName = mTempPath;
} }
void cUnixFSServices::SetTempDirName(TSTRING& tmpPath) { void cUnixFSServices::SetTempDirName(TSTRING& tmpPath)
{
mTempPath = tmpPath; mTempPath = tmpPath;
} }
@ -369,29 +374,40 @@ void cUnixFSServices::Stat( const TSTRING& strNameC, cFSStatArgs& stat) const
#endif #endif
// set the file type // set the file type
if(S_ISREG(statbuf.st_mode)) stat.mFileType = cFSStatArgs::TY_FILE; if (S_ISREG(statbuf.st_mode))
else if(S_ISDIR(statbuf.st_mode)) stat.mFileType = cFSStatArgs::TY_DIR; stat.mFileType = cFSStatArgs::TY_FILE;
else if(S_ISLNK(statbuf.st_mode)) stat.mFileType = cFSStatArgs::TY_SYMLINK; else if (S_ISDIR(statbuf.st_mode))
else if(S_ISBLK(statbuf.st_mode)) stat.mFileType = cFSStatArgs::TY_BLOCKDEV; stat.mFileType = cFSStatArgs::TY_DIR;
else if(S_ISCHR(statbuf.st_mode)) stat.mFileType = cFSStatArgs::TY_CHARDEV; else if (S_ISLNK(statbuf.st_mode))
else if(S_ISFIFO(statbuf.st_mode)) stat.mFileType = cFSStatArgs::TY_FIFO; stat.mFileType = cFSStatArgs::TY_SYMLINK;
else if (S_ISBLK(statbuf.st_mode))
stat.mFileType = cFSStatArgs::TY_BLOCKDEV;
else if (S_ISCHR(statbuf.st_mode))
stat.mFileType = cFSStatArgs::TY_CHARDEV;
else if (S_ISFIFO(statbuf.st_mode))
stat.mFileType = cFSStatArgs::TY_FIFO;
#ifdef S_ISSOCK #ifdef S_ISSOCK
else if(S_ISSOCK(statbuf.st_mode)) stat.mFileType = cFSStatArgs::TY_SOCK; else if (S_ISSOCK(statbuf.st_mode))
stat.mFileType = cFSStatArgs::TY_SOCK;
#endif #endif
#if HAVE_DOOR_CREATE #if HAVE_DOOR_CREATE
else if(S_ISDOOR(statbuf.st_mode)) stat.mFileType = cFSStatArgs::TY_DOOR; else if (S_ISDOOR(statbuf.st_mode))
stat.mFileType = cFSStatArgs::TY_DOOR;
#endif #endif
#if HAVE_PORT_CREATE #if HAVE_PORT_CREATE
else if(S_ISPORT(statbuf.st_mode)) stat.mFileType = cFSStatArgs::TY_PORT; else if (S_ISPORT(statbuf.st_mode))
stat.mFileType = cFSStatArgs::TY_PORT;
#endif #endif
#ifdef S_ISNAM #ifdef S_ISNAM
else if(S_ISNAM(statbuf.st_mode)) stat.mFileType = cFSStatArgs::TY_NAMED; else if (S_ISNAM(statbuf.st_mode))
stat.mFileType = cFSStatArgs::TY_NAMED;
#endif #endif
else stat.mFileType = cFSStatArgs::TY_INVALID; else
stat.mFileType = cFSStatArgs::TY_INVALID;
} }
void cUnixFSServices::GetMachineName(TSTRING& strName) const void cUnixFSServices::GetMachineName(TSTRING& strName) const
@ -573,7 +589,6 @@ bool cUnixFSServices::GetGroupName( gid_t group_id, TSTRING& tstrGroup ) const
} }
#ifndef S_ISVTX // DOS/DJGPP doesn't have this #ifndef S_ISVTX // DOS/DJGPP doesn't have this
# define S_ISVTX 0 # define S_ISVTX 0
#endif #endif
@ -990,8 +1005,7 @@ bool util_PathFind( TSTRING& strFullPath, const TSTRING& strFilename )
pchTemp++; pchTemp++;
else else
fMorePaths = false; fMorePaths = false;
} } while (!fFoundFile && fMorePaths);
while( !fFoundFile && fMorePaths );
} }
return (fFoundFile); return (fFoundFile);
@ -1142,7 +1156,6 @@ bool util_GetNextPathElement( const TSTRING& strPathC, TSTRING& strElem, int ind
// left, then tell the caller that there aren't that many elemnts // left, then tell the caller that there aren't that many elemnts
if (nextSep == TSTRING::npos && i < index) if (nextSep == TSTRING::npos && i < index)
fMoreSeps = false; fMoreSeps = false;
} }
else else
fMoreSeps = false; fMoreSeps = false;
@ -1168,11 +1181,7 @@ bool util_TrailingSep( TSTRING& str, bool fLeaveSep )
bool fWasSep = false; bool fWasSep = false;
// if there's a trailing sep // if there's a trailing sep
if( if (!str.empty() && str[str.size() - 1] == TW_SLASH)
! str.empty()
&&
str[ str.size() - 1 ] == TW_SLASH
)
{ {
if (!fLeaveSep) if (!fLeaveSep)
str.resize(str.size() - 1); str.resize(str.size() - 1);
@ -1198,11 +1207,11 @@ bool util_TrailingSep( TSTRING& str, bool fLeaveSep )
void util_RemoveTrailingSeps(TSTRING& str) void util_RemoveTrailingSeps(TSTRING& str)
{ {
while (util_TrailingSep(str, false)) while (util_TrailingSep(str, false))
{} {
}
} }
template<typename T> static inline void util_ZeroMemory(T& obj) template<typename T> static inline void util_ZeroMemory(T& obj)
{ {
memset(&obj, 0, sizeof(obj)); memset(&obj, 0, sizeof(obj));
} }

View File

@ -159,10 +159,8 @@ class cUnixFSServices : public iFSServices
virtual TSTRING GetErrString() const; virtual TSTRING GetErrString() const;
private: private:
TSTRING mTempPath; TSTRING mTempPath;
bool mResolveNames; bool mResolveNames;
}; };
#endif //__UNIXFSSERVICES_H #endif //__UNIXFSSERVICES_H

View File

@ -54,7 +54,8 @@
// Argument : CmpFuncT less : Comparison function. Must return as 'std::less'. // Argument : CmpFuncT less : Comparison function. Must return as 'std::less'.
// Will be called as: 'bool less( *FwdIterT, CmpObjT )'. // Will be called as: 'bool less( *FwdIterT, CmpObjT )'.
///////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////
template< class FwdIterT, class CmpObjT, class CmpFuncT > FwdIterT UpperBound( FwdIterT first, FwdIterT last, const CmpObjT& obj, CmpFuncT less ) template<class FwdIterT, class CmpObjT, class CmpFuncT>
FwdIterT UpperBound(FwdIterT first, FwdIterT last, const CmpObjT& obj, CmpFuncT less)
{ {
// count elements in set // count elements in set
int nElemsInSet = 0; int nElemsInSet = 0;
@ -89,4 +90,3 @@ template< class FwdIterT, class CmpObjT, class CmpFuncT > FwdIterT UpperBound( F
} }
#endif // __UPPERBOUND_H #endif // __UPPERBOUND_H

View File

@ -38,18 +38,15 @@
#ifdef TW_OLD_OPENBSD_VARARGS #ifdef TW_OLD_OPENBSD_VARARGS
# undef va_start # undef va_start
# ifdef __GNUC__ # ifdef __GNUC__
# define va_start(ap, last) \ # define va_start(ap, last) ((ap) = (va_list)__builtin_next_arg(last))
((ap) = (va_list)__builtin_next_arg(last))
# else # else
# define va_start(ap, last) \ # define va_start(ap, last) ((ap) = (va_list) & (last) + __va_size(last))
((ap) = (va_list)&(last) + __va_size(last))
# endif # endif
#endif // TW_OLD_OPENBSD_VARARGS #endif // TW_OLD_OPENBSD_VARARGS
iUserNotify* iUserNotify::mpInstance = 0; iUserNotify* iUserNotify::mpInstance = 0;
iUserNotify::iUserNotify(int verboseLevel) : iUserNotify::iUserNotify(int verboseLevel) : mVerboseLevel(verboseLevel)
mVerboseLevel(verboseLevel)
{ {
} }
@ -110,5 +107,3 @@ void iUserNotify::Notify(int verboseLevel, const TCHAR* format, ...)
HandleNotify(verboseLevel, format, args); HandleNotify(verboseLevel, format, args);
va_end(args); va_end(args);
} }

View File

@ -80,12 +80,14 @@ public:
iUserNotify(int verboseLevel = 0); iUserNotify(int verboseLevel = 0);
virtual ~iUserNotify(); virtual ~iUserNotify();
protected: protected:
virtual void HandleNotify(int level, const TCHAR* format, va_list& args) = 0; virtual void HandleNotify(int level, const TCHAR* format, va_list& args) = 0;
// this is implemented in derived classes to implement the specific type of // this is implemented in derived classes to implement the specific type of
// notification desired // notification desired
int mVerboseLevel; int mVerboseLevel;
private: private:
static iUserNotify* mpInstance; static iUserNotify* mpInstance;
}; };
@ -129,4 +131,3 @@ inline void iUserNotify::SetInstance(iUserNotify* pInst)
#endif //__USERNOTIFY_H #endif //__USERNOTIFY_H

View File

@ -53,4 +53,3 @@ void cUserNotifyStdout::HandleNotify( int level, const TCHAR* format, va_list& a
fflush(stderr); fflush(stderr);
} }
} }

View File

@ -50,4 +50,3 @@ public:
}; };
#endif /* __USERNOTIFYSTDOUT_H */ #endif /* __USERNOTIFYSTDOUT_H */

View File

@ -167,4 +167,3 @@ void cUserStringMemBased::AddString(int setID, int stringID, TCHAR* string)
setItr->second->insert(std::pair<int, TCHAR*>(stringID, string)); setItr->second->insert(std::pair<int, TCHAR*>(stringID, string));
} }

View File

@ -88,4 +88,3 @@ private:
# endif /* _MSC_VER */ # endif /* _MSC_VER */
#endif // __USERSTRINGMEM_H #endif // __USERSTRINGMEM_H

View File

@ -80,13 +80,15 @@ public:
~wc16_string_impl(); // call Release() to delete ~wc16_string_impl(); // call Release() to delete
private: private:
void operator = (const wc16_string_impl& rhs) { return; } // don't call void operator=(const wc16_string_impl& rhs)
{
return;
} // don't call
}; };
static WCHAR16 NULL_WCHAR16 = 0; static WCHAR16 NULL_WCHAR16 = 0;
wc16_string::wc16_string() wc16_string::wc16_string() : mpData(0)
: mpData(0)
{ {
} }
@ -134,20 +136,17 @@ int wc16_string::compare(const wc16_string& rhs) const
return memcmp(c_str(), rhs.c_str(), length() * sizeof(WCHAR16)); return memcmp(c_str(), rhs.c_str(), length() * sizeof(WCHAR16));
} }
wc16_string::size_type wc16_string::size_type wc16_string::length() const
wc16_string::length() const
{ {
return mpData ? mpData->length : 0; return mpData ? mpData->length : 0;
} }
wc16_string::size_type wc16_string::size_type wc16_string::size() const
wc16_string::size() const
{ {
return mpData ? mpData->length : 0; return mpData ? mpData->length : 0;
} }
wc16_string::const_iterator wc16_string::const_iterator wc16_string::c_str() const
wc16_string::c_str() const
{ {
if (mpData == 0) if (mpData == 0)
return &NULL_WCHAR16; return &NULL_WCHAR16;
@ -157,35 +156,24 @@ wc16_string::c_str() const
return mpData->pString; return mpData->pString;
} }
wc16_string::const_iterator wc16_string::const_iterator wc16_string::begin() const
wc16_string::begin() const
{ {
return (const_cast<wc16_string*>(this))->begin(); return (const_cast<wc16_string*>(this))->begin();
} }
wc16_string::iterator wc16_string::iterator wc16_string::begin()
wc16_string::begin()
{ {
return mpData ? mpData->pString : &NULL_WCHAR16; return mpData ? mpData->pString : &NULL_WCHAR16;
} }
wc16_string::const_iterator wc16_string::const_iterator wc16_string::end() const
wc16_string::end() const
{ {
return return const_cast<iterator>(mpData ? mpData->pString + mpData->length : &NULL_WCHAR16);
const_cast< iterator >(
mpData
? mpData->pString + mpData->length
: &NULL_WCHAR16 );
} }
wc16_string::iterator wc16_string::iterator wc16_string::end()
wc16_string::end()
{ {
return return mpData ? mpData->pString + mpData->length : &NULL_WCHAR16;
mpData
? mpData->pString + mpData->length
: &NULL_WCHAR16;
} }
wc16_string::const_iterator wc16_string::data() const wc16_string::const_iterator wc16_string::data() const
@ -339,4 +327,3 @@ void wc16_string_impl::CopyString(const wc16_string_impl& rhs)
memcpy(this->pString, rhs.pString, newlen * sizeof(WCHAR16)); memcpy(this->pString, rhs.pString, newlen * sizeof(WCHAR16));
} }

View File

@ -70,7 +70,6 @@ class wc16_string_impl;
class wc16_string class wc16_string
{ {
public: public:
typedef WCHAR16 value_type; typedef WCHAR16 value_type;
typedef value_type* iterator; typedef value_type* iterator;
typedef const value_type* const_iterator; typedef const value_type* const_iterator;
@ -110,9 +109,7 @@ public:
void swapbytes(); // useful to convert to network byte order void swapbytes(); // useful to convert to network byte order
private: private:
wc16_string_impl* mpData; wc16_string_impl* mpData;
}; };
#endif #endif

View File

@ -45,26 +45,43 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// cBlock // cBlock
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <int SIZE> template<int SIZE> class cBlock
class cBlock
{ {
public: public:
enum { INVALID_NUM = -1 }; enum
{
INVALID_NUM = -1
};
cBlock(); cBlock();
void SetDirty () { mbDirty = true; } void SetDirty()
bool IsDirty () const { return mbDirty; } {
int GetBlockNum () const { return mBlockNum; } mbDirty = true;
int8* GetData() { return mpData; } }
bool IsDirty() const
{
return mbDirty;
}
int GetBlockNum() const
{
return mBlockNum;
}
int8* GetData()
{
return mpData;
}
bool AssertValid() const; bool AssertValid() const;
// this asserts and returns false if the guard bytes have been corrupted // this asserts and returns false if the guard bytes have been corrupted
bool IsValidAddr(int8* pAddr) const; bool IsValidAddr(int8* pAddr) const;
// returns true if pAddr falls within mpData // returns true if pAddr falls within mpData
protected: protected:
enum { NUM_GUARD_BLOCKS = 8, // associated with BYTE_ALIGN: see ctor for info enum
GUARD_BLOCK_VAL = 0xAB }; // odd, non-zero value for debugging {
NUM_GUARD_BLOCKS = 8, // associated with BYTE_ALIGN: see ctor for info
GUARD_BLOCK_VAL = 0xAB
}; // odd, non-zero value for debugging
// guardMin and guardMax are used to detect bad writes // guardMin and guardMax are used to detect bad writes
uint8 mGuardMin[NUM_GUARD_BLOCKS]; uint8 mGuardMin[NUM_GUARD_BLOCKS];
@ -77,10 +94,7 @@ protected:
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// ctor // ctor
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <int SIZE> template<int SIZE> inline cBlock<SIZE>::cBlock() : mbDirty(false), mBlockNum(cBlock::INVALID_NUM)
inline cBlock<SIZE>::cBlock()
: mbDirty (false),
mBlockNum (cBlock::INVALID_NUM)
{ {
// To prevent misaligned memory access, the size of the data and the // To prevent misaligned memory access, the size of the data and the
// number of guard blocks must be a multiple of the byte alignment // number of guard blocks must be a multiple of the byte alignment
@ -104,17 +118,12 @@ inline cBlock<SIZE>::cBlock()
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// ctor // ctor
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <int SIZE> template<int SIZE> inline bool cBlock<SIZE>::AssertValid() const
inline bool cBlock<SIZE>::AssertValid() const
{ {
// determine if guard bites have been accidentally overwritten // determine if guard bites have been accidentally overwritten
for (int i = 0; i < NUM_GUARD_BLOCKS; i++) for (int i = 0; i < NUM_GUARD_BLOCKS; i++)
{ {
if( if ((mGuardMin[i] != (uint8)GUARD_BLOCK_VAL) || (mGuardMax[i] != (uint8)GUARD_BLOCK_VAL))
( mGuardMin[i] != (uint8) GUARD_BLOCK_VAL )
||
( mGuardMax[i] != (uint8) GUARD_BLOCK_VAL )
)
{ {
ASSERT(false); ASSERT(false);
return false; return false;
@ -124,8 +133,7 @@ inline bool cBlock<SIZE>::AssertValid() const
return true; return true;
} }
template <int SIZE> template<int SIZE> inline bool cBlock<SIZE>::IsValidAddr(int8* pAddr) const
inline bool cBlock<SIZE>::IsValidAddr(int8* pAddr) const
{ {
return ((pAddr >= &mpData[0]) && (pAddr <= &mpData[SIZE - 1])); return ((pAddr >= &mpData[0]) && (pAddr <= &mpData[SIZE - 1]));
} }
@ -134,17 +142,28 @@ inline bool cBlock<SIZE>::IsValidAddr(int8* pAddr) const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// cBlockImpl // cBlockImpl
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <int SIZE> template<int SIZE> class cBlockImpl : public cBlock<SIZE>
class cBlockImpl : public cBlock<SIZE>
{ {
public: public:
enum { INVALID_NUM = -1 }; enum
{
INVALID_NUM = -1
};
cBlockImpl(); cBlockImpl();
void SetBlockNum ( int blockNum ) { cBlock<SIZE>::mBlockNum = blockNum; } void SetBlockNum(int blockNum)
void SetTimestamp( uint32 timestamp ) { mTimestamp = timestamp; } {
uint32 GetTimestamp() const { return mTimestamp; } cBlock<SIZE>::mBlockNum = blockNum;
}
void SetTimestamp(uint32 timestamp)
{
mTimestamp = timestamp;
}
uint32 GetTimestamp() const
{
return mTimestamp;
}
void Write(cBidirArchive& arch); //throw( eArchive ) void Write(cBidirArchive& arch); //throw( eArchive )
void Read(cBidirArchive& arch, int blockNum = INVALID_NUM); //throw( eArchive ) void Read(cBidirArchive& arch, int blockNum = INVALID_NUM); //throw( eArchive )
@ -156,18 +175,14 @@ protected:
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// ctor // ctor
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <int SIZE> template<int SIZE> inline cBlockImpl<SIZE>::cBlockImpl() : cBlock<SIZE>(), mTimestamp(0)
inline cBlockImpl<SIZE>::cBlockImpl()
: cBlock<SIZE> ( ),
mTimestamp (0)
{ {
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Write // Write
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <int SIZE> template<int SIZE> inline void cBlockImpl<SIZE>::Write(cBidirArchive& arch) //throw( eArchive )
inline void cBlockImpl<SIZE>::Write( cBidirArchive& arch ) //throw( eArchive )
{ {
ASSERT(mbDirty); ASSERT(mbDirty);
ASSERT((mBlockNum >= 0) && (((mBlockNum + 1) * SIZE) <= arch.Length())); ASSERT((mBlockNum >= 0) && (((mBlockNum + 1) * SIZE) <= arch.Length()));
@ -181,8 +196,7 @@ inline void cBlockImpl<SIZE>::Write( cBidirArchive& arch ) //throw( eArchive )
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Read // Read
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <int SIZE> template<int SIZE> inline void cBlockImpl<SIZE>::Read(cBidirArchive& arch, int blockNum) //throw( eArchive )
inline void cBlockImpl<SIZE>::Read( cBidirArchive& arch, int blockNum ) //throw( eArchive )
{ {
if (blockNum != INVALID_NUM) if (blockNum != INVALID_NUM)
cBlock<SIZE>::mBlockNum = blockNum; cBlock<SIZE>::mBlockNum = blockNum;
@ -198,4 +212,3 @@ inline void cBlockImpl<SIZE>::Read( cBidirArchive& arch, int blockNum ) //throw(
} }
#endif #endif

View File

@ -52,11 +52,7 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// ctor // ctor
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
cBlockFile::cBlockFile() cBlockFile::cBlockFile() : mNumPages(-1), mNumBlocks(-1), mTimer(0), mpArchive(0)
: mNumPages (-1),
mNumBlocks (-1),
mTimer (0),
mpArchive (0)
{ {
#ifdef _BLOCKFILE_DEBUG #ifdef _BLOCKFILE_DEBUG
@ -230,7 +226,6 @@ cBlockFile::Block* cBlockFile::GetBlock( int blockNum ) //throw (eArchive)
AssertValid(); AssertValid();
#endif #endif
return &(*earliestIter); return &(*earliestIter);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -310,10 +305,14 @@ void cBlockFile::TraceContents(int dl) const
int cnt = 0; int cnt = 0;
for (BlockVector::const_iterator i = mvPagedBlocks.begin(); i != mvPagedBlocks.end(); i++, cnt++) for (BlockVector::const_iterator i = mvPagedBlocks.begin(); i != mvPagedBlocks.end(); i++, cnt++)
{ {
d.Trace( dl, "Page[%d] Block Num=%d Timestamp=%d Dirty=%s\n", cnt, i->GetBlockNum(), i->GetTimestamp(), i->IsDirty() ? "true" : "false"); d.Trace(dl,
"Page[%d] Block Num=%d Timestamp=%d Dirty=%s\n",
cnt,
i->GetBlockNum(),
i->GetTimestamp(),
i->IsDirty() ? "true" : "false");
} }
d.Trace(dl, "-------------------------\n"); d.Trace(dl, "-------------------------\n");
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -331,7 +330,11 @@ void cBlockFile::AssertValid() const
{ {
cDebug d("cBlockFile::AssertValid"); cDebug d("cBlockFile::AssertValid");
d.Trace(cDebug::D_DEBUG, "FATAL ERROR!!!\n"); d.Trace(cDebug::D_DEBUG, "FATAL ERROR!!!\n");
d.Trace(cDebug::D_DEBUG, "mpArchive->Length() = %d \n\t!= blocksize * numblocks = %d * %d\n", int(mpArchive->Length()), int(GetBlockSize()), int(GetNumBlocks())); d.Trace(cDebug::D_DEBUG,
"mpArchive->Length() = %d \n\t!= blocksize * numblocks = %d * %d\n",
int(mpArchive->Length()),
int(GetBlockSize()),
int(GetNumBlocks()));
d.Trace(cDebug::D_DEBUG, "now tracing the contents...\n"); d.Trace(cDebug::D_DEBUG, "now tracing the contents...\n");
TraceContents(cDebug::D_DEBUG); TraceContents(cDebug::D_DEBUG);
} }
@ -346,8 +349,7 @@ void cBlockFile::AssertValid() const
// make sure the block number is valid // make sure the block number is valid
// //
int blockNum = i->GetBlockNum(); int blockNum = i->GetBlockNum();
ASSERT( (blockNum == cBlock<BLOCK_SIZE>::INVALID_NUM) || ASSERT((blockNum == cBlock<BLOCK_SIZE>::INVALID_NUM) || ((blockNum >= 0) && (blockNum < GetNumBlocks())));
( (blockNum >= 0) && (blockNum < GetNumBlocks()) ) );
// //
// make sure the time stamp is less than or equal to the timer time... // make sure the time stamp is less than or equal to the timer time...
// //
@ -359,4 +361,3 @@ void cBlockFile::AssertValid() const
} }
#endif //_BLOCKFILE_DEBUG #endif //_BLOCKFILE_DEBUG

Some files were not shown because too many files have changed in this diff Show More