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:
parent
184b260d9f
commit
ccf8a62fa4
|
@ -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
|
||||
...
|
||||
|
|
@ -1,2 +1 @@
|
|||
#define BUILD_NUM _T("0")
|
||||
|
||||
|
|
|
@ -54,10 +54,10 @@
|
|||
//=============================================================================
|
||||
// eArchiveCrypto
|
||||
//=============================================================================
|
||||
TSTRING eArchiveCrypto::GetMsg( ) const
|
||||
TSTRING eArchiveCrypto::GetMsg() const
|
||||
{
|
||||
// RAD: Updated this to use new stringtable
|
||||
return ( mMsg + TSS_GetString( cCore, core::STR_ERR2_ARCH_CRYPTO_ERR ) );
|
||||
return (mMsg + TSS_GetString(cCore, core::STR_ERR2_ARCH_CRYPTO_ERR));
|
||||
}
|
||||
|
||||
|
||||
|
@ -113,22 +113,22 @@ void cArchive::ReadString(TSTRING& ret) // throw(eArchive)
|
|||
{
|
||||
// read in size of string
|
||||
int16 size;
|
||||
ReadInt16( size );
|
||||
ReadInt16(size);
|
||||
|
||||
// create buffer for WCHAR16 string
|
||||
wc16_string ws;
|
||||
ws.resize( size );
|
||||
ws.resize(size);
|
||||
WCHAR16* pwc = (WCHAR16*)ws.data();
|
||||
|
||||
for( int n = 0; n < size; n++ )
|
||||
for (int n = 0; n < size; n++)
|
||||
{
|
||||
int16 i16;
|
||||
ReadInt16( i16 );
|
||||
ReadInt16(i16);
|
||||
*pwc++ = i16;
|
||||
}
|
||||
|
||||
// convert WCHAR16 string to a TSTRING
|
||||
ret = cStringUtil::WstrToTstr( ws );
|
||||
ret = cStringUtil::WstrToTstr(ws);
|
||||
}
|
||||
|
||||
int cArchive::ReadBlob(void* pBlob, int count)
|
||||
|
@ -163,20 +163,20 @@ void cArchive::WriteString(TSTRING s) // throw(eArchive)
|
|||
{
|
||||
// convert string to a UCS2 string
|
||||
wc16_string ws;
|
||||
cStringUtil::Convert( ws, s ); // Make convert "type-dispatched"
|
||||
cStringUtil::Convert(ws, s); // Make convert "type-dispatched"
|
||||
|
||||
// we assume that we can represent the size as a unsigned 16-bit number
|
||||
// (we actually write it as a signed number, but we cast it)
|
||||
if( ws.length() > TSS_INT16_MAX )
|
||||
ThrowAndAssert( eArchiveStringTooLong() );
|
||||
if (ws.length() > TSS_INT16_MAX)
|
||||
ThrowAndAssert(eArchiveStringTooLong());
|
||||
|
||||
WriteInt16( static_cast<int16>( ws.length() ) );
|
||||
WriteInt16(static_cast<int16>(ws.length()));
|
||||
|
||||
// write out each 16 bit character
|
||||
// RAD:09/03/99 -- Optimized for performance with "const"
|
||||
wc16_string::const_iterator at = ws.begin();
|
||||
while ( at != ws.end() )
|
||||
WriteInt16( *at++ );
|
||||
while (at != ws.end())
|
||||
WriteInt16(*at++);
|
||||
}
|
||||
|
||||
|
||||
|
@ -193,24 +193,27 @@ int32 cArchive::GetStorageSize(const TSTRING& str)
|
|||
// after the length, all of the characters in the string are written as 16-bit values,
|
||||
// except for the null character
|
||||
//
|
||||
size += ( str.length() * 2 );
|
||||
size += (str.length() * 2);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int64 cArchive::Copy(cArchive* pFrom, int64 amt)
|
||||
{
|
||||
enum { BUF_SIZE = 2048 };
|
||||
enum
|
||||
{
|
||||
BUF_SIZE = 2048
|
||||
};
|
||||
int8 buf[BUF_SIZE];
|
||||
int64 amtLeft = amt;
|
||||
|
||||
while(amtLeft > 0)
|
||||
while (amtLeft > 0)
|
||||
{
|
||||
int64 amtToRead = amtLeft > (int64)BUF_SIZE ? (int64)BUF_SIZE : amtLeft;
|
||||
int64 amtRead = pFrom->ReadBlob(buf, static_cast<int>( amtToRead ) );
|
||||
int64 amtRead = pFrom->ReadBlob(buf, static_cast<int>(amtToRead));
|
||||
amtLeft -= amtRead;
|
||||
WriteBlob(buf, static_cast<int>( amtRead ) );
|
||||
if(amtRead < amtToRead)
|
||||
WriteBlob(buf, static_cast<int>(amtRead));
|
||||
if (amtRead < amtToRead)
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -288,8 +291,7 @@ void cMemMappedArchive::SetNewMap(void* pMap, int64 offset, int64 length) const
|
|||
// mapped.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cMemoryArchive::cMemoryArchive(int maxSize)
|
||||
: mMaxAllocatedLen(maxSize)
|
||||
cMemoryArchive::cMemoryArchive(int maxSize) : mMaxAllocatedLen(maxSize)
|
||||
{
|
||||
ASSERT(maxSize > 0);
|
||||
mpMemory = 0;
|
||||
|
@ -321,13 +323,15 @@ void cMemoryArchive::Seek(int64 offset, SeekFrom from) // throw(eArchive)
|
|||
offset = mLogicalSize + (int)offset;
|
||||
break;
|
||||
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)
|
||||
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);
|
||||
}
|
||||
|
||||
int64 cMemoryArchive::CurrentPos() const
|
||||
|
@ -350,8 +354,8 @@ void cMemoryArchive::Truncate()
|
|||
|
||||
void cMemoryArchive::MapArchive(int64 offset, int64 len) // throw(eArchive)
|
||||
{
|
||||
if ( offset + (int)len > mLogicalSize )
|
||||
AllocateMemory( static_cast<int>( offset + len ) );
|
||||
if (offset + (int)len > mLogicalSize)
|
||||
AllocateMemory(static_cast<int>(offset + len));
|
||||
|
||||
SetNewMap(mpMemory + offset, offset, len);
|
||||
}
|
||||
|
@ -404,7 +408,7 @@ void cMemoryArchive::AllocateMemory(int len) // throw(eArchive)
|
|||
ThrowAndAssert(eArchiveOutOfMem());
|
||||
#endif
|
||||
|
||||
if( 0 == mAllocatedLen )
|
||||
if (0 == mAllocatedLen)
|
||||
mAllocatedLen = MIN_ALLOCATED_SIZE;
|
||||
|
||||
while (mAllocatedLen < len)
|
||||
|
@ -464,26 +468,20 @@ public:
|
|||
//-----------------------------------------------------------------------------
|
||||
// cFixedMemArchive
|
||||
//-----------------------------------------------------------------------------
|
||||
cFixedMemArchive::cFixedMemArchive()
|
||||
: mpMemory (0),
|
||||
mSize (0),
|
||||
mReadHead (0)
|
||||
cFixedMemArchive::cFixedMemArchive() : mpMemory(0), mSize(0), mReadHead(0)
|
||||
{
|
||||
}
|
||||
|
||||
cFixedMemArchive::cFixedMemArchive( int8* pMem, int32 size )
|
||||
: mpMemory (0),
|
||||
mSize (0),
|
||||
mReadHead (0)
|
||||
cFixedMemArchive::cFixedMemArchive(int8* pMem, int32 size) : mpMemory(0), mSize(0), mReadHead(0)
|
||||
{
|
||||
Attach( pMem, size );
|
||||
Attach(pMem, size);
|
||||
}
|
||||
|
||||
cFixedMemArchive::~cFixedMemArchive()
|
||||
{
|
||||
}
|
||||
|
||||
void cFixedMemArchive::Attach( int8* pMem, int32 size )
|
||||
void cFixedMemArchive::Attach(int8* pMem, int32 size)
|
||||
{
|
||||
mpMemory = pMem;
|
||||
mSize = size;
|
||||
|
@ -503,13 +501,15 @@ void cFixedMemArchive::Seek(int64 offset, SeekFrom from) // throw(eArchive)
|
|||
offset = mSize + (int)offset;
|
||||
break;
|
||||
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)
|
||||
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);
|
||||
}
|
||||
|
||||
int64 cFixedMemArchive::CurrentPos() const
|
||||
|
@ -529,10 +529,10 @@ bool cFixedMemArchive::EndOfFile()
|
|||
|
||||
int cFixedMemArchive::Read(void* pDest, int count) // throw(eArchive)
|
||||
{
|
||||
ASSERT( pDest );
|
||||
ASSERT(pDest);
|
||||
if (mReadHead + count > mSize)
|
||||
{
|
||||
count = static_cast<int>( mSize - mReadHead );
|
||||
count = static_cast<int>(mSize - mReadHead);
|
||||
if (count <= 0)
|
||||
return 0;
|
||||
}
|
||||
|
@ -549,7 +549,7 @@ int cFixedMemArchive::Write(const void* pDest, int count) // throw(eArchive)
|
|||
{
|
||||
if (mReadHead + count > mSize)
|
||||
{
|
||||
ASSERT( false );
|
||||
ASSERT(false);
|
||||
throw eArchiveWrite();
|
||||
}
|
||||
|
||||
|
@ -566,11 +566,9 @@ int cFixedMemArchive::Write(const void* pDest, int count) // throw(eArchive)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Ctor -- Initialize member variables to 0 or NULL equivalents.
|
||||
cFileArchive::cFileArchive() :
|
||||
mFileSize(0),
|
||||
mReadHead(0),
|
||||
isWritable(false)
|
||||
{}
|
||||
cFileArchive::cFileArchive() : mFileSize(0), mReadHead(0), isWritable(false)
|
||||
{
|
||||
}
|
||||
|
||||
cFileArchive::~cFileArchive()
|
||||
{
|
||||
|
@ -578,14 +576,14 @@ cFileArchive::~cFileArchive()
|
|||
|
||||
bool cFileArchive::EndOfFile()
|
||||
{
|
||||
return ( mReadHead >= mFileSize );
|
||||
return (mReadHead >= mFileSize);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Seek -- This is where the actual offset is performed. The default
|
||||
// for each archive will be 0.
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
void cFileArchive::Seek( int64 offset, SeekFrom from) // throw(eArchive)
|
||||
void cFileArchive::Seek(int64 offset, SeekFrom from) // throw(eArchive)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -600,19 +598,19 @@ void cFileArchive::Seek( int64 offset, SeekFrom from) // throw(eArchive)
|
|||
offset = mFileSize + offset;
|
||||
break;
|
||||
default:
|
||||
throw eArchiveSeek( mCurrentFilename, iFSServices::GetInstance()->GetErrString() ) ;
|
||||
throw eArchiveSeek(mCurrentFilename, iFSServices::GetInstance()->GetErrString());
|
||||
}
|
||||
|
||||
if ( offset > mFileSize )
|
||||
throw eArchiveSeek( mCurrentFilename, iFSServices::GetInstance()->GetErrString() ) ;
|
||||
if (offset > mFileSize)
|
||||
throw eArchiveSeek(mCurrentFilename, iFSServices::GetInstance()->GetErrString());
|
||||
mReadHead = offset;
|
||||
|
||||
mCurrentFile.Seek(mReadHead, cFile::SEEK_BEGIN);
|
||||
//This is where the actual read/writehead is set!!
|
||||
}//try
|
||||
catch( eFile& fileError )
|
||||
} //try
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
throw( eArchiveSeek( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchiveSeek(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -630,9 +628,9 @@ int64 cFileArchive::Length(void) const
|
|||
{
|
||||
return mCurrentFile.GetSize();
|
||||
}
|
||||
catch(eFile& fileError)
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
throw( eArchiveSeek( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchiveSeek(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -645,22 +643,22 @@ void cFileArchive::OpenRead(const TCHAR* filename, uint32 openFlags)
|
|||
{
|
||||
// set up open flags
|
||||
uint32 flags = cFile::OPEN_READ;
|
||||
flags |= ( ( openFlags & FA_OPEN_TRUNCATE ) ? cFile::OPEN_TRUNCATE : 0 );
|
||||
flags |= ( ( openFlags & FA_OPEN_TEXT ) ? cFile::OPEN_TEXT : 0 );
|
||||
flags |= ( ( openFlags & FA_SCANNING ) ? cFile::OPEN_SCANNING : 0 );
|
||||
flags |= ( ( openFlags & FA_DIRECT ) ? cFile::OPEN_DIRECT : 0 );
|
||||
flags |= ((openFlags & FA_OPEN_TRUNCATE) ? cFile::OPEN_TRUNCATE : 0);
|
||||
flags |= ((openFlags & FA_OPEN_TEXT) ? cFile::OPEN_TEXT : 0);
|
||||
flags |= ((openFlags & FA_SCANNING) ? cFile::OPEN_SCANNING : 0);
|
||||
flags |= ((openFlags & FA_DIRECT) ? cFile::OPEN_DIRECT : 0);
|
||||
|
||||
mOpenFlags = openFlags;
|
||||
mCurrentFilename = filename;
|
||||
mCurrentFile.Open( filename, flags );
|
||||
mCurrentFile.Open(filename, flags);
|
||||
isWritable = false;
|
||||
|
||||
mFileSize = mCurrentFile.GetSize();
|
||||
mReadHead = mCurrentFile.Seek( 0, cFile::SEEK_BEGIN );
|
||||
mReadHead = mCurrentFile.Seek(0, cFile::SEEK_BEGIN);
|
||||
}
|
||||
catch(eFile& fileError)
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
throw(eArchiveOpen( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchiveOpen(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -673,22 +671,22 @@ void cFileArchive::OpenReadWrite(const TCHAR* filename, uint32 openFlags)
|
|||
{
|
||||
// set up open flags
|
||||
uint32 flags = cFile::OPEN_WRITE;
|
||||
flags |= ( ( openFlags & FA_OPEN_TRUNCATE ) ? cFile::OPEN_TRUNCATE : 0 );
|
||||
flags |= ( ( openFlags & FA_OPEN_TEXT ) ? cFile::OPEN_TEXT : 0 );
|
||||
flags |= ( ( openFlags & FA_SCANNING ) ? cFile::OPEN_SCANNING : 0 );
|
||||
flags |= ( ( openFlags & FA_DIRECT ) ? cFile::OPEN_DIRECT : 0 );
|
||||
flags |= ((openFlags & FA_OPEN_TRUNCATE) ? cFile::OPEN_TRUNCATE : 0);
|
||||
flags |= ((openFlags & FA_OPEN_TEXT) ? cFile::OPEN_TEXT : 0);
|
||||
flags |= ((openFlags & FA_SCANNING) ? cFile::OPEN_SCANNING : 0);
|
||||
flags |= ((openFlags & FA_DIRECT) ? cFile::OPEN_DIRECT : 0);
|
||||
|
||||
mOpenFlags = openFlags;
|
||||
mCurrentFilename = filename;
|
||||
mCurrentFile.Open( filename, flags );
|
||||
mCurrentFile.Open(filename, flags);
|
||||
isWritable = true;
|
||||
|
||||
mFileSize = mCurrentFile.GetSize();
|
||||
mReadHead = mCurrentFile.Seek( 0, cFile::SEEK_BEGIN );
|
||||
mReadHead = mCurrentFile.Seek(0, cFile::SEEK_BEGIN);
|
||||
}
|
||||
catch(eFile& fileError)
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
throw( eArchiveOpen( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchiveOpen(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -714,9 +712,9 @@ void cFileArchive::Close()
|
|||
|
||||
mCurrentFilename = _T("");
|
||||
}
|
||||
catch(eFile& fileError)
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
throw( eArchive( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchive(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -729,43 +727,42 @@ int cFileArchive::Read(void* pDest, int count)
|
|||
|
||||
try
|
||||
{
|
||||
if ( mReadHead + count > mFileSize && !(mOpenFlags & FA_DIRECT))
|
||||
count = static_cast<int>( mFileSize - mReadHead );
|
||||
if (mReadHead + count > mFileSize && !(mOpenFlags & FA_DIRECT))
|
||||
count = static_cast<int>(mFileSize - mReadHead);
|
||||
|
||||
if ( pDest != NULL )
|
||||
if (pDest != NULL)
|
||||
{
|
||||
int nbRead =
|
||||
static_cast<int>( mCurrentFile.Read( pDest, count ) );
|
||||
int nbRead = static_cast<int>(mCurrentFile.Read(pDest, count));
|
||||
|
||||
// 'count' may not be equal to 'nbRead' if the file is open in
|
||||
// text mode.
|
||||
count = nbRead;
|
||||
if(count < 0) count = 0;
|
||||
if (count < 0)
|
||||
count = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
int32 dummy;
|
||||
for (i = count; ; i -= sizeof(int32))
|
||||
for (i = count;; i -= sizeof(int32))
|
||||
{
|
||||
if (i < (int)sizeof(int32))
|
||||
{
|
||||
if (i > 0)
|
||||
mCurrentFile.Read( &dummy, i );
|
||||
mCurrentFile.Read(&dummy, i);
|
||||
break;
|
||||
}
|
||||
mCurrentFile.Read( &dummy, i );
|
||||
mCurrentFile.Read(&dummy, i);
|
||||
}
|
||||
}
|
||||
|
||||
mReadHead += count;
|
||||
return count;
|
||||
}
|
||||
catch( eFile& fileError )
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
throw( eArchiveRead( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchiveRead(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
@ -777,35 +774,35 @@ int cFileArchive::Write(const void* pDest, int count) // throw(eArchive)
|
|||
try
|
||||
{
|
||||
int64 actual_count = 0;
|
||||
ASSERT( mCurrentFile.isWritable );
|
||||
ASSERT(mCurrentFile.isWritable);
|
||||
|
||||
actual_count = mCurrentFile.Write( pDest, count );
|
||||
actual_count = mCurrentFile.Write(pDest, count);
|
||||
|
||||
if ( actual_count < count )
|
||||
if (actual_count < count)
|
||||
{
|
||||
//Disk full??
|
||||
throw eArchiveWrite( mCurrentFilename, iFSServices::GetInstance()->GetErrString() ) ;
|
||||
throw eArchiveWrite(mCurrentFilename, iFSServices::GetInstance()->GetErrString());
|
||||
}
|
||||
|
||||
// increment the read/write head
|
||||
mReadHead += actual_count;
|
||||
|
||||
// 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
|
||||
cDebug d("cFileArchive::Write()");
|
||||
d.TraceDebug(_T("file(%s) adjusted mFileSize = %d mReadHead = %d\n"), mCurrentFilename.c_str(), (int)mFileSize, (int)mReadHead);
|
||||
#endif
|
||||
#endif
|
||||
mFileSize = mReadHead;
|
||||
}
|
||||
|
||||
return (int)actual_count;
|
||||
}
|
||||
catch( eFile& fileError )
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
throw( eArchiveWrite( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchiveWrite(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -815,53 +812,53 @@ int cFileArchive::Write(const void* pDest, int count) // throw(eArchive)
|
|||
/////////////////////////////////////////////////////////////////////////
|
||||
void cFileArchive::Truncate() // throw(eArchive)
|
||||
{
|
||||
ASSERT( mCurrentFile.IsOpen() );
|
||||
ASSERT( mCurrentFile.isWritable );
|
||||
ASSERT(mCurrentFile.IsOpen());
|
||||
ASSERT(mCurrentFile.isWritable);
|
||||
|
||||
try
|
||||
{
|
||||
mCurrentFile.Truncate ( mReadHead );
|
||||
mCurrentFile.Truncate(mReadHead);
|
||||
}
|
||||
catch( eFile& fileError )
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
//TODO: create an error number for truncate...
|
||||
throw( eArchiveWrite( mCurrentFilename, fileError.GetDescription() ) );
|
||||
throw(eArchiveWrite(mCurrentFilename, fileError.GetDescription()));
|
||||
}
|
||||
|
||||
mFileSize = mReadHead;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// OpenReadWrite -- Opens the file to be read or written to
|
||||
//
|
||||
// since we'll never open an existing file, the truncateFile flag is unnecessary.
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
void cLockedTemporaryFileArchive::OpenReadWrite( const TCHAR* filename, uint32 openFlags )
|
||||
void cLockedTemporaryFileArchive::OpenReadWrite(const TCHAR* filename, uint32 openFlags)
|
||||
{
|
||||
TSTRING strTempFile;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
|
||||
ASSERT( !mCurrentFile.IsOpen() ); // shouldn't be able to create a new file when we're already open
|
||||
if ( mCurrentFile.IsOpen() )
|
||||
throw( eArchive( mCurrentFilename, _T("Internal Error") ) );
|
||||
ASSERT(!mCurrentFile.IsOpen()); // shouldn't be able to create a new file when we're already open
|
||||
if (mCurrentFile.IsOpen())
|
||||
throw(eArchive(mCurrentFilename, _T("Internal Error")));
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// if filename is NULL, create a temp file for the caller
|
||||
if( filename == NULL )
|
||||
if (filename == NULL)
|
||||
{
|
||||
try
|
||||
{
|
||||
iFSServices::GetInstance()->GetTempDirName( strTempFile );
|
||||
iFSServices::GetInstance()->GetTempDirName(strTempFile);
|
||||
strTempFile += _T("twtempXXXXXX");
|
||||
iFSServices::GetInstance()->MakeTempFilename( strTempFile );
|
||||
iFSServices::GetInstance()->MakeTempFilename(strTempFile);
|
||||
}
|
||||
catch( eFSServices& fileError)
|
||||
catch (eFSServices& fileError)
|
||||
{
|
||||
TSTRING errStr = TSS_GetString( cCore, core::STR_BAD_TEMPDIRECTORY );
|
||||
TSTRING errStr = TSS_GetString(cCore, core::STR_BAD_TEMPDIRECTORY);
|
||||
throw eArchiveOpen(strTempFile, errStr);
|
||||
}
|
||||
}
|
||||
|
@ -872,27 +869,28 @@ void cLockedTemporaryFileArchive::OpenReadWrite( const TCHAR* filename, uint32 o
|
|||
|
||||
// set up flags
|
||||
uint32 flags = cFile::OPEN_WRITE | cFile::OPEN_LOCKED_TEMP | cFile::OPEN_CREATE | cFile::OPEN_EXCLUSIVE;
|
||||
if ( openFlags & FA_OPEN_TRUNCATE )
|
||||
if (openFlags & FA_OPEN_TRUNCATE)
|
||||
flags |= cFile::OPEN_TRUNCATE;
|
||||
if ( openFlags & FA_OPEN_TEXT )
|
||||
if (openFlags & FA_OPEN_TEXT)
|
||||
flags |= cFile::OPEN_TEXT;
|
||||
|
||||
// open file
|
||||
mCurrentFilename = filename ? filename : strTempFile.c_str();
|
||||
mCurrentFile.Open( mCurrentFilename, flags );
|
||||
mCurrentFile.Open(mCurrentFilename, flags);
|
||||
|
||||
isWritable = true;
|
||||
mFileSize = mCurrentFile.GetSize();
|
||||
mReadHead = mCurrentFile.Seek( 0, cFile::SEEK_BEGIN );
|
||||
mReadHead = mCurrentFile.Seek(0, cFile::SEEK_BEGIN);
|
||||
|
||||
#if 0 // IS_SUNPRO
|
||||
cDebug d("cLockedTemporaryFileArchive::OpenReadWrite()");
|
||||
d.TraceDebug(_T("file(%s) set mFileSize to %d mReadHead to %d\n"), mCurrentFilename.c_str(), (int)mFileSize, (int)mReadHead);
|
||||
#endif
|
||||
|
||||
}//try
|
||||
catch (eFile& fileError) {
|
||||
TSTRING errStr = TSS_GetString( cCore, core::STR_BAD_TEMPDIRECTORY );
|
||||
} //try
|
||||
catch (eFile& fileError)
|
||||
{
|
||||
TSTRING errStr = TSS_GetString(cCore, core::STR_BAD_TEMPDIRECTORY);
|
||||
eArchiveOpen e(strTempFile, errStr);
|
||||
throw e;
|
||||
}
|
||||
|
@ -907,4 +905,3 @@ void cLockedTemporaryFileArchive::Close()
|
|||
// Note: this deletes the file as well
|
||||
cFileArchive::Close();
|
||||
}
|
||||
|
||||
|
|
|
@ -56,24 +56,24 @@
|
|||
//=============================================================================
|
||||
// eArchive exception classes
|
||||
//=============================================================================
|
||||
TSS_FILE_EXCEPTION( eArchive, eFileError );
|
||||
TSS_FILE_EXCEPTION( eArchiveOpen, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveWrite, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveRead, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveEOF, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveSeek, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveMemmap, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveOutOfMem, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveInvalidOp, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveFormat, eArchive );
|
||||
TSS_FILE_EXCEPTION( eArchiveNotRegularFile, eArchive );
|
||||
TSS_BEGIN_EXCEPTION( eArchiveCrypto, eArchive )
|
||||
TSS_FILE_EXCEPTION(eArchive, eFileError);
|
||||
TSS_FILE_EXCEPTION(eArchiveOpen, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveWrite, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveRead, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveEOF, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveSeek, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveMemmap, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveOutOfMem, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveInvalidOp, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveFormat, eArchive);
|
||||
TSS_FILE_EXCEPTION(eArchiveNotRegularFile, eArchive);
|
||||
TSS_BEGIN_EXCEPTION(eArchiveCrypto, eArchive)
|
||||
|
||||
virtual TSTRING GetMsg() const;
|
||||
// eCryptoArchive appends a special string to the end of
|
||||
// all exception messages
|
||||
virtual TSTRING GetMsg() const;
|
||||
// eCryptoArchive appends a special string to the end of
|
||||
// all exception messages
|
||||
TSS_END_EXCEPTION()
|
||||
TSS_EXCEPTION( eArchiveStringTooLong, eArchive );
|
||||
TSS_EXCEPTION(eArchiveStringTooLong, eArchive);
|
||||
|
||||
// throw( eArchiveOpen( cErrorUtil::MakeFileError( fileError.GetMsg(), strTempFile ) ) );
|
||||
|
||||
|
@ -85,7 +85,9 @@ TSS_EXCEPTION( eArchiveStringTooLong, eArchive );
|
|||
class cArchive
|
||||
{
|
||||
public:
|
||||
virtual ~cArchive() {}
|
||||
virtual ~cArchive()
|
||||
{
|
||||
}
|
||||
|
||||
// convenience methods
|
||||
//
|
||||
|
@ -137,7 +139,8 @@ protected:
|
|||
class cBidirArchive : public cArchive
|
||||
{
|
||||
public:
|
||||
enum SeekFrom {
|
||||
enum SeekFrom
|
||||
{
|
||||
BEGINNING = 0,
|
||||
CURRENT = 1,
|
||||
END = -1
|
||||
|
@ -155,7 +158,8 @@ public:
|
|||
class cMemMappedArchive : public cBidirArchive
|
||||
{
|
||||
public:
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
MAP_TO_EOF = -1
|
||||
};
|
||||
|
||||
|
@ -202,7 +206,10 @@ public:
|
|||
|
||||
void Truncate(); // set the length to the current pos
|
||||
|
||||
int8* GetMemory() const { return mpMemory; }
|
||||
int8* GetMemory() const
|
||||
{
|
||||
return mpMemory;
|
||||
}
|
||||
|
||||
protected:
|
||||
int8* mpMemory;
|
||||
|
@ -224,20 +231,21 @@ class cFixedMemArchive : public cBidirArchive
|
|||
{
|
||||
public:
|
||||
cFixedMemArchive();
|
||||
cFixedMemArchive( int8* pMem, int32 size );
|
||||
cFixedMemArchive(int8* pMem, int32 size);
|
||||
virtual ~cFixedMemArchive();
|
||||
|
||||
void Attach( int8* pMem, int32 size );
|
||||
void Attach(int8* pMem, int32 size);
|
||||
// this method associates the archive with pMem and sets the size of the
|
||||
// archive. Unlike cMemoryArchive, this may never grow or shrink in size.
|
||||
|
||||
//-----------------------------------
|
||||
// cBidirArchive interface
|
||||
//-----------------------------------
|
||||
virtual void Seek (int64 offset, SeekFrom from) ; // throw(eArchive);
|
||||
virtual int64 CurrentPos () const ;
|
||||
virtual int64 Length () const ;
|
||||
virtual void Seek(int64 offset, SeekFrom from); // throw(eArchive);
|
||||
virtual int64 CurrentPos() const;
|
||||
virtual int64 Length() const;
|
||||
virtual bool EndOfFile();
|
||||
|
||||
protected:
|
||||
//-----------------------------------
|
||||
// cArchive interface
|
||||
|
@ -265,8 +273,8 @@ public:
|
|||
};
|
||||
|
||||
// TODO: Open should throw
|
||||
virtual void OpenRead(const TCHAR* filename, uint32 openFlags = 0 );
|
||||
virtual void OpenReadWrite(const TCHAR* filename, uint32 openFlags = FA_OPEN_TRUNCATE );
|
||||
virtual void OpenRead(const TCHAR* filename, uint32 openFlags = 0);
|
||||
virtual void OpenReadWrite(const TCHAR* filename, uint32 openFlags = FA_OPEN_TRUNCATE);
|
||||
// opens a file for reading or writing; the file is always created if it doesn't exist,
|
||||
// and is truncated to zero length if truncateFile is set to true;
|
||||
TSTRING GetCurrentFilename(void) const;
|
||||
|
@ -307,7 +315,7 @@ protected:
|
|||
class cLockedTemporaryFileArchive : public cFileArchive
|
||||
{
|
||||
public:
|
||||
virtual void OpenReadWrite ( const TCHAR* filename = NULL, uint32 openFlags = FA_OPEN_TRUNCATE );
|
||||
virtual void OpenReadWrite(const TCHAR* filename = NULL, uint32 openFlags = FA_OPEN_TRUNCATE);
|
||||
// creates the file. filename must not exist on the file system.
|
||||
// if filename is NULL, the class will create and use a temporary file.
|
||||
// truncateFile has no meaning
|
||||
|
@ -320,9 +328,12 @@ public:
|
|||
private:
|
||||
// open for read only makes no sense if we're always creating the file,
|
||||
// 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
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#include "ntmbs.h"
|
||||
|
||||
#if IS_ANDROID
|
||||
int mblen(const char *s, size_t n)
|
||||
int mblen(const char* s, size_t n)
|
||||
{
|
||||
return mbtowc(0, s, n);
|
||||
}
|
||||
|
@ -64,26 +64,26 @@ int mblen(const char *s, size_t n)
|
|||
//
|
||||
|
||||
/* static */
|
||||
bool cCharUtil::PeekNextChar( const TSTRING::const_iterator& cur,
|
||||
bool cCharUtil::PeekNextChar(const TSTRING::const_iterator& cur,
|
||||
const TSTRING::const_iterator& end,
|
||||
TSTRING::const_iterator& first,
|
||||
TSTRING::const_iterator& last )
|
||||
TSTRING::const_iterator& last)
|
||||
{
|
||||
//
|
||||
// do we have a valid string here?
|
||||
//
|
||||
if( cur > end )
|
||||
if (cur > end)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( cur == end )
|
||||
if (cur == end)
|
||||
{
|
||||
first = last = end;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( *cur == _T('\0') )
|
||||
if (*cur == _T('\0'))
|
||||
{
|
||||
first = last = cur;
|
||||
return false;
|
||||
|
@ -98,7 +98,7 @@ bool cCharUtil::PeekNextChar( const TSTRING::const_iterator& cur,
|
|||
else
|
||||
{
|
||||
#if !IS_AROS
|
||||
mblen (NULL, 0);
|
||||
mblen(NULL, 0);
|
||||
int len = mblen(&*cur, MB_CUR_MAX);
|
||||
if (len < 0) //invalid multibyte sequence, but let's not blow up.
|
||||
len = 1;
|
||||
|
@ -138,16 +138,14 @@ bool cCharUtil::PeekNextChar( const TSTRING::const_iterator& cur,
|
|||
//
|
||||
|
||||
/* static */
|
||||
bool cCharUtil::PopNextChar( TSTRING::const_iterator& cur,
|
||||
bool cCharUtil::PopNextChar(TSTRING::const_iterator& cur,
|
||||
const TSTRING::const_iterator& end,
|
||||
TSTRING::const_iterator& first,
|
||||
TSTRING::const_iterator& last )
|
||||
TSTRING::const_iterator& last)
|
||||
{
|
||||
bool f = PeekNextChar( cur, end, first, last );
|
||||
bool f = PeekNextChar(cur, end, first, last);
|
||||
|
||||
cur = last; // pop causes 'cur' to move to just beyond character ('last')
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -44,23 +44,20 @@
|
|||
class cCharUtil
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
// finds the next whole character in string identified by ['cur'-'end')
|
||||
// identifies beginning of char in 'first', then end of character in 'last'
|
||||
// returns 'are there more characters in string?'
|
||||
// if there are no more characters, will return 0 and first = last = end
|
||||
static bool PeekNextChar( const TSTRING::const_iterator& cur,
|
||||
static bool PeekNextChar(const TSTRING::const_iterator& cur,
|
||||
const TSTRING::const_iterator& end,
|
||||
TSTRING::const_iterator& first,
|
||||
TSTRING::const_iterator& last );
|
||||
TSTRING::const_iterator& last);
|
||||
|
||||
// same as PeekNextChar but increments 'cur' to 'last'
|
||||
static bool PopNextChar( TSTRING::const_iterator& cur,
|
||||
static bool PopNextChar(TSTRING::const_iterator& cur,
|
||||
const TSTRING::const_iterator& end,
|
||||
TSTRING::const_iterator& first,
|
||||
TSTRING::const_iterator& last );
|
||||
TSTRING::const_iterator& last);
|
||||
};
|
||||
|
||||
#endif//__CHARUTIL_H
|
||||
|
||||
#endif //__CHARUTIL_H
|
||||
|
|
|
@ -38,9 +38,7 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ctor, dotr
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
cCmdLineParser::cCmdLineParser() :
|
||||
mArgTable(HASH_VERY_SMALL),
|
||||
mLastArgInfo(-1, PARAM_NONE)
|
||||
cCmdLineParser::cCmdLineParser() : mArgTable(HASH_VERY_SMALL), mLastArgInfo(-1, PARAM_NONE)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -51,19 +49,20 @@ cCmdLineParser::~cCmdLineParser()
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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())
|
||||
{
|
||||
// this refers to the list of parameters that comes after all the cmd line switches
|
||||
mLastArgInfo.mId = argId;
|
||||
mLastArgInfo.mNumParams = numParams;
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
|
||||
if(! arg.empty())
|
||||
if (!arg.empty())
|
||||
mArgTable.Insert(arg, cArgInfo(argId, numParams));
|
||||
if(! alias.empty())
|
||||
if (!alias.empty())
|
||||
{
|
||||
// put the alias in the table with a '-' prepended to it so it matches '--'
|
||||
TSTRING str(_T("-"));
|
||||
|
@ -71,8 +70,8 @@ void cCmdLineParser::AddArg(int argId, const TSTRING& arg, const TSTRING& alias,
|
|||
mArgTable.Insert(str, cArgInfo(argId, numParams));
|
||||
}
|
||||
// This argument can appear more than once on the command line.
|
||||
if( multipleAllowed )
|
||||
mMultipleAllowed.insert( argId );
|
||||
if (multipleAllowed)
|
||||
mMultipleAllowed.insert(argId);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -90,7 +89,7 @@ void cCmdLineParser::AddArg(int argId, const TSTRING& arg, const TSTRING& alias,
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Parse
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
||||
void cCmdLineParser::Parse(int argc, const TCHAR* const* argv)
|
||||
{
|
||||
// clear out any existing data
|
||||
mArgData.clear();
|
||||
|
@ -99,34 +98,30 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
|||
bool bProcessedFinalParams = false; // gets set to true when the parameters to the command line are processed
|
||||
|
||||
// I assume argv[0] is the executable name...
|
||||
for(int i=1; i < argc; i++)
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if(argv[i][0] == _T('-'))
|
||||
if (argv[i][0] == _T('-'))
|
||||
{
|
||||
pCurArg = argv[i];
|
||||
|
||||
// this is a switch; find it in the table...
|
||||
cArgInfo argInfo;
|
||||
if ( !mArgTable.Lookup( TSTRING(&argv[i][1] ), argInfo ) )
|
||||
if (!mArgTable.Lookup(TSTRING(&argv[i][1]), argInfo))
|
||||
{
|
||||
// unknown switch!
|
||||
throw eCmdLineInvalidArg(
|
||||
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
|
||||
+ pCurArg );
|
||||
throw eCmdLineInvalidArg(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + pCurArg);
|
||||
}
|
||||
//
|
||||
// make sure this hasn't been specified yet...
|
||||
//
|
||||
if( ArgInList( argInfo.mId ) )
|
||||
if (ArgInList(argInfo.mId))
|
||||
{
|
||||
// Make sure it isn't okay for this one to appear more than once...
|
||||
std::set<int>::iterator it = mMultipleAllowed.find( argInfo.mId );
|
||||
if( it == mMultipleAllowed.end() )
|
||||
std::set<int>::iterator it = mMultipleAllowed.find(argInfo.mId);
|
||||
if (it == mMultipleAllowed.end())
|
||||
{
|
||||
// It wasn't in our list of allowed params, so error.
|
||||
throw eCmdLineMultiArg(
|
||||
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
|
||||
+ argv[i] );
|
||||
throw eCmdLineMultiArg(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + argv[i]);
|
||||
}
|
||||
}
|
||||
//
|
||||
|
@ -134,24 +129,22 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
|||
//
|
||||
mArgData.push_back(cArgData(argInfo.mId, TSTRING(argv[i])));
|
||||
cArgData& curArg = mArgData.back();
|
||||
switch( argInfo.mNumParams )
|
||||
switch (argInfo.mNumParams)
|
||||
{
|
||||
case PARAM_NONE:
|
||||
// make sure there are no parameters to this, but be careful because
|
||||
// it is legal to start the parameters to the executable here.
|
||||
if((i+1 < argc) && (argv[i+1][0] != _T('-')))
|
||||
if ((i + 1 < argc) && (argv[i + 1][0] != _T('-')))
|
||||
{
|
||||
// search for any more parameters
|
||||
// TODO: In the future we may want to support a '--' switch that specifies the start
|
||||
// of parameters to the executable.
|
||||
for (int j = i + 2; j < argc; ++j )
|
||||
for (int j = i + 2; j < argc; ++j)
|
||||
{
|
||||
if (argv[j][0] == _T('-'))
|
||||
{
|
||||
// >0 parameter passed !
|
||||
throw eCmdLineBadParam(
|
||||
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
|
||||
+ pCurArg );
|
||||
throw eCmdLineBadParam(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + pCurArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -160,20 +153,18 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
|||
case PARAM_ONE:
|
||||
// get the next parameter...
|
||||
i++;
|
||||
if ( (i >= argc) || (argv[i][0] == _T('-')) )
|
||||
if ((i >= argc) || (argv[i][0] == _T('-')))
|
||||
{
|
||||
// zero parameters passed to something that needed one param
|
||||
throw eCmdLineBadParam(
|
||||
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
|
||||
+ pCurArg );
|
||||
throw eCmdLineBadParam(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + pCurArg);
|
||||
}
|
||||
|
||||
curArg.mParams.push_back( TSTRING(argv[i]) );
|
||||
curArg.mParams.push_back(TSTRING(argv[i]));
|
||||
break;
|
||||
|
||||
case PARAM_MANY:
|
||||
i++;
|
||||
while((i < argc) && (argv[i][0] != _T('-')))
|
||||
while ((i < argc) && (argv[i][0] != _T('-')))
|
||||
{
|
||||
curArg.mParams.push_back(TSTRING(argv[i]));
|
||||
i++;
|
||||
|
@ -182,7 +173,7 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
|||
break;
|
||||
|
||||
default:
|
||||
ASSERTMSG( false, "Unknown number of arguments to parser" );
|
||||
ASSERTMSG(false, "Unknown number of arguments to parser");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -191,14 +182,14 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
|||
// this must be the final "unnamed" arg
|
||||
// first, make sure it is consistent with the current info...
|
||||
bool bResult = true;
|
||||
switch(mLastArgInfo.mNumParams)
|
||||
switch (mLastArgInfo.mNumParams)
|
||||
{
|
||||
case PARAM_NONE:
|
||||
// this is an error; they didn't want any command line parameters...
|
||||
bResult = false;
|
||||
break;
|
||||
case PARAM_ONE:
|
||||
if(i+1 != argc)
|
||||
if (i + 1 != argc)
|
||||
// there is >1 final parameter; it is an error
|
||||
bResult = false;
|
||||
break;
|
||||
|
@ -207,33 +198,28 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
|||
break;
|
||||
default:
|
||||
ASSERT(false);
|
||||
|
||||
}
|
||||
if(! bResult)
|
||||
if (!bResult)
|
||||
{
|
||||
throw eCmdLineBadParam( );
|
||||
throw eCmdLineBadParam();
|
||||
}
|
||||
|
||||
// ok, we can push the final parameter info onto the list...
|
||||
mArgData.push_back(cArgData(mLastArgInfo.mId));
|
||||
cArgData& curArg = mArgData.back();
|
||||
|
||||
while ( i < argc )
|
||||
while (i < argc)
|
||||
{
|
||||
if ( argv[i][0] == _T('-') )
|
||||
if (argv[i][0] == _T('-'))
|
||||
{
|
||||
if ( ! pCurArg )
|
||||
if (!pCurArg)
|
||||
{
|
||||
throw eCmdLineBadSwitchPos(
|
||||
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
|
||||
+ argv[i] );
|
||||
throw eCmdLineBadSwitchPos(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + argv[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// there was an extra parameter passed somewhere!
|
||||
throw eCmdLineBadArgParam(
|
||||
TSS_GetString( cCore, core::STR_ERR2_BAD_ARG_PARAMS )
|
||||
+ pCurArg );
|
||||
throw eCmdLineBadArgParam(TSS_GetString(cCore, core::STR_ERR2_BAD_ARG_PARAMS) + pCurArg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,21 +227,18 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
|||
curArg.mParams.push_back(TSTRING(argv[i]));
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// it is possible not to process the final command line parameters in the "else" case above
|
||||
// (this only occurs if there are no command line parameters specified) so let's make sure that
|
||||
// is consistent with what we are configured with...
|
||||
// NOTE -- it is ok to have no cmd line parameters if they specified PARAM_NONE or PARAM_MANY
|
||||
if(! bProcessedFinalParams)
|
||||
if (!bProcessedFinalParams)
|
||||
{
|
||||
if(mLastArgInfo.mNumParams == PARAM_ONE)
|
||||
if (mLastArgInfo.mNumParams == PARAM_ONE)
|
||||
{
|
||||
throw eCmdLineBadParam( );
|
||||
throw eCmdLineBadParam();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,28 +252,24 @@ void cCmdLineParser::Parse(int argc, const TCHAR *const * argv)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cCmdLineParser::TestMutEx()
|
||||
{
|
||||
std::list<std::pair<int,int> >::const_iterator i;
|
||||
std::list<std::pair<int, int> >::const_iterator i;
|
||||
cCmdLineIter iter1(*this), iter2(*this);
|
||||
for(i = mMutExList.begin(); i != mMutExList.end(); i++)
|
||||
for (i = mMutExList.begin(); i != mMutExList.end(); i++)
|
||||
{
|
||||
//TODO -- there is a much more efficent way to do this (using cFCOPropVector, for example)
|
||||
// the command line is presumably small enough, tho, that it probably isn't a big
|
||||
// deal to do it this way.
|
||||
iter1.SeekToArg(i->first);
|
||||
if(! iter1.Done())
|
||||
if (!iter1.Done())
|
||||
{
|
||||
iter2.SeekToArg(i->second);
|
||||
if(! iter2.Done())
|
||||
if (!iter2.Done())
|
||||
{
|
||||
// we have a mutual exclusion violation!
|
||||
throw eCmdLineMutEx(
|
||||
iter1.ActualParam()
|
||||
+ _T(", ")
|
||||
+ iter2.ActualParam() );
|
||||
throw eCmdLineMutEx(iter1.ActualParam() + _T(", ") + iter2.ActualParam());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -298,51 +277,51 @@ void cCmdLineParser::TestMutEx()
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cCmdLineParser::TestDependency()
|
||||
{
|
||||
std::list< std::pair< std::pair< int, int>, bool > >::const_iterator i;
|
||||
std::list<std::pair<std::pair<int, int>, bool> >::const_iterator i;
|
||||
cCmdLineIter iter1(*this), iter2(*this);
|
||||
|
||||
for( i = mDependencyList.begin(); i != mDependencyList.end(); ++i)
|
||||
for (i = mDependencyList.begin(); i != mDependencyList.end(); ++i)
|
||||
{
|
||||
iter1.SeekToArg( i->first.first );
|
||||
iter1.SeekToArg(i->first.first);
|
||||
// was it on the command line?
|
||||
if( !iter1.Done() )
|
||||
if (!iter1.Done())
|
||||
{
|
||||
// it was, is the corresponding arg on the command line?
|
||||
iter2.SeekToArg( i->first.second );
|
||||
if( iter2.Done() ) // it wasn't, dependency error
|
||||
iter2.SeekToArg(i->first.second);
|
||||
if (iter2.Done()) // it wasn't, dependency error
|
||||
{
|
||||
TSTRING arg1, arg2, alias1, alias2;
|
||||
cCmdLineParser::LookupArgInfo( i->first.first, arg1, alias1 );
|
||||
cCmdLineParser::LookupArgInfo( i->first.second, arg2, alias2 );
|
||||
cCmdLineParser::LookupArgInfo(i->first.first, arg1, alias1);
|
||||
cCmdLineParser::LookupArgInfo(i->first.second, arg2, alias2);
|
||||
|
||||
// determine in which form the user passed the arguments,
|
||||
// and construct the error message in the same form
|
||||
if ( iter1.ActualParam().length() == 2 )
|
||||
throw eCmdLineDependency( _T("The switch -") + arg1 + _T(" requires -") + arg2 +_T(".") );
|
||||
if (iter1.ActualParam().length() == 2)
|
||||
throw eCmdLineDependency(_T("The switch -") + arg1 + _T(" requires -") + arg2 + _T("."));
|
||||
else
|
||||
throw eCmdLineDependency( _T("The switch --") + alias1 + _T(" requires --") + alias2 + _T(".") );
|
||||
throw eCmdLineDependency(_T("The switch --") + alias1 + _T(" requires --") + alias2 + _T("."));
|
||||
}
|
||||
}
|
||||
else if( i->second )
|
||||
else if (i->second)
|
||||
// only make this second check if the dependencies are MUTUAL,
|
||||
// as indicated (or not) by the bool value.
|
||||
{
|
||||
iter2.SeekToArg( i->first.second );
|
||||
iter2.SeekToArg(i->first.second);
|
||||
// the first arg in the pair was not on the command line,
|
||||
// so just make sure the second isn't there...
|
||||
if( !iter2.Done() )
|
||||
if (!iter2.Done())
|
||||
{
|
||||
// arg2 appeared without arg1, so dependency error.
|
||||
TSTRING arg1, arg2, alias1, alias2;
|
||||
cCmdLineParser::LookupArgInfo( i->first.first, arg1, alias1 );
|
||||
cCmdLineParser::LookupArgInfo( i->first.second, arg2, alias2 );
|
||||
cCmdLineParser::LookupArgInfo(i->first.first, arg1, alias1);
|
||||
cCmdLineParser::LookupArgInfo(i->first.second, arg2, alias2);
|
||||
|
||||
// determine in which form the user passed the arguments,
|
||||
// and construct the error message in the same form
|
||||
if ( iter1.ActualParam().length() == 2 )
|
||||
throw eCmdLineDependency( _T("The switch -") + arg2 + _T(" requires -") + arg1 +_T(".") );
|
||||
if (iter1.ActualParam().length() == 2)
|
||||
throw eCmdLineDependency(_T("The switch -") + arg2 + _T(" requires -") + arg1 + _T("."));
|
||||
else
|
||||
throw eCmdLineDependency( _T("The switch --") + alias2 + _T(" requires --") + alias1 + _T(".") );
|
||||
throw eCmdLineDependency(_T("The switch --") + alias2 + _T(" requires --") + alias1 + _T("."));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,15 +343,15 @@ void cCmdLineParser::AddMutEx(int argId1, int argId2)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// AddDependency
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cCmdLineParser::AddDependency(int argId1, int argId2, bool mutual )
|
||||
void cCmdLineParser::AddDependency(int argId1, int argId2, bool mutual)
|
||||
{
|
||||
// again, no checking for duplicates... would a set
|
||||
// prove to be a better container for this operation?
|
||||
std::pair< int, int > Args( argId1, argId2 );
|
||||
std::pair< std::pair< int, int >, bool > Dep( Args, mutual );
|
||||
std::pair<int, int> Args(argId1, argId2);
|
||||
std::pair<std::pair<int, int>, bool> Dep(Args, mutual);
|
||||
|
||||
ASSERT(argId1 != argId2);
|
||||
mDependencyList.push_back( Dep);
|
||||
mDependencyList.push_back(Dep);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -382,14 +361,14 @@ void cCmdLineParser::AddDependency(int argId1, int argId2, bool mutual )
|
|||
void cCmdLineParser::TraceContents(int dl)
|
||||
{
|
||||
cDebug d("cCmdLineParser::TraceContents");
|
||||
if(dl == -1)
|
||||
if (dl == -1)
|
||||
dl = cDebug::D_DEBUG;
|
||||
|
||||
std::list<cArgData>::const_iterator i;
|
||||
for(i = mArgData.begin(); i != mArgData.end(); i++)
|
||||
for (i = mArgData.begin(); i != mArgData.end(); i++)
|
||||
{
|
||||
d.Trace(dl, "* Item id:%d\n", i->mId);
|
||||
for(std::vector<TSTRING>::const_iterator vi = i->mParams.begin(); vi != i->mParams.end(); vi++)
|
||||
for (std::vector<TSTRING>::const_iterator vi = i->mParams.begin(); vi != i->mParams.end(); vi++)
|
||||
{
|
||||
d.Trace(dl, "\t%s\n", vi->c_str());
|
||||
}
|
||||
|
@ -398,7 +377,7 @@ void cCmdLineParser::TraceContents(int dl)
|
|||
d.Trace(dl, "--- Switch id table ---\n");
|
||||
|
||||
cHashTableIter<TSTRING, cArgInfo> iter(mArgTable);
|
||||
for(iter.SeekBegin(); ! iter.Done(); iter.Next())
|
||||
for (iter.SeekBegin(); !iter.Done(); iter.Next())
|
||||
{
|
||||
d.Trace(dl, "[%d] %s\n", iter.Val().mId, iter.Key().c_str());
|
||||
}
|
||||
|
@ -416,12 +395,12 @@ bool cCmdLineParser::LookupArgInfo(int argId, TSTRING& arg, TSTRING& alias) cons
|
|||
alias = _T("");
|
||||
|
||||
cHashTableIter<TSTRING, cArgInfo> iter(mArgTable);
|
||||
for(iter.SeekBegin(); ! iter.Done(); iter.Next())
|
||||
for (iter.SeekBegin(); !iter.Done(); iter.Next())
|
||||
{
|
||||
if(iter.Val().mId == argId)
|
||||
if (iter.Val().mId == argId)
|
||||
{
|
||||
TSTRING str = iter.Key();
|
||||
if((str.length() > 0) && (str[0] == _T('-')))
|
||||
if ((str.length() > 0) && (str[0] == _T('-')))
|
||||
{
|
||||
// this is the alias!
|
||||
alias = (str.c_str() + 1);
|
||||
|
@ -433,7 +412,7 @@ bool cCmdLineParser::LookupArgInfo(int argId, TSTRING& arg, TSTRING& alias) cons
|
|||
}
|
||||
}
|
||||
}
|
||||
return ((! arg.empty()) || (! alias.empty()));
|
||||
return ((!arg.empty()) || (!alias.empty()));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -442,9 +421,9 @@ bool cCmdLineParser::LookupArgInfo(int argId, TSTRING& arg, TSTRING& alias) cons
|
|||
bool cCmdLineParser::ArgInList(int argId)
|
||||
{
|
||||
std::list<cArgData>::iterator i;
|
||||
for( i = mArgData.begin(); i != mArgData.end(); i++ )
|
||||
for (i = mArgData.begin(); i != mArgData.end(); i++)
|
||||
{
|
||||
if( i->mId == argId )
|
||||
if (i->mId == argId)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -460,13 +439,11 @@ bool cCmdLineParser::ArgInList(int argId)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
bool cCmdLineIter::SeekToArg(int argId) const
|
||||
{
|
||||
for(SeekBegin(); ! Done(); Next())
|
||||
for (SeekBegin(); !Done(); Next())
|
||||
{
|
||||
if(ArgId() == argId)
|
||||
if (ArgId() == argId)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -49,14 +49,15 @@
|
|||
//=============================================================================
|
||||
// eCmdLine
|
||||
//=============================================================================
|
||||
TSS_EXCEPTION( eCmdLine, eError )
|
||||
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( 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( eCmdLineMutEx, eCmdLine ) // a mutual exclusion error has occured
|
||||
TSS_EXCEPTION( eCmdLineDependency, eCmdLine ) // a dependency error has occurred.
|
||||
TSS_EXCEPTION( eCmdLineMultiArg, eCmdLine ) // an arg was found twice in the command line
|
||||
TSS_EXCEPTION(eCmdLine, eError)
|
||||
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(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(eCmdLineMutEx, eCmdLine) // a mutual exclusion error has occured
|
||||
TSS_EXCEPTION(eCmdLineDependency, eCmdLine) // a dependency error has occurred.
|
||||
TSS_EXCEPTION(eCmdLineMultiArg, eCmdLine) // an arg was found twice in the command line
|
||||
|
||||
|
||||
/*
|
||||
|
@ -102,7 +103,8 @@ public:
|
|||
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
|
||||
// command line.
|
||||
// argId -- a number that uniquely identifies the argument; no two arguments
|
||||
|
@ -119,29 +121,29 @@ public:
|
|||
// argId2 both exist on the command line, then the parse will fail and the error
|
||||
// value ERR_MUTUAL_EXCLUSION will be set.
|
||||
|
||||
void AddDependency(int argId1, int argId2, bool mutual = false );
|
||||
void AddDependency(int argId1, int argId2, bool mutual = false);
|
||||
// This adds a dependency constraint. When Parse() is called, if argId1
|
||||
// exists on the command line independent from argId2, then the parse will fail.
|
||||
// If the default param mutual is true, then the command parser will check for
|
||||
// argId1 if argId2 is passed. We do this, since it is possible for one arg to
|
||||
// depend on another, but have the other arg alone on the command line, legally.
|
||||
|
||||
void Parse(int argc, const TCHAR *const * argv); // throw eCmdLine
|
||||
void Parse(int argc, const TCHAR* const* argv); // throw eCmdLine
|
||||
// after AddArg() has been called for every argument that could be processed by the
|
||||
// command line, call this to tokenize argv. If the return value is false, then
|
||||
// the input was invalid in some way; the actual error can be determined by calling
|
||||
// GetErrorInfo() below.
|
||||
|
||||
// void Clear();
|
||||
// void Clear();
|
||||
// clear out all information that this class contains
|
||||
|
||||
bool LookupArgInfo(int argId, TSTRING& arg, TSTRING& alias) const;
|
||||
// given an argId, fill out the strings with the argument and alias strings. Returns false
|
||||
// if the argId cannot be found. This method is not very fast, so don't use it often.
|
||||
|
||||
#ifdef DEBUG
|
||||
void TraceContents(int dl = -1) ;
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
void TraceContents(int dl = -1);
|
||||
#endif
|
||||
private:
|
||||
void TestMutEx();
|
||||
// tests for mutual exclusion violations; if it fails, the current error is set and false
|
||||
|
@ -158,7 +160,9 @@ private:
|
|||
int mId;
|
||||
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
|
||||
struct cArgData
|
||||
|
@ -167,15 +171,18 @@ private:
|
|||
std::vector<TSTRING> mParams;
|
||||
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;
|
||||
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<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::set< int > mMultipleAllowed;
|
||||
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::set<int> mMultipleAllowed;
|
||||
|
||||
friend class cCmdLineIter;
|
||||
};
|
||||
|
@ -218,8 +225,7 @@ private:
|
|||
//#############################################################################
|
||||
// inline implementation
|
||||
//#############################################################################
|
||||
inline cCmdLineIter::cCmdLineIter(const cCmdLineParser& parser) :
|
||||
mList(parser.mArgData)
|
||||
inline cCmdLineIter::cCmdLineIter(const cCmdLineParser& parser) : mList(parser.mArgData)
|
||||
{
|
||||
SeekBegin();
|
||||
}
|
||||
|
@ -241,18 +247,18 @@ inline void cCmdLineIter::Next() const
|
|||
}
|
||||
inline int cCmdLineIter::ArgId() const
|
||||
{
|
||||
ASSERT(! Done());
|
||||
ASSERT(!Done());
|
||||
return mIter->mId;
|
||||
}
|
||||
inline int cCmdLineIter::NumParams() const
|
||||
{
|
||||
ASSERT(! Done());
|
||||
ASSERT(!Done());
|
||||
return mIter->mParams.size();
|
||||
}
|
||||
|
||||
inline const TSTRING& cCmdLineIter::ActualParam() const
|
||||
{
|
||||
ASSERT(! Done());
|
||||
ASSERT(!Done());
|
||||
return mIter->mActualParam;
|
||||
}
|
||||
|
||||
|
@ -264,4 +270,3 @@ inline const TSTRING& cCmdLineIter::ParamAt(int index) const
|
|||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -66,11 +66,11 @@
|
|||
|
||||
/// Exceptions
|
||||
|
||||
TSS_EXCEPTION( eConverter, eError );
|
||||
TSS_EXCEPTION( eConverterReset, eConverter );
|
||||
TSS_EXCEPTION( eConverterFatal, eConverter );
|
||||
TSS_EXCEPTION( eConverterUnsupportedConversion, eConverter );
|
||||
TSS_EXCEPTION( eConverterUnknownCodepage, eConverter );
|
||||
TSS_EXCEPTION(eConverter, eError);
|
||||
TSS_EXCEPTION(eConverterReset, eConverter);
|
||||
TSS_EXCEPTION(eConverterFatal, eConverter);
|
||||
TSS_EXCEPTION(eConverterUnsupportedConversion, eConverter);
|
||||
TSS_EXCEPTION(eConverterUnknownCodepage, eConverter);
|
||||
|
||||
|
||||
/// Classes
|
||||
|
@ -90,45 +90,38 @@ TSS_EXCEPTION( eConverterUnknownCodepage, eConverter );
|
|||
*/
|
||||
class iCodeConverter
|
||||
{
|
||||
public:
|
||||
|
||||
public:
|
||||
static iCodeConverter* GetInstance(); // Singleton
|
||||
static void Finit();
|
||||
|
||||
|
||||
|
||||
/// Subclass Responsibilities
|
||||
virtual
|
||||
int
|
||||
Convert(
|
||||
ntmbs_t, // NTMBS buffer
|
||||
virtual int Convert(ntmbs_t, // NTMBS buffer
|
||||
size_t, // Capacity in mbchar_t's (bytes)
|
||||
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
|
||||
|
||||
|
||||
virtual
|
||||
int
|
||||
Convert(
|
||||
ntdbs_t, // NTDBS (Null-terminated two byte sequence) buf
|
||||
virtual int Convert(ntdbs_t, // NTDBS (Null-terminated two byte sequence) buf
|
||||
size_t, // Capacity in dbchar_t's
|
||||
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
|
||||
|
||||
protected:
|
||||
|
||||
iCodeConverter() {}
|
||||
virtual ~iCodeConverter() {}
|
||||
|
||||
private:
|
||||
protected:
|
||||
iCodeConverter()
|
||||
{
|
||||
}
|
||||
virtual ~iCodeConverter()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
static iCodeConverter* CreateConverter();
|
||||
static iCodeConverter* CreateGoodEnoughConverter();
|
||||
|
||||
static iCodeConverter* m_pInst;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -139,41 +132,39 @@ class iCodeConverter
|
|||
#ifdef HAVE_ICONV_H
|
||||
#include <iconv.h>
|
||||
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
#ifndef __USE_XOPEN
|
||||
#define __USE_XOPEN 1
|
||||
#endif
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
# ifdef HAVE_LANGINFO_H
|
||||
# ifndef __USE_XOPEN
|
||||
# define __USE_XOPEN 1
|
||||
# endif
|
||||
# include <langinfo.h>
|
||||
# endif
|
||||
|
||||
class cIconvUtil
|
||||
{
|
||||
public:
|
||||
|
||||
public:
|
||||
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* GetMiddleIdentifier();
|
||||
static void ResetConverter( iconv_t );
|
||||
static bool TestConverter( const char* pTo, const char* pFrom );
|
||||
static iconv_t OpenHandle( const char* pTo, const char* pFrom ); // throws
|
||||
static void CloseHandle( iconv_t ic );
|
||||
static void ResetConverter(iconv_t);
|
||||
static bool TestConverter(const char* pTo, const char* pFrom);
|
||||
static iconv_t OpenHandle(const char* pTo, const char* pFrom); // throws
|
||||
static void CloseHandle(iconv_t ic);
|
||||
};
|
||||
|
||||
|
||||
class cIconvConverter : public iCodeConverter
|
||||
{
|
||||
public:
|
||||
|
||||
public:
|
||||
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( ntdbs_t, size_t, const_ntmbs_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);
|
||||
|
||||
cIconvConverter();
|
||||
virtual ~cIconvConverter();
|
||||
|
||||
private:
|
||||
private:
|
||||
void Init();
|
||||
|
||||
iconv_t icToDb;
|
||||
|
@ -182,18 +173,16 @@ class cIconvConverter : public iCodeConverter
|
|||
|
||||
class cDoubleIconvConverter : public iCodeConverter
|
||||
{
|
||||
public:
|
||||
|
||||
public:
|
||||
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( ntdbs_t, size_t, const_ntmbs_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);
|
||||
|
||||
cDoubleIconvConverter();
|
||||
virtual ~cDoubleIconvConverter();
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
||||
iconv_t icMbToUTF8;
|
||||
|
@ -220,10 +209,12 @@ class cDoubleIconvConverter : public iCodeConverter
|
|||
class cWcharIs32BitUcs2Converterer : public iCodeConverter
|
||||
{
|
||||
public:
|
||||
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(ntmbs_t, size_t, const_ntdbs_t, size_t);
|
||||
virtual int Convert(ntdbs_t, size_t, const_ntmbs_t, size_t);
|
||||
|
||||
virtual ~cWcharIs32BitUcs2Converterer() {}
|
||||
virtual ~cWcharIs32BitUcs2Converterer()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif // WCHAR_IS_32_BITS
|
||||
|
@ -240,10 +231,12 @@ public:
|
|||
class cWcharIs16BitUcs2Converterer : public iCodeConverter
|
||||
{
|
||||
public:
|
||||
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(ntmbs_t, size_t, const_ntdbs_t, size_t);
|
||||
virtual int Convert(ntdbs_t, size_t, const_ntmbs_t, size_t);
|
||||
|
||||
virtual ~cWcharIs16BitUcs2Converterer() {}
|
||||
virtual ~cWcharIs16BitUcs2Converterer()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif // WCHAR_IS_16_BITS
|
||||
|
@ -253,10 +246,12 @@ public:
|
|||
class cGoodEnoughConverterer : public iCodeConverter
|
||||
{
|
||||
public:
|
||||
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(ntmbs_t, size_t, const_ntdbs_t, size_t);
|
||||
virtual int Convert(ntdbs_t, size_t, const_ntmbs_t, size_t);
|
||||
|
||||
virtual ~cGoodEnoughConverterer() {}
|
||||
virtual ~cGoodEnoughConverterer()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -269,14 +264,14 @@ class cConvertUtil
|
|||
TSS_HIGH_ASCII_START = 0x0080u,
|
||||
TSS_HIGH_ASCII_END = 0x00FFu
|
||||
};
|
||||
public:
|
||||
static dbchar_t ConvertNonChar( mbchar_t ch );
|
||||
static mbchar_t ConvertNonChar( dbchar_t ch );
|
||||
|
||||
static bool ValueInReservedRange( mbchar_t ch );
|
||||
static bool ValueInReservedRange( dbchar_t ch );
|
||||
public:
|
||||
static dbchar_t ConvertNonChar(mbchar_t ch);
|
||||
static mbchar_t ConvertNonChar(dbchar_t ch);
|
||||
|
||||
static bool ValueInReservedRange(mbchar_t ch);
|
||||
static bool ValueInReservedRange(dbchar_t ch);
|
||||
};
|
||||
|
||||
|
||||
#endif //__CODECONVERT_H
|
||||
|
||||
|
|
|
@ -42,18 +42,18 @@
|
|||
#include "codeconvert.h" // for: iCodeConverter::GetInstance
|
||||
#include "twlocale.h" // for: cTWLocale::InitGlobalLocale
|
||||
|
||||
TSS_ImplementPackage( cCore )
|
||||
TSS_ImplementPackage(cCore)
|
||||
|
||||
cCore::cCore()
|
||||
{
|
||||
TSS_REGISTER_PKG_ERRORS( core );
|
||||
TSS_REGISTER_PKG_ERRORS(core);
|
||||
|
||||
// NOTE: Initialize code converter when cCore is a dependency
|
||||
// of another package (created on first call to GetInstance(),
|
||||
// forcing creation here to hasten the display of any errors)
|
||||
|
||||
cDebug::SetDebugLevel( cDebug::D_DEBUG );
|
||||
cDebug::AddOutTarget( cDebug::OUT_STDOUT );
|
||||
cDebug::SetDebugLevel(cDebug::D_DEBUG);
|
||||
cDebug::AddOutTarget(cDebug::OUT_STDOUT);
|
||||
|
||||
cTWLocale::InitGlobalLocale();
|
||||
|
||||
|
@ -64,4 +64,3 @@ cCore::~cCore()
|
|||
{
|
||||
iCodeConverter::Finit();
|
||||
}
|
||||
|
||||
|
|
|
@ -47,16 +47,14 @@
|
|||
|
||||
//--Classes
|
||||
|
||||
TSS_BeginPackage( cCore )
|
||||
TSS_BeginPackage(cCore)
|
||||
|
||||
TSS_DECLARE_STRINGTABLE;
|
||||
|
||||
public:
|
||||
public:
|
||||
cCore();
|
||||
~cCore();
|
||||
|
||||
cCore();
|
||||
~cCore();
|
||||
|
||||
TSS_EndPackage( cCore )
|
||||
TSS_EndPackage(cCore)
|
||||
|
||||
#endif //__CORE_H
|
||||
|
||||
|
|
|
@ -49,118 +49,118 @@
|
|||
#include "ntmbs.h"
|
||||
#include "displayencoder.h"
|
||||
|
||||
TSS_BEGIN_ERROR_REGISTRATION( core )
|
||||
TSS_BEGIN_ERROR_REGISTRATION(core)
|
||||
|
||||
/// Internal
|
||||
|
||||
TSS_REGISTER_ERROR( eInternal(), _T("Internal error.") )
|
||||
TSS_REGISTER_ERROR(eInternal(), _T("Internal error."))
|
||||
|
||||
|
||||
/// General
|
||||
|
||||
TSS_REGISTER_ERROR( eErrorGeneral(), _T("General Error") );
|
||||
TSS_REGISTER_ERROR( eOpen(), _T("File could not be opened.") );
|
||||
TSS_REGISTER_ERROR( eOpenRead(), _T("File could not be opened for reading.") );
|
||||
TSS_REGISTER_ERROR( eOpenWrite(), _T("File could not be opened for writing.") );
|
||||
TSS_REGISTER_ERROR( eBadModeSwitch(), _T("Unknown mode specified.") );
|
||||
TSS_REGISTER_ERROR( eBadCmdLine(), _T("Command line error.") );
|
||||
TSS_REGISTER_ERROR(eErrorGeneral(), _T("General Error"));
|
||||
TSS_REGISTER_ERROR(eOpen(), _T("File could not be opened."));
|
||||
TSS_REGISTER_ERROR(eOpenRead(), _T("File could not be opened for reading."));
|
||||
TSS_REGISTER_ERROR(eOpenWrite(), _T("File could not be opened for writing."));
|
||||
TSS_REGISTER_ERROR(eBadModeSwitch(), _T("Unknown mode specified."));
|
||||
TSS_REGISTER_ERROR(eBadCmdLine(), _T("Command line error."));
|
||||
|
||||
|
||||
/// Archive
|
||||
|
||||
TSS_REGISTER_ERROR( eArchive(), _T("Archive error.") )
|
||||
TSS_REGISTER_ERROR( eArchiveOpen(), _T("File could not be opened.") )
|
||||
TSS_REGISTER_ERROR( eArchiveWrite(), _T("File could not be written.") )
|
||||
TSS_REGISTER_ERROR( eArchiveRead(), _T("File could not be read.") )
|
||||
TSS_REGISTER_ERROR( eArchiveEOF(), _T("End of file reached.") )
|
||||
TSS_REGISTER_ERROR( eArchiveSeek(), _T("File seek failed.") )
|
||||
TSS_REGISTER_ERROR( eArchiveMemmap(), _T("Memory mapped archive file invalid.") )
|
||||
TSS_REGISTER_ERROR( eArchiveOutOfMem(), _T("Archive ran out of memory.") )
|
||||
TSS_REGISTER_ERROR( eArchiveInvalidOp(),_T("Archive logic error.") )
|
||||
TSS_REGISTER_ERROR( eArchiveFormat(), _T("Archive file format invalid.") )
|
||||
TSS_REGISTER_ERROR( eArchiveNotRegularFile(), _T("File is not a regular file.") )
|
||||
TSS_REGISTER_ERROR( eArchiveCrypto(), _T("File could not be decrypted.") )
|
||||
TSS_REGISTER_ERROR( eArchiveStringTooLong(), _T("String was too long.") )
|
||||
TSS_REGISTER_ERROR(eArchive(), _T("Archive error."))
|
||||
TSS_REGISTER_ERROR(eArchiveOpen(), _T("File could not be opened."))
|
||||
TSS_REGISTER_ERROR(eArchiveWrite(), _T("File could not be written."))
|
||||
TSS_REGISTER_ERROR(eArchiveRead(), _T("File could not be read."))
|
||||
TSS_REGISTER_ERROR(eArchiveEOF(), _T("End of file reached."))
|
||||
TSS_REGISTER_ERROR(eArchiveSeek(), _T("File seek failed."))
|
||||
TSS_REGISTER_ERROR(eArchiveMemmap(), _T("Memory mapped archive file invalid."))
|
||||
TSS_REGISTER_ERROR(eArchiveOutOfMem(), _T("Archive ran out of memory."))
|
||||
TSS_REGISTER_ERROR(eArchiveInvalidOp(), _T("Archive logic error."))
|
||||
TSS_REGISTER_ERROR(eArchiveFormat(), _T("Archive file format invalid."))
|
||||
TSS_REGISTER_ERROR(eArchiveNotRegularFile(), _T("File is not a regular file."))
|
||||
TSS_REGISTER_ERROR(eArchiveCrypto(), _T("File could not be decrypted."))
|
||||
TSS_REGISTER_ERROR(eArchiveStringTooLong(), _T("String was too long."))
|
||||
|
||||
|
||||
/// File
|
||||
|
||||
TSS_REGISTER_ERROR( eFile(), _T("File error.") )
|
||||
TSS_REGISTER_ERROR( eFileOpen(), _T("File could not be opened.") )
|
||||
TSS_REGISTER_ERROR( eFileWrite(), _T("File could not be written.") )
|
||||
TSS_REGISTER_ERROR( eFileRead(), _T("File could not be read.") )
|
||||
TSS_REGISTER_ERROR( eFileEOF(), _T("End of file reached.") )
|
||||
TSS_REGISTER_ERROR( eFileSeek(), _T("File seek failed.") )
|
||||
TSS_REGISTER_ERROR( eFileInvalidOp(), _T("File logic error.") )
|
||||
TSS_REGISTER_ERROR( eFileTrunc(), _T("File could not be truncated.") )
|
||||
TSS_REGISTER_ERROR( eFileClose(), _T("File could not be closed.") )
|
||||
TSS_REGISTER_ERROR( eFileFlush(), _T("File could not be flushed.") )
|
||||
TSS_REGISTER_ERROR( eFileRewind(), _T("File could not be rewound.") )
|
||||
TSS_REGISTER_ERROR(eFile(), _T("File error."))
|
||||
TSS_REGISTER_ERROR(eFileOpen(), _T("File could not be opened."))
|
||||
TSS_REGISTER_ERROR(eFileWrite(), _T("File could not be written."))
|
||||
TSS_REGISTER_ERROR(eFileRead(), _T("File could not be read."))
|
||||
TSS_REGISTER_ERROR(eFileEOF(), _T("End of file reached."))
|
||||
TSS_REGISTER_ERROR(eFileSeek(), _T("File seek failed."))
|
||||
TSS_REGISTER_ERROR(eFileInvalidOp(), _T("File logic error."))
|
||||
TSS_REGISTER_ERROR(eFileTrunc(), _T("File could not be truncated."))
|
||||
TSS_REGISTER_ERROR(eFileClose(), _T("File could not be closed."))
|
||||
TSS_REGISTER_ERROR(eFileFlush(), _T("File could not be flushed."))
|
||||
TSS_REGISTER_ERROR(eFileRewind(), _T("File could not be rewound."))
|
||||
|
||||
|
||||
/// General API failures
|
||||
TSS_REGISTER_ERROR(eUnix(), _T("Unix API failure.") )
|
||||
TSS_REGISTER_ERROR(eUnix(), _T("Unix API failure."))
|
||||
|
||||
|
||||
/// FSServices
|
||||
|
||||
TSS_REGISTER_ERROR( eFSServices(), _T("File system error.") )
|
||||
TSS_REGISTER_ERROR( eFSServicesGeneric(),_T("File system error.") )
|
||||
TSS_REGISTER_ERROR(eFSServices(), _T("File system error."))
|
||||
TSS_REGISTER_ERROR(eFSServicesGeneric(), _T("File system error."))
|
||||
|
||||
|
||||
/// Serializer
|
||||
|
||||
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( eSerializerOutputStreamFmt(), _T("Invalid output stream format.") )
|
||||
TSS_REGISTER_ERROR( eSerializerInputStremTypeArray(), _T("A bad index was encountered in file.") )
|
||||
TSS_REGISTER_ERROR( eSerializerArchive(), _T("File read encountered an archive error.") )
|
||||
TSS_REGISTER_ERROR( eSerializerVersionMismatch(), _T("File version mismatch.") )
|
||||
TSS_REGISTER_ERROR( eSerializerEncryption(), _T("File encryption error.") )
|
||||
TSS_REGISTER_ERROR( eSerializer(), _T("File format error.") )
|
||||
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(eSerializerOutputStreamFmt(), _T("Invalid output stream format."))
|
||||
TSS_REGISTER_ERROR(eSerializerInputStremTypeArray(), _T("A bad index was encountered in file."))
|
||||
TSS_REGISTER_ERROR(eSerializerArchive(), _T("File read encountered an archive error."))
|
||||
TSS_REGISTER_ERROR(eSerializerVersionMismatch(), _T("File version mismatch."))
|
||||
TSS_REGISTER_ERROR(eSerializerEncryption(), _T("File encryption error."))
|
||||
TSS_REGISTER_ERROR(eSerializer(), _T("File format error."))
|
||||
|
||||
|
||||
/// Command Line
|
||||
|
||||
TSS_REGISTER_ERROR( eCmdLine(), _T("Command line parsing error.") )
|
||||
TSS_REGISTER_ERROR( eCmdLineInvalidArg(), _T("Invalid argument passed on command line.") )
|
||||
TSS_REGISTER_ERROR( eCmdLineBadArgParam(), _T("Incorrect number of parameters to a command line argument.") )
|
||||
TSS_REGISTER_ERROR( eCmdLineBadParam(), _T("Incorrect number of parameters on command line.") )
|
||||
TSS_REGISTER_ERROR( eCmdLineBadSwitchPos(), _T("Switch appears after final command line parameter.") )
|
||||
TSS_REGISTER_ERROR( eCmdLineMutEx(), _T("Specified command line switches are mutually exclusive.") )
|
||||
TSS_REGISTER_ERROR( eCmdLineDependency(), _T("Command line parameter missing.") )
|
||||
TSS_REGISTER_ERROR( eCmdLineMultiArg(), _T("Command line argument specified more than once.") )
|
||||
TSS_REGISTER_ERROR(eCmdLine(), _T("Command line parsing error."))
|
||||
TSS_REGISTER_ERROR(eCmdLineInvalidArg(), _T("Invalid argument passed on command line."))
|
||||
TSS_REGISTER_ERROR(eCmdLineBadArgParam(), _T("Incorrect number of parameters to a command line argument."))
|
||||
TSS_REGISTER_ERROR(eCmdLineBadParam(), _T("Incorrect number of parameters on command line."))
|
||||
TSS_REGISTER_ERROR(eCmdLineBadSwitchPos(), _T("Switch appears after final command line parameter."))
|
||||
TSS_REGISTER_ERROR(eCmdLineMutEx(), _T("Specified command line switches are mutually exclusive."))
|
||||
TSS_REGISTER_ERROR(eCmdLineDependency(), _T("Command line parameter missing."))
|
||||
TSS_REGISTER_ERROR(eCmdLineMultiArg(), _T("Command line argument specified more than once."))
|
||||
|
||||
|
||||
/// TWLocale
|
||||
|
||||
TSS_REGISTER_ERROR( eTWLocale(), _T("Localization error.") )
|
||||
TSS_REGISTER_ERROR( eTWLocaleBadNumFormat(),_T("Bad number format.") )
|
||||
TSS_REGISTER_ERROR(eTWLocale(), _T("Localization error."))
|
||||
TSS_REGISTER_ERROR(eTWLocaleBadNumFormat(), _T("Bad number format."))
|
||||
|
||||
|
||||
/// Character Handling (defined in ntmbs.h)
|
||||
|
||||
TSS_REGISTER_ERROR( eCharacter(), _T("General Character Handling Error.") )
|
||||
TSS_REGISTER_ERROR( eCharacterEncoding(), _T("Character Encoding Error.") )
|
||||
TSS_REGISTER_ERROR(eCharacter(), _T("General Character Handling Error."))
|
||||
TSS_REGISTER_ERROR(eCharacterEncoding(), _T("Character Encoding Error."))
|
||||
|
||||
|
||||
/// Character Conversion Handling (defined in <codeconvert.h>)
|
||||
|
||||
TSS_REGISTER_ERROR( eConverter(), _T("General conversion error.") )
|
||||
TSS_REGISTER_ERROR( eConverterReset(), _T("Converter handle could not be reset.") )
|
||||
TSS_REGISTER_ERROR( eConverterFatal(), _T("Catastrophic conversion error.") )
|
||||
TSS_REGISTER_ERROR( eConverterUnsupportedConversion(), _T("Unsupported character conversion.") )
|
||||
TSS_REGISTER_ERROR( eConverterUnknownCodepage(), _T("Could not identify code page.") )
|
||||
TSS_REGISTER_ERROR(eConverter(), _T("General conversion error."))
|
||||
TSS_REGISTER_ERROR(eConverterReset(), _T("Converter handle could not be reset."))
|
||||
TSS_REGISTER_ERROR(eConverterFatal(), _T("Catastrophic conversion error."))
|
||||
TSS_REGISTER_ERROR(eConverterUnsupportedConversion(), _T("Unsupported character conversion."))
|
||||
TSS_REGISTER_ERROR(eConverterUnknownCodepage(), _T("Could not identify code page."))
|
||||
|
||||
//
|
||||
// Display Encoder
|
||||
//
|
||||
|
||||
TSS_REGISTER_ERROR( eEncoder(), _T("Display encoder error.") )
|
||||
TSS_REGISTER_ERROR( eBadDecoderInput(), _T("Bad input to display encoder.") )
|
||||
TSS_REGISTER_ERROR( eBadHexConversion(), _T("Bad hex conversion in display encoder.") )
|
||||
TSS_REGISTER_ERROR( eUnknownEscapeEncoding(), _T("Unknown encoding in display encoder input.") )
|
||||
TSS_REGISTER_ERROR(eEncoder(), _T("Display encoder error."))
|
||||
TSS_REGISTER_ERROR(eBadDecoderInput(), _T("Bad input to display encoder."))
|
||||
TSS_REGISTER_ERROR(eBadHexConversion(), _T("Bad hex conversion in display encoder."))
|
||||
TSS_REGISTER_ERROR(eUnknownEscapeEncoding(), _T("Unknown encoding in display encoder input."))
|
||||
|
||||
|
||||
TSS_END_ERROR_REGISTRATION()
|
||||
|
||||
|
|
|
@ -41,8 +41,7 @@
|
|||
|
||||
#include "core/errortable.h"
|
||||
|
||||
TSS_DECLARE_ERROR_REGISTRATION( core )
|
||||
TSS_DECLARE_ERROR_REGISTRATION(core)
|
||||
|
||||
|
||||
#endif//__COREERRORS_H
|
||||
|
||||
#endif //__COREERRORS_H
|
||||
|
|
|
@ -39,35 +39,31 @@
|
|||
#include "corestrings.h" // for: cCore and core::STR_IDS
|
||||
|
||||
|
||||
TSS_BeginStringtable( cCore )
|
||||
TSS_BeginStringtable(cCore)
|
||||
|
||||
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_ERROR_ERROR, _T("### Error") ),
|
||||
TSS_StringEntry( core::STR_ERROR_WARNING, _T("### Warning") ),
|
||||
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_CONTINUING, _T("Continuing...") ),
|
||||
TSS_StringEntry( core::STR_ERR2_FILENAME, _T("Filename: ") ),
|
||||
TSS_StringEntry( core::STR_ERROR_FILENAME, _T("Filename: ") ),
|
||||
TSS_StringEntry( core::STR_UNKNOWN, _T("Unknown") ),
|
||||
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_NEWLINE, _T("\n") ),
|
||||
TSS_StringEntry( core::STR_MEMARCHIVE_FILENAME, _T("Error occured in internal memory file") ),
|
||||
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_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_ERR2_ARCH_CRYPTO_ERR, _T("File could not be decrypted.")),
|
||||
TSS_StringEntry(core::STR_ERR2_BAD_ARG_PARAMS, _T("Argument: ")),
|
||||
TSS_StringEntry(core::STR_ERROR_ERROR, _T("### Error")),
|
||||
TSS_StringEntry(core::STR_ERROR_WARNING, _T("### Warning")), 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_CONTINUING, _T("Continuing...")),
|
||||
TSS_StringEntry(core::STR_ERR2_FILENAME, _T("Filename: ")),
|
||||
TSS_StringEntry(core::STR_ERROR_FILENAME, _T("Filename: ")), TSS_StringEntry(core::STR_UNKNOWN, _T("Unknown")),
|
||||
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_NEWLINE, _T("\n")),
|
||||
TSS_StringEntry(core::STR_MEMARCHIVE_FILENAME, _T("Error occured in internal memory file")),
|
||||
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_UNKNOWN_TIME, _T("Unknown time")),
|
||||
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
|
||||
|
||||
TSS_StringEntry( core::STR_ERR_ISNULL, _T("Argument cannot be null.") ),
|
||||
TSS_StringEntry( core::STR_ERR_OVERFLOW, _T("An overflow has been detected.") ),
|
||||
TSS_StringEntry( core::STR_ERR_UNDERFLOW, _T("An underflow has been detected.") ),
|
||||
TSS_StringEntry( core::STR_ERR_BADCHAR, _T("Input contained an invalid character.") )
|
||||
|
||||
TSS_EndStringtable( cCore )
|
||||
|
||||
|
||||
TSS_StringEntry(core::STR_ERR_ISNULL, _T("Argument cannot be null.")),
|
||||
TSS_StringEntry(core::STR_ERR_OVERFLOW, _T("An overflow has been detected.")),
|
||||
TSS_StringEntry(core::STR_ERR_UNDERFLOW, _T("An underflow has been detected.")),
|
||||
TSS_StringEntry(core::STR_ERR_BADCHAR, _T("Input contained an invalid character."))
|
||||
|
||||
TSS_EndStringtable(cCore)
|
||||
|
|
|
@ -45,37 +45,19 @@
|
|||
|
||||
//--Message Keys
|
||||
|
||||
TSS_BeginStringIds( core )
|
||||
TSS_BeginStringIds(core)
|
||||
|
||||
STR_ERR2_ARCH_CRYPTO_ERR,
|
||||
STR_ERR2_BAD_ARG_PARAMS,
|
||||
STR_ERROR_ERROR,
|
||||
STR_ERROR_WARNING,
|
||||
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,
|
||||
STR_ERR2_BAD_ARG_PARAMS, STR_ERROR_ERROR, STR_ERROR_WARNING, 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
|
||||
|
||||
STR_ERR_ISNULL,
|
||||
STR_ERR_OVERFLOW,
|
||||
STR_ERR_UNDERFLOW,
|
||||
STR_ERR_ISNULL, STR_ERR_OVERFLOW, STR_ERR_UNDERFLOW,
|
||||
STR_ERR_BADCHAR
|
||||
|
||||
TSS_EndStringIds( core )
|
||||
TSS_EndStringIds(core)
|
||||
|
||||
|
||||
#endif //__CORESTRINGS_H
|
||||
|
||||
|
|
|
@ -37,9 +37,9 @@
|
|||
|
||||
#ifdef DEBUG
|
||||
|
||||
#ifndef va_start
|
||||
#include <cstdarg>
|
||||
#endif
|
||||
# ifndef va_start
|
||||
# include <cstdarg>
|
||||
# endif
|
||||
#include <cwchar>
|
||||
#include <fstream>
|
||||
#include <cstdio>
|
||||
|
@ -47,7 +47,7 @@
|
|||
int cDebug::mDebugLevel(10);
|
||||
uint32 cDebug::mOutMask(cDebug::OUT_TRACE);
|
||||
std::ofstream cDebug::logfile;
|
||||
//mDebugLevel default == 10, mOutMask default == OUT_TRACE.
|
||||
//mDebugLevel default == 10, mOutMask default == OUT_TRACE.
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Constructors and Destructor
|
||||
|
@ -61,14 +61,14 @@ cDebug::cDebug(const char* label)
|
|||
mLabel[cnt] = '\0';
|
||||
}
|
||||
|
||||
cDebug::cDebug(const cDebug &rhs)
|
||||
cDebug::cDebug(const cDebug& rhs)
|
||||
{
|
||||
strncpy(mLabel, rhs.mLabel, MAX_LABEL);
|
||||
}
|
||||
|
||||
cDebug::~cDebug()
|
||||
{
|
||||
if(logfile)
|
||||
if (logfile)
|
||||
logfile.close();
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -86,7 +86,6 @@ void cDebug::Trace(int levelNum, const char* format, ...)
|
|||
va_start(args, format);
|
||||
DoTrace(format, args);
|
||||
va_end(args);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -96,7 +95,7 @@ void cDebug::Trace(int levelNum, const char* format, ...)
|
|||
// console, etc...
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void cDebug::DoTrace(const char *format, va_list &args)
|
||||
void cDebug::DoTrace(const char* format, va_list& args)
|
||||
{
|
||||
size_t guard1 = 0xBABABABA;
|
||||
char out[2048];
|
||||
|
@ -135,14 +134,14 @@ void cDebug::DoTrace(const char *format, va_list &args)
|
|||
logfile.flush();
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
# ifdef DEBUG
|
||||
|
||||
//
|
||||
// wrappers around Trace() that requires less typing
|
||||
// TODO: this is quick and dirty, but lets me check in all these files right away. --ghk
|
||||
//
|
||||
|
||||
void cDebug::TraceAlways(const char *format, ...)
|
||||
void cDebug::TraceAlways(const char* format, ...)
|
||||
{
|
||||
if (D_ALWAYS > mDebugLevel)
|
||||
return;
|
||||
|
@ -154,7 +153,7 @@ void cDebug::TraceAlways(const char *format, ...)
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
void cDebug::TraceError(const char *format, ...)
|
||||
void cDebug::TraceError(const char* format, ...)
|
||||
{
|
||||
if (D_ERROR > mDebugLevel)
|
||||
return;
|
||||
|
@ -166,7 +165,7 @@ void cDebug::TraceError(const char *format, ...)
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
void cDebug::TraceWarning(const char *format, ...)
|
||||
void cDebug::TraceWarning(const char* format, ...)
|
||||
{
|
||||
if (D_WARNING > mDebugLevel)
|
||||
return;
|
||||
|
@ -178,7 +177,7 @@ void cDebug::TraceWarning(const char *format, ...)
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
void cDebug::TraceDebug(const char *format, ...)
|
||||
void cDebug::TraceDebug(const char* format, ...)
|
||||
{
|
||||
if (D_DEBUG > mDebugLevel)
|
||||
return;
|
||||
|
@ -190,7 +189,7 @@ void cDebug::TraceDebug(const char *format, ...)
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
void cDebug::TraceDetail(const char *format, ...)
|
||||
void cDebug::TraceDetail(const char* format, ...)
|
||||
{
|
||||
if (D_DETAIL > mDebugLevel)
|
||||
return;
|
||||
|
@ -202,7 +201,7 @@ void cDebug::TraceDetail(const char *format, ...)
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
void cDebug::TraceNever(const char *format, ...)
|
||||
void cDebug::TraceNever(const char* format, ...)
|
||||
{
|
||||
if (D_NEVER > mDebugLevel)
|
||||
return;
|
||||
|
@ -214,12 +213,12 @@ void cDebug::TraceNever(const char *format, ...)
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
void cDebug::TraceVaArgs( int iDebugLevel, const char *format, va_list &args )
|
||||
void cDebug::TraceVaArgs(int iDebugLevel, const char* format, va_list& args)
|
||||
{
|
||||
if ( iDebugLevel <= mDebugLevel )
|
||||
DoTrace( format, args);
|
||||
if (iDebugLevel <= mDebugLevel)
|
||||
DoTrace(format, args);
|
||||
}
|
||||
#endif // DEBUG
|
||||
# endif // DEBUG
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// AddOutTarget -- Attempts to add a new target for trace/debug output.
|
||||
|
@ -231,7 +230,8 @@ bool cDebug::AddOutTarget(OutTarget target)
|
|||
mOutMask |= OUT_STDOUT;
|
||||
if (target == OUT_TRACE)
|
||||
mOutMask |= OUT_TRACE;
|
||||
if (target == OUT_FILE) {
|
||||
if (target == OUT_FILE)
|
||||
{
|
||||
mOutMask |= OUT_FILE;
|
||||
return false;
|
||||
}
|
||||
|
@ -286,10 +286,12 @@ bool cDebug::SetOutputFile(const char* filename)
|
|||
//make sure info. will not be clobbered.
|
||||
|
||||
//Should be open now- if not, abort.
|
||||
if (!logfile) {
|
||||
if (!logfile)
|
||||
{
|
||||
mOutMask ^= OUT_FILE;
|
||||
return false;
|
||||
} else
|
||||
}
|
||||
else
|
||||
mOutMask |= OUT_FILE;
|
||||
return true;
|
||||
}
|
||||
|
@ -298,7 +300,7 @@ bool cDebug::SetOutputFile(const char* filename)
|
|||
// DebugOut -- Works just like TRACE. note: there is an internal buffer size
|
||||
// of 1024; traces larger than that will have unpredictable results.
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void cDebug::DebugOut( const char* lpOutputString, ... )
|
||||
void cDebug::DebugOut(const char* lpOutputString, ...)
|
||||
{
|
||||
char buf[2048];
|
||||
// create the output buffer
|
||||
|
@ -307,9 +309,9 @@ void cDebug::DebugOut( const char* lpOutputString, ... )
|
|||
vsnprintf(buf, 2048, lpOutputString, args);
|
||||
va_end(args);
|
||||
|
||||
#ifdef DEBUG
|
||||
# ifdef DEBUG
|
||||
TCERR << buf;
|
||||
#endif //_DEBUG
|
||||
# endif //_DEBUG
|
||||
|
||||
TCOUT.flush();
|
||||
}
|
||||
|
@ -318,4 +320,3 @@ void cDebug::DebugOut( const char* lpOutputString, ... )
|
|||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// ASSERT macro support function
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
151
src/core/debug.h
151
src/core/debug.h
|
@ -40,15 +40,13 @@
|
|||
#include <assert.h>
|
||||
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
/* Do it in this order, because autoconf checks for <stdarg.h>
|
||||
* first i.e. if HAVE_VARARGS_H is defined, it is only because
|
||||
* <stdarg.h> couldn't be found.
|
||||
*/
|
||||
#ifdef HAVE_VARARGS_H
|
||||
# include <varargs.h>
|
||||
#include <varargs.h>
|
||||
#else
|
||||
# ifdef HAVE_STDARG_H
|
||||
# include <stdarg.h>
|
||||
|
@ -107,17 +105,17 @@ public:
|
|||
// The wide character overloads of these functions will expect wide strings
|
||||
// for %s options.
|
||||
//
|
||||
void TraceAlways (const char *format, ...);
|
||||
void TraceError (const char *format, ...);
|
||||
void TraceWarning (const char *format, ...);
|
||||
void TraceDebug (const char *format, ...);
|
||||
void TraceDetail (const char *format, ...);
|
||||
void TraceNever (const char *format, ...);
|
||||
void TraceAlways(const char* format, ...);
|
||||
void TraceError(const char* format, ...);
|
||||
void TraceWarning(const char* format, ...);
|
||||
void TraceDebug(const char* format, ...);
|
||||
void TraceDetail(const char* format, ...);
|
||||
void TraceNever(const char* format, ...);
|
||||
|
||||
|
||||
// these are of use if you are inside a function with a "..." as an argument
|
||||
// and you want to trace those args
|
||||
void TraceVaArgs (int iDebugLevel, const char *format, va_list &args);
|
||||
void TraceVaArgs(int iDebugLevel, const char* format, va_list& args);
|
||||
|
||||
// ...but you can still choose to use this interface...
|
||||
|
||||
|
@ -125,26 +123,28 @@ public:
|
|||
// Outputs based on levelnum. If levelnum <= global debug, print.
|
||||
|
||||
public:
|
||||
|
||||
static bool AddOutTarget (OutTarget target);
|
||||
static bool RemoveOutTarget (OutTarget target);
|
||||
static bool AddOutTarget(OutTarget target);
|
||||
static bool RemoveOutTarget(OutTarget target);
|
||||
// used to specify the out target....
|
||||
static bool HasOutTarget (OutTarget target);
|
||||
static bool HasOutTarget(OutTarget target);
|
||||
|
||||
static bool SetOutputFile (const char* filename);
|
||||
static bool SetOutputFile(const char* filename);
|
||||
// specifies the output file name used when OUT_FILE is set
|
||||
static void SetDebugLevel (int level);
|
||||
static int GetDebugLevel (void);
|
||||
static void SetDebugLevel(int level);
|
||||
static int GetDebugLevel(void);
|
||||
// gets and sets the global debug level. Trace output at or below this
|
||||
// level will be output.
|
||||
|
||||
static void DebugOut ( const char* lpOutputString, ... );
|
||||
static void DebugOut(const char* lpOutputString, ...);
|
||||
// Works just like TRACE
|
||||
// note: there is an internal buffer size of 1024; traces larger
|
||||
// than that will have unpredictable and probably bad results
|
||||
private:
|
||||
#ifdef DEBUG
|
||||
enum { MAX_LABEL = 128 };
|
||||
enum
|
||||
{
|
||||
MAX_LABEL = 128
|
||||
};
|
||||
|
||||
static int mDebugLevel;
|
||||
static uint32 mOutMask;
|
||||
|
@ -152,14 +152,14 @@ private:
|
|||
char mLabel[MAX_LABEL];
|
||||
|
||||
// helper functions
|
||||
void DoTrace(const char *format, va_list &args);
|
||||
void DoTrace(const char* format, va_list& args);
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef DEBUG
|
||||
#define TRACE cDebug::DebugOut
|
||||
# define TRACE cDebug::DebugOut
|
||||
#else
|
||||
#define TRACE 1 ? (void)0 : cDebug::DebugOut
|
||||
# define TRACE 1 ? (void)0 : cDebug::DebugOut
|
||||
#endif // DEBUG
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -179,51 +179,90 @@ inline int cDebug::GetDebugLevel()
|
|||
return mDebugLevel;
|
||||
}
|
||||
|
||||
#else // DEBUG
|
||||
# else // DEBUG
|
||||
|
||||
inline cDebug::cDebug (const char *) {}
|
||||
inline cDebug::~cDebug () {}
|
||||
inline cDebug::cDebug (const cDebug&) {}
|
||||
inline void cDebug::TraceAlways (const char *, ...) {}
|
||||
inline void cDebug::TraceError (const char *, ...) {}
|
||||
inline void cDebug::TraceWarning (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
|
||||
inline cDebug::cDebug(const char*)
|
||||
{
|
||||
}
|
||||
inline cDebug::~cDebug()
|
||||
{
|
||||
}
|
||||
inline cDebug::cDebug(const cDebug&)
|
||||
{
|
||||
}
|
||||
inline void cDebug::TraceAlways(const char*, ...)
|
||||
{
|
||||
}
|
||||
inline void cDebug::TraceError(const char*, ...)
|
||||
{
|
||||
}
|
||||
inline void cDebug::TraceWarning(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
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// ASSERT macro
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define ASSERTMSG( exp, s ) assert( (exp) != 0 )
|
||||
#define ASSERT( exp ) assert( (exp) != 0 )
|
||||
# define ASSERTMSG(exp, s) assert((exp) != 0)
|
||||
# define ASSERT(exp) assert((exp) != 0)
|
||||
// if we are not windows we will just use the standard assert()
|
||||
#define TSS_DebugBreak() ASSERT( false );
|
||||
# define TSS_DebugBreak() ASSERT(false);
|
||||
|
||||
#ifndef ASSERT
|
||||
#error ASSERT did not get defined!!!
|
||||
#endif
|
||||
# ifndef ASSERT
|
||||
# error ASSERT did not get defined!!!
|
||||
# endif
|
||||
|
||||
#ifndef ASSERTMSG
|
||||
#error ASSERTMSG did not get defined!!!
|
||||
#endif
|
||||
# ifndef ASSERTMSG
|
||||
# error ASSERTMSG did not get defined!!!
|
||||
# endif
|
||||
|
||||
#ifndef TSS_DebugBreak
|
||||
#error TSS_DebugBreak did not get defined!!!
|
||||
#endif
|
||||
# ifndef TSS_DebugBreak
|
||||
# error TSS_DebugBreak did not get defined!!!
|
||||
# endif
|
||||
|
||||
#endif //__DEBUG_H
|
||||
|
||||
|
|
|
@ -66,10 +66,9 @@
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
inline bool IsSingleTCHAR( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last )
|
||||
inline bool IsSingleTCHAR(TSTRING::const_iterator first, TSTRING::const_iterator last)
|
||||
{
|
||||
return( first + 1 == last );
|
||||
return (first + 1 == last);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -80,26 +79,22 @@ inline bool IsSingleTCHAR( TSTRING::const_iterator first,
|
|||
|
||||
class iCharEncoder
|
||||
{
|
||||
public:
|
||||
virtual ~iCharEncoder() {};
|
||||
public:
|
||||
virtual ~iCharEncoder(){};
|
||||
|
||||
virtual bool NeedsEncoding( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const = 0;
|
||||
virtual bool NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const = 0;
|
||||
// Determines if character identified by [first,last) needs encoding.
|
||||
// Returns true if it does.
|
||||
|
||||
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const = 0;
|
||||
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const = 0;
|
||||
// Encodes character identified by [first,last) in such a way that it
|
||||
// can be decoded by Decode(). Returns encoded character sequence.
|
||||
|
||||
virtual TSTRING EncodePretty( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const = 0;
|
||||
virtual TSTRING EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const = 0;
|
||||
// Encodes character identified by [first,last) in a manner that is not roundtrip,
|
||||
// but looks good. Returns encoded character sequence.
|
||||
|
||||
virtual TSTRING Decode( TSTRING::const_iterator* pcur,
|
||||
const TSTRING::const_iterator end ) const = 0;
|
||||
virtual TSTRING Decode(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end) const = 0;
|
||||
// Decodes character sequence beginning with '*pcur' and ending before 'end'.
|
||||
// Returns decoded character or sequence of characters. Advances *pcur beyond
|
||||
// the last character decoded.
|
||||
|
@ -107,33 +102,34 @@ class iCharEncoder
|
|||
|
||||
virtual TCHAR Identifier() const = 0;
|
||||
|
||||
static TCHAR EscapeChar() { return char_escape; }
|
||||
|
||||
protected:
|
||||
static TCHAR EscapeChar()
|
||||
{
|
||||
return char_escape;
|
||||
}
|
||||
|
||||
protected:
|
||||
static TCHAR char_escape;
|
||||
};
|
||||
|
||||
|
||||
class cNonNarrowableCharEncoder : public iCharEncoder
|
||||
{
|
||||
public:
|
||||
virtual ~cNonNarrowableCharEncoder() {}
|
||||
public:
|
||||
virtual ~cNonNarrowableCharEncoder()
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool NeedsEncoding( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const;
|
||||
virtual bool NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
|
||||
|
||||
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const;
|
||||
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
|
||||
|
||||
virtual TSTRING EncodePretty( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const;
|
||||
virtual TSTRING EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
|
||||
|
||||
virtual TSTRING Decode( TSTRING::const_iterator* cur,
|
||||
const TSTRING::const_iterator end ) const;
|
||||
virtual TSTRING Decode(TSTRING::const_iterator* cur, const TSTRING::const_iterator end) const;
|
||||
|
||||
virtual TCHAR Identifier() const;
|
||||
private:
|
||||
|
||||
private:
|
||||
static TCHAR char_identifier;
|
||||
static TCHAR char_replace;
|
||||
};
|
||||
|
@ -141,26 +137,24 @@ class cNonNarrowableCharEncoder : public iCharEncoder
|
|||
|
||||
class cNonPrintableCharEncoder : public iCharEncoder
|
||||
{
|
||||
public:
|
||||
cNonPrintableCharEncoder( bool f_allowWS )
|
||||
: m_allowWS( f_allowWS ) {};
|
||||
public:
|
||||
cNonPrintableCharEncoder(bool f_allowWS) : m_allowWS(f_allowWS){};
|
||||
|
||||
virtual ~cNonPrintableCharEncoder() {}
|
||||
virtual ~cNonPrintableCharEncoder()
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool NeedsEncoding( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const;
|
||||
virtual bool NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
|
||||
|
||||
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const;
|
||||
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
|
||||
|
||||
virtual TSTRING EncodePretty( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const;
|
||||
virtual TSTRING EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
|
||||
|
||||
virtual TSTRING Decode( TSTRING::const_iterator* cur,
|
||||
const TSTRING::const_iterator end ) const;
|
||||
virtual TSTRING Decode(TSTRING::const_iterator* cur, const TSTRING::const_iterator end) const;
|
||||
|
||||
virtual TCHAR Identifier() const;
|
||||
private:
|
||||
|
||||
private:
|
||||
static TCHAR char_identifier;
|
||||
static TCHAR char_replace;
|
||||
|
||||
|
@ -169,23 +163,22 @@ class cNonPrintableCharEncoder : public iCharEncoder
|
|||
|
||||
class cQuoteCharEncoder : public iCharEncoder
|
||||
{
|
||||
public:
|
||||
virtual ~cQuoteCharEncoder() {}
|
||||
public:
|
||||
virtual ~cQuoteCharEncoder()
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool NeedsEncoding( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const;
|
||||
virtual bool NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
|
||||
|
||||
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const;
|
||||
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
|
||||
|
||||
virtual TSTRING EncodePretty( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const;
|
||||
virtual TSTRING EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
|
||||
|
||||
virtual TSTRING Decode( TSTRING::const_iterator* cur,
|
||||
const TSTRING::const_iterator end ) const;
|
||||
virtual TSTRING Decode(TSTRING::const_iterator* cur, const TSTRING::const_iterator end) const;
|
||||
|
||||
virtual TCHAR Identifier() const;
|
||||
private:
|
||||
|
||||
private:
|
||||
static TCHAR char_test;
|
||||
static TCHAR char_identifier;
|
||||
static TCHAR char_replace;
|
||||
|
@ -194,23 +187,22 @@ class cQuoteCharEncoder : public iCharEncoder
|
|||
|
||||
class cBackslashCharEncoder : public iCharEncoder
|
||||
{
|
||||
public:
|
||||
virtual ~cBackslashCharEncoder() {}
|
||||
public:
|
||||
virtual ~cBackslashCharEncoder()
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool NeedsEncoding( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const;
|
||||
virtual bool NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
|
||||
|
||||
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const;
|
||||
virtual TSTRING EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
|
||||
|
||||
virtual TSTRING EncodePretty( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const;
|
||||
virtual TSTRING EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const;
|
||||
|
||||
virtual TSTRING Decode( TSTRING::const_iterator* cur,
|
||||
const TSTRING::const_iterator end ) const;
|
||||
virtual TSTRING Decode(TSTRING::const_iterator* cur, const TSTRING::const_iterator end) const;
|
||||
|
||||
virtual TCHAR Identifier() const;
|
||||
private:
|
||||
|
||||
private:
|
||||
static TCHAR char_test;
|
||||
static TCHAR char_identifier;
|
||||
static TCHAR char_replace;
|
||||
|
@ -241,18 +233,13 @@ TCHAR cNonPrintableCharEncoder::char_replace = _T('?');
|
|||
// TESTS
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool cNonNarrowableCharEncoder::NeedsEncoding(
|
||||
TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const
|
||||
bool cNonNarrowableCharEncoder::NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const
|
||||
{
|
||||
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
|
||||
// std::isprint<wchar_t> does a wctob() on the wchar!!?!?!
|
||||
|
@ -275,35 +262,23 @@ bool cNonPrintableCharEncoder::NeedsEncoding(
|
|||
//
|
||||
|
||||
// assuming all unprintable chars are one TCHAR long
|
||||
if( ! IsSingleTCHAR( first, last ) )
|
||||
if (!IsSingleTCHAR(first, last))
|
||||
return false;
|
||||
|
||||
if( m_allowWS && cCharEncoderUtil::IsWhiteSpace( *first ) )
|
||||
if (m_allowWS && cCharEncoderUtil::IsWhiteSpace(*first))
|
||||
return false;
|
||||
|
||||
return cCharEncoderUtil::IsPrintable( *first );
|
||||
return cCharEncoderUtil::IsPrintable(*first);
|
||||
}
|
||||
|
||||
bool cQuoteCharEncoder::NeedsEncoding(
|
||||
TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const
|
||||
bool cQuoteCharEncoder::NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const
|
||||
{
|
||||
return(
|
||||
IsSingleTCHAR( first, last )
|
||||
&&
|
||||
( *first == char_test )
|
||||
);
|
||||
return (IsSingleTCHAR(first, last) && (*first == char_test));
|
||||
}
|
||||
|
||||
bool cBackslashCharEncoder::NeedsEncoding(
|
||||
TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const
|
||||
bool cBackslashCharEncoder::NeedsEncoding(TSTRING::const_iterator first, TSTRING::const_iterator last) const
|
||||
{
|
||||
return(
|
||||
IsSingleTCHAR( first, last )
|
||||
&&
|
||||
( *first == char_test )
|
||||
);
|
||||
return (IsSingleTCHAR(first, last) && (*first == char_test));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -311,43 +286,37 @@ bool cBackslashCharEncoder::NeedsEncoding(
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
TSTRING cNonNarrowableCharEncoder::EncodeRoundtrip(
|
||||
TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const
|
||||
TSTRING cNonNarrowableCharEncoder::EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const
|
||||
{
|
||||
TSTRING str;
|
||||
|
||||
str += char_escape;
|
||||
str += char_identifier;
|
||||
str += cCharEncoderUtil::CharStringToHexValue( TSTRING( first, last ) );
|
||||
str += cCharEncoderUtil::CharStringToHexValue(TSTRING(first, last));
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
TSTRING cNonPrintableCharEncoder::EncodeRoundtrip(
|
||||
TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const
|
||||
TSTRING cNonPrintableCharEncoder::EncodeRoundtrip(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)
|
||||
|
||||
TSTRING str;
|
||||
|
||||
str += char_escape;
|
||||
str += char_identifier;
|
||||
str += cCharEncoderUtil::CharStringToHexValue( TSTRING( first, last ) );
|
||||
str += cCharEncoderUtil::CharStringToHexValue(TSTRING(first, last));
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
TSTRING cQuoteCharEncoder::EncodeRoundtrip(
|
||||
TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const
|
||||
TSTRING cQuoteCharEncoder::EncodeRoundtrip(TSTRING::const_iterator first, TSTRING::const_iterator last) const
|
||||
{
|
||||
// should just be a quote
|
||||
ASSERT( IsSingleTCHAR( first, last ) );
|
||||
ASSERT( *first == char_test );
|
||||
ASSERT(IsSingleTCHAR(first, last));
|
||||
ASSERT(*first == char_test);
|
||||
|
||||
TSTRING str;
|
||||
|
||||
|
@ -358,14 +327,11 @@ 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
|
||||
ASSERT( IsSingleTCHAR( first, last ) );
|
||||
ASSERT( *first == char_test );
|
||||
ASSERT(IsSingleTCHAR(first, last));
|
||||
ASSERT(*first == char_test);
|
||||
|
||||
TSTRING str;
|
||||
|
||||
|
@ -380,43 +346,35 @@ TSTRING cBackslashCharEncoder::EncodeRoundtrip(
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
TSTRING cNonNarrowableCharEncoder::EncodePretty(
|
||||
TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const
|
||||
TSTRING cNonNarrowableCharEncoder::EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const
|
||||
{
|
||||
return EncodeRoundtrip( first, last );
|
||||
return EncodeRoundtrip(first, last);
|
||||
}
|
||||
|
||||
|
||||
TSTRING cNonPrintableCharEncoder::EncodePretty(
|
||||
TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const
|
||||
TSTRING cNonPrintableCharEncoder::EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const
|
||||
{
|
||||
return EncodeRoundtrip( first, last );
|
||||
return EncodeRoundtrip(first, last);
|
||||
}
|
||||
|
||||
|
||||
TSTRING cQuoteCharEncoder::EncodePretty(
|
||||
TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const
|
||||
TSTRING cQuoteCharEncoder::EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const
|
||||
{
|
||||
// should just be a quote
|
||||
ASSERT( IsSingleTCHAR( first, last ) );
|
||||
ASSERT( *first == char_test );
|
||||
ASSERT(IsSingleTCHAR(first, last));
|
||||
ASSERT(*first == char_test);
|
||||
|
||||
return TSTRING( 1, char_replace );
|
||||
return TSTRING(1, char_replace);
|
||||
}
|
||||
|
||||
|
||||
TSTRING cBackslashCharEncoder::EncodePretty(
|
||||
TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last ) const
|
||||
TSTRING cBackslashCharEncoder::EncodePretty(TSTRING::const_iterator first, TSTRING::const_iterator last) const
|
||||
{
|
||||
// should just be a backslash
|
||||
ASSERT( IsSingleTCHAR( first, last ) );
|
||||
ASSERT( *first == char_test );
|
||||
ASSERT(IsSingleTCHAR(first, last));
|
||||
ASSERT(*first == char_test);
|
||||
|
||||
return TSTRING( 1, char_replace );
|
||||
return TSTRING(1, char_replace);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -424,49 +382,45 @@ TSTRING cBackslashCharEncoder::EncodePretty(
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
TSTRING cNonNarrowableCharEncoder::Decode( TSTRING::const_iterator* pcur,
|
||||
const TSTRING::const_iterator end ) const
|
||||
TSTRING cNonNarrowableCharEncoder::Decode(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end) const
|
||||
{
|
||||
// check preconditions
|
||||
if( (*pcur) >= end || *(*pcur) != Identifier() )
|
||||
ThrowAndAssert( eBadDecoderInput() );
|
||||
if ((*pcur) >= end || *(*pcur) != Identifier())
|
||||
ThrowAndAssert(eBadDecoderInput());
|
||||
|
||||
return( cCharEncoderUtil::DecodeHexToChar( pcur, end ) );
|
||||
return (cCharEncoderUtil::DecodeHexToChar(pcur, end));
|
||||
}
|
||||
|
||||
|
||||
TSTRING cNonPrintableCharEncoder::Decode( TSTRING::const_iterator* pcur,
|
||||
const TSTRING::const_iterator end ) const
|
||||
TSTRING cNonPrintableCharEncoder::Decode(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end) const
|
||||
{
|
||||
// check preconditions
|
||||
if( (*pcur) >= end || *(*pcur) != Identifier() )
|
||||
ThrowAndAssert( eBadDecoderInput() );
|
||||
if ((*pcur) >= end || *(*pcur) != Identifier())
|
||||
ThrowAndAssert(eBadDecoderInput());
|
||||
|
||||
return( cCharEncoderUtil::DecodeHexToChar( pcur, end ) );
|
||||
return (cCharEncoderUtil::DecodeHexToChar(pcur, end));
|
||||
}
|
||||
|
||||
|
||||
TSTRING cQuoteCharEncoder::Decode( TSTRING::const_iterator* pcur,
|
||||
const TSTRING::const_iterator end ) const
|
||||
TSTRING cQuoteCharEncoder::Decode(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end) const
|
||||
{
|
||||
if( (*pcur) >= end || *(*pcur) != Identifier() )
|
||||
ThrowAndAssert( eBadDecoderInput() );
|
||||
if ((*pcur) >= end || *(*pcur) != Identifier())
|
||||
ThrowAndAssert(eBadDecoderInput());
|
||||
|
||||
(*pcur)++; // advance past part decoded
|
||||
|
||||
return TSTRING( 1, Identifier() );
|
||||
return TSTRING(1, Identifier());
|
||||
}
|
||||
|
||||
|
||||
TSTRING cBackslashCharEncoder::Decode( TSTRING::const_iterator* pcur,
|
||||
const TSTRING::const_iterator end ) const
|
||||
TSTRING cBackslashCharEncoder::Decode(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end) const
|
||||
{
|
||||
if( (*pcur) >= end || *(*pcur) != Identifier() )
|
||||
ThrowAndAssert( eBadDecoderInput() );
|
||||
if ((*pcur) >= end || *(*pcur) != Identifier())
|
||||
ThrowAndAssert(eBadDecoderInput());
|
||||
|
||||
(*pcur)++; // advance past part decoded
|
||||
|
||||
return TSTRING( 1, Identifier() );
|
||||
return TSTRING(1, Identifier());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -500,117 +454,107 @@ TCHAR cBackslashCharEncoder::Identifier() const
|
|||
// UTILITIES
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool cCharEncoderUtil::IsWhiteSpace( TCHAR ch )
|
||||
bool cCharEncoderUtil::IsWhiteSpace(TCHAR ch)
|
||||
{
|
||||
return ( ch == '\r' ||
|
||||
ch == '\n' ||
|
||||
ch == '\t' ||
|
||||
ch == '\v' ||
|
||||
ch == ' ' );
|
||||
return (ch == '\r' || ch == '\n' || ch == '\t' || ch == '\v' || ch == ' ');
|
||||
}
|
||||
|
||||
bool cCharEncoderUtil::IsPrintable( TCHAR ch )
|
||||
bool cCharEncoderUtil::IsPrintable(TCHAR ch)
|
||||
{
|
||||
#if USE_CLIB_LOCALE && !defined(__APPLE__)
|
||||
|
||||
return( ! isprint( ch ) ); // kludge for KAI
|
||||
return (!isprint(ch)); // kludge for KAI
|
||||
|
||||
#else // USE_CLIB_LOCALE
|
||||
|
||||
return( ! std::isprint<TCHAR>( ch, std::locale() ) );
|
||||
return (!std::isprint<TCHAR>(ch, std::locale()));
|
||||
|
||||
#endif // USE_CLIB_LOCALE
|
||||
}
|
||||
|
||||
TSTRING cCharEncoderUtil::CharStringToHexValue( const TSTRING& str )
|
||||
TSTRING cCharEncoderUtil::CharStringToHexValue(const TSTRING& str)
|
||||
{
|
||||
TSTRING strOut;
|
||||
TSTRING::const_iterator at;
|
||||
|
||||
for( at = str.begin(); at < str.end(); at++ )
|
||||
for (at = str.begin(); at < str.end(); at++)
|
||||
{
|
||||
strOut += char_to_hex( *at );
|
||||
strOut += char_to_hex(*at);
|
||||
}
|
||||
|
||||
return strOut;
|
||||
}
|
||||
|
||||
|
||||
TSTRING cCharEncoderUtil::HexValueToCharString( const TSTRING& str )
|
||||
TSTRING cCharEncoderUtil::HexValueToCharString(const TSTRING& str)
|
||||
{
|
||||
TSTRING strOut;
|
||||
TSTRING::const_iterator at;
|
||||
|
||||
for( at = str.begin(); at < str.end(); at += TCHAR_AS_HEX__IN_TCHARS )
|
||||
for (at = str.begin(); at < str.end(); at += TCHAR_AS_HEX__IN_TCHARS)
|
||||
{
|
||||
strOut += hex_to_char( at, at + TCHAR_AS_HEX__IN_TCHARS );
|
||||
strOut += hex_to_char(at, at + TCHAR_AS_HEX__IN_TCHARS);
|
||||
}
|
||||
|
||||
return strOut;
|
||||
}
|
||||
|
||||
TCHAR cCharEncoderUtil::hex_to_char( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last )
|
||||
TCHAR cCharEncoderUtil::hex_to_char(TSTRING::const_iterator first, TSTRING::const_iterator last)
|
||||
{
|
||||
static const TCHAR max_char = std::numeric_limits<TCHAR>::max();
|
||||
static const TCHAR min_char = std::numeric_limits<TCHAR>::min();
|
||||
|
||||
if( first + TCHAR_AS_HEX__IN_TCHARS != last )
|
||||
ThrowAndAssert( eBadHexConversion() );
|
||||
if (first + TCHAR_AS_HEX__IN_TCHARS != last)
|
||||
ThrowAndAssert(eBadHexConversion());
|
||||
|
||||
TISTRINGSTREAM ss( TSTRING( first, last ) );
|
||||
ss.imbue( std::locale::classic() );
|
||||
ss.fill ( _T('0') );
|
||||
ss.setf( std::ios_base::hex, std::ios_base::basefield );
|
||||
TISTRINGSTREAM ss(TSTRING(first, last));
|
||||
ss.imbue(std::locale::classic());
|
||||
ss.fill(_T('0'));
|
||||
ss.setf(std::ios_base::hex, std::ios_base::basefield);
|
||||
|
||||
unsigned long ch;
|
||||
ss >> ch;
|
||||
|
||||
if( ss.bad() || ss.fail() )
|
||||
ThrowAndAssert( eBadHexConversion( TSTRING( first, last ) ) );
|
||||
if( (TCHAR)ch > max_char || (TCHAR)ch < min_char )
|
||||
ThrowAndAssert( eBadHexConversion( TSTRING( first, last ) ) );
|
||||
if (ss.bad() || ss.fail())
|
||||
ThrowAndAssert(eBadHexConversion(TSTRING(first, last)));
|
||||
if ((TCHAR)ch > max_char || (TCHAR)ch < min_char)
|
||||
ThrowAndAssert(eBadHexConversion(TSTRING(first, last)));
|
||||
|
||||
return (TCHAR)ch;
|
||||
}
|
||||
|
||||
|
||||
TSTRING cCharEncoderUtil::char_to_hex( TCHAR ch )
|
||||
TSTRING cCharEncoderUtil::char_to_hex(TCHAR ch)
|
||||
{
|
||||
TOSTRINGSTREAM ss;
|
||||
|
||||
ss.imbue( std::locale::classic() );
|
||||
ss.fill ( _T('0') );
|
||||
ss.width( TCHAR_AS_HEX__IN_TCHARS );
|
||||
ss.setf( std::ios_base::hex, std::ios_base::basefield );
|
||||
ss.imbue(std::locale::classic());
|
||||
ss.fill(_T('0'));
|
||||
ss.width(TCHAR_AS_HEX__IN_TCHARS);
|
||||
ss.setf(std::ios_base::hex, std::ios_base::basefield);
|
||||
|
||||
ss << tss::util::char_to_size( ch );
|
||||
ss << tss::util::char_to_size(ch);
|
||||
|
||||
if( ss.bad() || ss.fail() ||
|
||||
ss.str().length() != TCHAR_AS_HEX__IN_TCHARS )
|
||||
ThrowAndAssert( eBadHexConversion( TSTRING( 1, ch ) ) );
|
||||
if (ss.bad() || ss.fail() || ss.str().length() != TCHAR_AS_HEX__IN_TCHARS)
|
||||
ThrowAndAssert(eBadHexConversion(TSTRING(1, ch)));
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
TSTRING cCharEncoderUtil::DecodeHexToChar( TSTRING::const_iterator* pcur,
|
||||
const TSTRING::const_iterator end )
|
||||
TSTRING cCharEncoderUtil::DecodeHexToChar(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end)
|
||||
{
|
||||
// get hex numbers -- 2 chars
|
||||
TSTRING str;
|
||||
size_t n = 0;
|
||||
for( (*pcur)++;
|
||||
n < TCHAR_AS_HEX__IN_TCHARS &&
|
||||
(*pcur) != end;
|
||||
n++, (*pcur)++ )
|
||||
for ((*pcur)++; n < TCHAR_AS_HEX__IN_TCHARS && (*pcur) != end; n++, (*pcur)++)
|
||||
{
|
||||
str += *(*pcur);
|
||||
}
|
||||
|
||||
if( n != TCHAR_AS_HEX__IN_TCHARS )
|
||||
ThrowAndAssert( eBadDecoderInput() );
|
||||
if (n != TCHAR_AS_HEX__IN_TCHARS)
|
||||
ThrowAndAssert(eBadDecoderInput());
|
||||
|
||||
// convert hex numbers
|
||||
return HexValueToCharString( str );
|
||||
return HexValueToCharString(str);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -618,28 +562,23 @@ TSTRING cCharEncoderUtil::DecodeHexToChar( TSTRING::const_iterator* pcur,
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
cEncoder::cEncoder( int e, int f )
|
||||
: m_fFlags( f )
|
||||
cEncoder::cEncoder(int e, int f) : m_fFlags(f)
|
||||
{
|
||||
// add encodings
|
||||
if( e & NON_NARROWABLE )
|
||||
m_encodings.push_back( new cNonNarrowableCharEncoder );
|
||||
if( e & NON_PRINTABLE )
|
||||
m_encodings.push_back( new cNonPrintableCharEncoder( AllowWhiteSpace() ) );
|
||||
if( e & BACKSLASH )
|
||||
m_encodings.push_back( new cBackslashCharEncoder );
|
||||
if( e & DBL_QUOTE )
|
||||
m_encodings.push_back( new cQuoteCharEncoder );
|
||||
if (e & NON_NARROWABLE)
|
||||
m_encodings.push_back(new cNonNarrowableCharEncoder);
|
||||
if (e & NON_PRINTABLE)
|
||||
m_encodings.push_back(new cNonPrintableCharEncoder(AllowWhiteSpace()));
|
||||
if (e & BACKSLASH)
|
||||
m_encodings.push_back(new cBackslashCharEncoder);
|
||||
if (e & DBL_QUOTE)
|
||||
m_encodings.push_back(new cQuoteCharEncoder);
|
||||
|
||||
// assert that we weren't passed anything freaky
|
||||
ASSERT( 0 == ( e & ~( NON_NARROWABLE |
|
||||
NON_PRINTABLE |
|
||||
BACKSLASH |
|
||||
DBL_QUOTE ) ) );
|
||||
ASSERT(0 == (e & ~(NON_NARROWABLE | NON_PRINTABLE | BACKSLASH | DBL_QUOTE)));
|
||||
|
||||
// add flags
|
||||
ASSERT( ! ( ( m_fFlags & ROUNDTRIP ) &&
|
||||
( m_fFlags & NON_ROUNDTRIP ) ) );
|
||||
ASSERT(!((m_fFlags & ROUNDTRIP) && (m_fFlags & NON_ROUNDTRIP)));
|
||||
|
||||
#ifdef TSS_DO_SCHEMA_VALIDATION
|
||||
|
||||
|
@ -647,32 +586,31 @@ cEncoder::cEncoder( int e, int f )
|
|||
ValidateSchema();
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
cEncoder::~cEncoder()
|
||||
{
|
||||
sack_type::iterator itr;
|
||||
for( itr = m_encodings.begin(); itr != m_encodings.end(); ++itr)
|
||||
for (itr = m_encodings.begin(); itr != m_encodings.end(); ++itr)
|
||||
delete *itr;
|
||||
}
|
||||
|
||||
bool cEncoder::RoundTrip() const
|
||||
{
|
||||
return( 0 != ( m_fFlags & ROUNDTRIP ) );
|
||||
return (0 != (m_fFlags & ROUNDTRIP));
|
||||
}
|
||||
|
||||
bool cEncoder::AllowWhiteSpace() const
|
||||
{
|
||||
return( 0 != ( m_fFlags & ALLOW_WHITESPACE ) );
|
||||
return (0 != (m_fFlags & ALLOW_WHITESPACE));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// ENCODER BASIC FUNCTIONALITY
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void cEncoder::Encode( TSTRING& strIn ) const
|
||||
void cEncoder::Encode(TSTRING& strIn) const
|
||||
{
|
||||
// TODO:BAM -- reserve space for strOut as an optimization?
|
||||
TSTRING strOut; // encoded string we will build up
|
||||
|
@ -683,29 +621,27 @@ void cEncoder::Encode( TSTRING& strIn ) const
|
|||
TSTRING::const_iterator last = end; // identifies end of current character
|
||||
|
||||
// while get next char (updates cur)
|
||||
while( cCharUtil::PopNextChar( cur, end, first, last ) )
|
||||
while (cCharUtil::PopNextChar(cur, end, first, last))
|
||||
{
|
||||
bool fCharEncoded = false; // answers: did char need encoding?
|
||||
sack_type::const_iterator atE;
|
||||
|
||||
// for all encoders
|
||||
for( atE = m_encodings.begin();
|
||||
atE != m_encodings.end();
|
||||
atE++ )
|
||||
for (atE = m_encodings.begin(); atE != m_encodings.end(); atE++)
|
||||
{
|
||||
// does char need encoding?
|
||||
if( (*atE)->NeedsEncoding( first, last ) )
|
||||
if ((*atE)->NeedsEncoding(first, last))
|
||||
{
|
||||
strOut += Encode( first, last, atE );
|
||||
strOut += Encode(first, last, atE);
|
||||
fCharEncoded = true;
|
||||
break; // each char should only fail at most one
|
||||
// encoding test, so it should be cool to quit
|
||||
}
|
||||
}
|
||||
|
||||
if( ! fCharEncoded )
|
||||
if (!fCharEncoded)
|
||||
{
|
||||
strOut.append( first, last ); // simply add current char to output since it needed no encoding
|
||||
strOut.append(first, last); // simply add current char to output since it needed no encoding
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -713,18 +649,17 @@ void cEncoder::Encode( TSTRING& strIn ) const
|
|||
strIn = strOut;
|
||||
}
|
||||
|
||||
TSTRING cEncoder::Encode( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last,
|
||||
sack_type::const_iterator encoding ) const
|
||||
TSTRING
|
||||
cEncoder::Encode(TSTRING::const_iterator first, TSTRING::const_iterator last, sack_type::const_iterator encoding) const
|
||||
{
|
||||
// encode it
|
||||
if( RoundTrip() )
|
||||
return (*encoding)->EncodeRoundtrip( first, last );
|
||||
if (RoundTrip())
|
||||
return (*encoding)->EncodeRoundtrip(first, last);
|
||||
else
|
||||
return (*encoding)->EncodePretty( first, last );
|
||||
return (*encoding)->EncodePretty(first, last);
|
||||
}
|
||||
|
||||
void cEncoder::Decode( TSTRING& strIn ) const
|
||||
void cEncoder::Decode(TSTRING& strIn) const
|
||||
{
|
||||
// TODO:BAM -- reserve space for strOut as an optimization?
|
||||
TSTRING strOut; // decoded string we will build up
|
||||
|
@ -736,37 +671,34 @@ void cEncoder::Decode( TSTRING& strIn ) const
|
|||
|
||||
|
||||
// while get next char (updates cur)
|
||||
while( cCharUtil::PopNextChar( cur, end, first, last ) )
|
||||
while (cCharUtil::PopNextChar(cur, end, first, last))
|
||||
{
|
||||
// is this char the escape character?
|
||||
if( IsSingleTCHAR( first, last ) &&
|
||||
*first == iCharEncoder::EscapeChar() )
|
||||
if (IsSingleTCHAR(first, last) && *first == iCharEncoder::EscapeChar())
|
||||
{
|
||||
// get to identifier
|
||||
if( ! cCharUtil::PopNextChar( cur, end, first, last ) )
|
||||
ThrowAndAssert( eBadDecoderInput() );
|
||||
if (!cCharUtil::PopNextChar(cur, end, first, last))
|
||||
ThrowAndAssert(eBadDecoderInput());
|
||||
|
||||
// this algorithm assumes that all identifiers are single char
|
||||
// so anything following the escape char should be a
|
||||
// single-char identifier
|
||||
if( ! IsSingleTCHAR( first, last ) )
|
||||
THROW_INTERNAL( "displayencoder.cpp" );
|
||||
if (!IsSingleTCHAR(first, last))
|
||||
THROW_INTERNAL("displayencoder.cpp");
|
||||
|
||||
// determine to which encoding the identifier belongs
|
||||
bool fFoundEncoding = false;
|
||||
sack_type::const_iterator atE;
|
||||
for( atE = m_encodings.begin();
|
||||
atE != m_encodings.end();
|
||||
atE++ )
|
||||
for (atE = m_encodings.begin(); atE != m_encodings.end(); atE++)
|
||||
{
|
||||
// is this the right encoding?
|
||||
if( *first == (*atE)->Identifier() )
|
||||
if (*first == (*atE)->Identifier())
|
||||
{
|
||||
// this is the correct encoding....
|
||||
fFoundEncoding = true;
|
||||
|
||||
// ...so decode char
|
||||
strOut += (*atE)->Decode( &first, end ); // should modify cur
|
||||
strOut += (*atE)->Decode(&first, end); // should modify cur
|
||||
|
||||
cur = first; // advance current char pointer
|
||||
|
||||
|
@ -775,12 +707,12 @@ void cEncoder::Decode( TSTRING& strIn ) const
|
|||
}
|
||||
}
|
||||
|
||||
if( ! fFoundEncoding )
|
||||
ThrowAndAssert( eUnknownEscapeEncoding( TSTRING( 1, *first ) ) );
|
||||
if (!fFoundEncoding)
|
||||
ThrowAndAssert(eUnknownEscapeEncoding(TSTRING(1, *first)));
|
||||
}
|
||||
else
|
||||
{
|
||||
strOut.append( first, last );
|
||||
strOut.append(first, last);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -793,8 +725,8 @@ void cEncoder::Decode( TSTRING& strIn ) const
|
|||
|
||||
void cEncoder::ValidateSchema() const
|
||||
{
|
||||
ASSERT( OnlyOneCatagoryPerChar() );
|
||||
ASSERT( AllIdentifiersUnique() );
|
||||
ASSERT(OnlyOneCatagoryPerChar());
|
||||
ASSERT(AllIdentifiersUnique());
|
||||
}
|
||||
|
||||
|
||||
|
@ -803,28 +735,27 @@ bool cEncoder::OnlyOneCatagoryPerChar() const
|
|||
{
|
||||
// TODO:BAM - man, is there a better way to do this?
|
||||
TCHAR ch = std::numeric_limits<TCHAR>::min();
|
||||
TSTRING ach(1,ch);
|
||||
TSTRING ach(1, ch);
|
||||
|
||||
if( ch != std::numeric_limits<TCHAR>::max() )
|
||||
if (ch != std::numeric_limits<TCHAR>::max())
|
||||
{
|
||||
do
|
||||
{
|
||||
bool fFailedATest = false;
|
||||
|
||||
ach[0] = ch;
|
||||
for( sack_type::const_iterator atE = m_encodings.begin(); atE != m_encodings.end(); atE++ )
|
||||
for (sack_type::const_iterator atE = m_encodings.begin(); atE != m_encodings.end(); atE++)
|
||||
{
|
||||
if( (*atE)->NeedsEncoding( ach.begin(), ach.end() ) )
|
||||
if ((*atE)->NeedsEncoding(ach.begin(), ach.end()))
|
||||
{
|
||||
if( fFailedATest )
|
||||
if (fFailedATest)
|
||||
return false; // each char can only fail one test
|
||||
else
|
||||
fFailedATest = true;
|
||||
}
|
||||
}
|
||||
ch++;
|
||||
}
|
||||
while( ch != std::numeric_limits<TCHAR>::max() );
|
||||
} while (ch != std::numeric_limits<TCHAR>::max());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -833,10 +764,10 @@ bool cEncoder::OnlyOneCatagoryPerChar() const
|
|||
bool cEncoder::AllIdentifiersUnique() const
|
||||
{
|
||||
TSTRING chars;
|
||||
for( sack_type::const_iterator atE = m_encodings.begin(); atE != m_encodings.end(); atE++ )
|
||||
for (sack_type::const_iterator atE = m_encodings.begin(); atE != m_encodings.end(); atE++)
|
||||
{
|
||||
TCHAR chID = (*atE)->Identifier();
|
||||
if( chars.find( chID ) == TSTRING::npos )
|
||||
if (chars.find(chID) == TSTRING::npos)
|
||||
chars += chID;
|
||||
else
|
||||
return false;
|
||||
|
@ -845,7 +776,7 @@ bool cEncoder::AllIdentifiersUnique() const
|
|||
}
|
||||
|
||||
|
||||
bool cEncoder::AllTestsRunOnEncodedString( const TSTRING& s ) const
|
||||
bool cEncoder::AllTestsRunOnEncodedString(const TSTRING& s) const
|
||||
{
|
||||
TSTRING::const_iterator cur = s.begin(); // pointer to working position in s
|
||||
const TSTRING::const_iterator end = s.end(); // end of s
|
||||
|
@ -854,14 +785,12 @@ bool cEncoder::AllTestsRunOnEncodedString( const TSTRING& s ) const
|
|||
|
||||
|
||||
// while get next char (updates cur)
|
||||
while( cCharUtil::PopNextChar( cur, end, first, last ) )
|
||||
while (cCharUtil::PopNextChar(cur, end, first, last))
|
||||
{
|
||||
sack_type::const_iterator atE;
|
||||
for( atE = m_encodings.begin();
|
||||
atE != m_encodings.end();
|
||||
atE++ )
|
||||
for (atE = m_encodings.begin(); atE != m_encodings.end(); atE++)
|
||||
{
|
||||
if( (*atE)->NeedsEncoding( first, last ) )
|
||||
if ((*atE)->NeedsEncoding(first, last))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -877,25 +806,17 @@ bool cEncoder::AllTestsRunOnEncodedString( const TSTRING& s ) const
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
cDisplayEncoder::cDisplayEncoder( Flags f )
|
||||
: cEncoder(
|
||||
NON_NARROWABLE |
|
||||
NON_PRINTABLE |
|
||||
BACKSLASH |
|
||||
DBL_QUOTE,
|
||||
f
|
||||
)
|
||||
cDisplayEncoder::cDisplayEncoder(Flags f) : cEncoder(NON_NARROWABLE | NON_PRINTABLE | BACKSLASH | DBL_QUOTE, f)
|
||||
{
|
||||
}
|
||||
|
||||
void cDisplayEncoder::Encode( TSTRING& str ) const
|
||||
void cDisplayEncoder::Encode(TSTRING& str) const
|
||||
{
|
||||
cEncoder::Encode( str );
|
||||
cEncoder::Encode(str);
|
||||
}
|
||||
|
||||
bool cDisplayEncoder::Decode( TSTRING& str ) const
|
||||
bool cDisplayEncoder::Decode(TSTRING& str) const
|
||||
{
|
||||
cEncoder::Decode( str );
|
||||
cEncoder::Decode(str);
|
||||
return true; // TODO:BAM -- throw error!
|
||||
}
|
||||
|
||||
|
|
|
@ -40,10 +40,10 @@
|
|||
// EXCEPTION DECLARATION
|
||||
//=========================================================================
|
||||
|
||||
TSS_EXCEPTION( eEncoder, eError );
|
||||
TSS_EXCEPTION( eBadDecoderInput, eEncoder );
|
||||
TSS_EXCEPTION( eBadHexConversion, eEncoder );
|
||||
TSS_EXCEPTION( eUnknownEscapeEncoding, eEncoder );
|
||||
TSS_EXCEPTION(eEncoder, eError);
|
||||
TSS_EXCEPTION(eBadDecoderInput, eEncoder);
|
||||
TSS_EXCEPTION(eBadHexConversion, eEncoder);
|
||||
TSS_EXCEPTION(eUnknownEscapeEncoding, eEncoder);
|
||||
|
||||
//=========================================================================
|
||||
// DECLARATION OF CLASSES
|
||||
|
@ -59,7 +59,7 @@ class iCharEncoder;
|
|||
// as long as AllIdentifiersUnique and OnlyOneCatagoryPerChar are true
|
||||
class cEncoder
|
||||
{
|
||||
public:
|
||||
public:
|
||||
enum Encodings
|
||||
{
|
||||
NON_NARROWABLE = 0x01, // WC -> MB, MB alway narrowable:
|
||||
|
@ -75,23 +75,22 @@ class cEncoder
|
|||
ALLOW_WHITESPACE = 0x04
|
||||
};
|
||||
|
||||
cEncoder( int e, int f ); // mask of Encodings
|
||||
cEncoder(int e, int f); // mask of Encodings
|
||||
virtual ~cEncoder();
|
||||
|
||||
void Encode( TSTRING& str ) const;
|
||||
void Decode( TSTRING& str ) const; // TODO:BAM -- throw error!
|
||||
void Encode(TSTRING& str) const;
|
||||
void Decode(TSTRING& str) const; // TODO:BAM -- throw error!
|
||||
|
||||
void ValidateSchema() const;
|
||||
bool OnlyOneCatagoryPerChar() const;
|
||||
bool AllIdentifiersUnique() const;
|
||||
bool AllTestsRunOnEncodedString( const TSTRING& str ) const;
|
||||
bool AllTestsRunOnEncodedString(const TSTRING& str) const;
|
||||
|
||||
private:
|
||||
typedef std::vector< iCharEncoder* > sack_type;
|
||||
private:
|
||||
typedef std::vector<iCharEncoder*> sack_type;
|
||||
|
||||
TSTRING Encode( TSTRING::const_iterator first,
|
||||
TSTRING::const_iterator last,
|
||||
sack_type::const_iterator encoding ) const;
|
||||
TSTRING
|
||||
Encode(TSTRING::const_iterator first, TSTRING::const_iterator last, sack_type::const_iterator encoding) const;
|
||||
|
||||
bool RoundTrip() const;
|
||||
bool AllowWhiteSpace() const;
|
||||
|
@ -104,55 +103,51 @@ class cEncoder
|
|||
|
||||
class cDisplayEncoder : public cEncoder
|
||||
{
|
||||
public:
|
||||
cDisplayEncoder( Flags f = NON_ROUNDTRIP );
|
||||
public:
|
||||
cDisplayEncoder(Flags f = NON_ROUNDTRIP);
|
||||
|
||||
void Encode( TSTRING& str ) const;
|
||||
bool Decode( TSTRING& str ) const;
|
||||
void Encode(TSTRING& str) const;
|
||||
bool Decode(TSTRING& str) const;
|
||||
|
||||
static TSTRING EncodeInline( const TSTRING& sIn )
|
||||
static TSTRING EncodeInline(const TSTRING& sIn)
|
||||
{
|
||||
TSTRING sOut = sIn;
|
||||
cDisplayEncoder e;
|
||||
e.Encode( sOut );
|
||||
e.Encode(sOut);
|
||||
return sOut;
|
||||
}
|
||||
|
||||
static TSTRING EncodeInlineAllowWS( const TSTRING& sIn )
|
||||
static TSTRING EncodeInlineAllowWS(const TSTRING& sIn)
|
||||
{
|
||||
TSTRING sOut = sIn;
|
||||
cDisplayEncoder e( (Flags)( NON_ROUNDTRIP | ALLOW_WHITESPACE ) );
|
||||
e.Encode( sOut );
|
||||
cDisplayEncoder e((Flags)(NON_ROUNDTRIP | ALLOW_WHITESPACE));
|
||||
e.Encode(sOut);
|
||||
return sOut;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class cCharEncoderUtil
|
||||
{
|
||||
public:
|
||||
public:
|
||||
static bool IsPrintable(TCHAR ch);
|
||||
static bool IsWhiteSpace(TCHAR ch);
|
||||
|
||||
static bool IsPrintable( TCHAR ch );
|
||||
static bool IsWhiteSpace( TCHAR ch );
|
||||
static TSTRING CharStringToHexValue(const TSTRING& str);
|
||||
|
||||
static TSTRING CharStringToHexValue( const TSTRING& str );
|
||||
static TSTRING HexValueToCharString(const TSTRING& str);
|
||||
|
||||
static TSTRING HexValueToCharString( const TSTRING& str );
|
||||
static TCHAR hex_to_char(TSTRING::const_iterator first, TSTRING::const_iterator last);
|
||||
|
||||
static TCHAR hex_to_char( TSTRING::const_iterator first,
|
||||
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,
|
||||
const TSTRING::const_iterator end );
|
||||
static TSTRING DecodeHexToChar(TSTRING::const_iterator* pcur, const TSTRING::const_iterator end);
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
BYTE_AS_HEX__IN_TCHARS = 2,
|
||||
BYTES_PER_TCHAR = sizeof( TCHAR ),
|
||||
BYTES_PER_TCHAR = sizeof(TCHAR),
|
||||
TCHAR_AS_HEX__IN_TCHARS = BYTE_AS_HEX__IN_TCHARS * BYTES_PER_TCHAR
|
||||
};
|
||||
};
|
||||
|
@ -241,4 +236,3 @@ typedef cDisplayEncoder_<TCHAR> cDisplayEncoder;
|
|||
#endif //__DISPLAYENCODER_H
|
||||
|
||||
*/
|
||||
|
||||
|
|
|
@ -40,29 +40,29 @@
|
|||
#include "ntmbs.h"
|
||||
#include <iomanip>
|
||||
|
||||
TSTRING cDisplayUtil::FormatMultiLineString( const TSTRING& str, int nOffset, int nWidth )
|
||||
TSTRING cDisplayUtil::FormatMultiLineString(const TSTRING& str, int nOffset, int nWidth)
|
||||
{
|
||||
TOSTRINGSTREAM sstr;
|
||||
TSTRING strT;
|
||||
bool fFirstLine = true;
|
||||
for( TSTRING::const_iterator i = str.begin(); i != str.end(); i = *i ? i + 1 : i )
|
||||
for (TSTRING::const_iterator i = str.begin(); i != str.end(); i = *i ? i + 1 : i)
|
||||
{
|
||||
// return found -- add line to output string
|
||||
if( _T('\n') == *i )
|
||||
if (_T('\n') == *i)
|
||||
{
|
||||
// only do offset for strings after the first
|
||||
if( fFirstLine )
|
||||
if (fFirstLine)
|
||||
{
|
||||
fFirstLine = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// add offset
|
||||
for( int j = 0; j < nOffset; j++ )
|
||||
for (int j = 0; j < nOffset; j++)
|
||||
sstr << _T(" ");
|
||||
|
||||
// set width
|
||||
sstr << std::setw( nWidth );
|
||||
sstr << std::setw(nWidth);
|
||||
}
|
||||
|
||||
// add to stringstream
|
||||
|
@ -74,7 +74,7 @@ TSTRING cDisplayUtil::FormatMultiLineString( const TSTRING& str, int nOffset, in
|
|||
else
|
||||
{
|
||||
// add char to string
|
||||
strT.append( i, (TSTRING::const_iterator)(*i ? i + 1 : i) );
|
||||
strT.append(i, (TSTRING::const_iterator)(*i ? i + 1 : i));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,19 +82,17 @@ TSTRING cDisplayUtil::FormatMultiLineString( const TSTRING& str, int nOffset, in
|
|||
// we want our client to be able to say "out << PropAsString() << endl;"
|
||||
|
||||
// add offset
|
||||
if( ! fFirstLine )
|
||||
if (!fFirstLine)
|
||||
{
|
||||
for( int j = 0; j < nOffset; j++ )
|
||||
for (int j = 0; j < nOffset; j++)
|
||||
sstr << _T(" ");
|
||||
}
|
||||
|
||||
// set width
|
||||
sstr << std::setw( nWidth );
|
||||
sstr << std::setw(nWidth);
|
||||
|
||||
// now add last string
|
||||
sstr << strT;
|
||||
|
||||
return( sstr.str() );
|
||||
return (sstr.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
class cDisplayUtil
|
||||
{
|
||||
public:
|
||||
static TSTRING FormatMultiLineString( const TSTRING& str, int nOffset, int nWidth );
|
||||
static TSTRING FormatMultiLineString(const TSTRING& str, int nOffset, int nWidth);
|
||||
};
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -98,4 +98,3 @@ public:
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
#endif // #ifndef __DISPLAYUTIL_H
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ bool CheckEpoch()
|
|||
time_struct.tm_mday = 1;
|
||||
time_struct.tm_mon = 0;
|
||||
time_struct.tm_year = 138;
|
||||
int64 endoftime = cTimeUtil::DateToTime( &time_struct );
|
||||
int64 endoftime = cTimeUtil::DateToTime(&time_struct);
|
||||
|
||||
if (time(0) > endoftime)
|
||||
{
|
||||
|
@ -64,4 +64,3 @@ bool CheckEpoch()
|
|||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -42,4 +42,3 @@
|
|||
bool CheckEpoch();
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -39,13 +39,11 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// CalcHash
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
uint32 eError::CalcHash( const char* name )
|
||||
uint32 eError::CalcHash(const char* name)
|
||||
{
|
||||
CRC_INFO crc;
|
||||
crcInit( crc );
|
||||
crcUpdate( crc, (const uint8*)name, strlen( name ) );
|
||||
crcFinit( crc );
|
||||
crcInit(crc);
|
||||
crcUpdate(crc, (const uint8*)name, strlen(name));
|
||||
crcFinit(crc);
|
||||
return crc.crc;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,14 +42,13 @@
|
|||
class eError
|
||||
{
|
||||
public:
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Construction and Assignment
|
||||
//-------------------------------------------------------------------------
|
||||
eError( const TSTRING& msg, uint32 flags = 0 );
|
||||
explicit eError( const eError& rhs );
|
||||
eError(const TSTRING& msg, uint32 flags = 0);
|
||||
explicit eError(const eError& rhs);
|
||||
explicit eError();
|
||||
void operator=( const eError& rhs );
|
||||
void operator=(const eError& rhs);
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Destruction
|
||||
|
@ -87,7 +86,7 @@ public:
|
|||
SUPRESS_THIRD_MSG = 0x00000002 // supresses the "continuing" or "exiting" message
|
||||
};
|
||||
|
||||
void SetFlags( uint32 flags );
|
||||
void SetFlags(uint32 flags);
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Flag Convenience Methods
|
||||
|
@ -104,7 +103,7 @@ public:
|
|||
//-------------------------------------------------------------------------
|
||||
// Utility Methods
|
||||
//-------------------------------------------------------------------------
|
||||
static uint32 CalcHash( const char* name );
|
||||
static uint32 CalcHash(const char* name);
|
||||
// calculates the CRC32 of the string passed in as name. This methods
|
||||
// asserts that name is non null. This is used to generate unique IDs
|
||||
// for errors.
|
||||
|
@ -129,44 +128,51 @@ protected:
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if HAVE_GCC
|
||||
#define TSS_BEGIN_EXCEPTION_EXPLICIT
|
||||
# define TSS_BEGIN_EXCEPTION_EXPLICIT
|
||||
#else
|
||||
#define TSS_BEGIN_EXCEPTION_EXPLICIT explicit
|
||||
# define TSS_BEGIN_EXCEPTION_EXPLICIT explicit
|
||||
#endif
|
||||
|
||||
#define TSS_BEGIN_EXCEPTION( except, base ) \
|
||||
#define TSS_BEGIN_EXCEPTION(except, base) \
|
||||
class except : public base \
|
||||
{\
|
||||
public:\
|
||||
except( const TSTRING& msg, uint32 flags = 0 ) \
|
||||
: base( msg, flags ) {} \
|
||||
TSS_BEGIN_EXCEPTION_EXPLICIT except( const except& rhs ) \
|
||||
: base( rhs ) {} \
|
||||
explicit except() : base() {} \
|
||||
{ \
|
||||
public: \
|
||||
except(const TSTRING& msg, uint32 flags = 0) : base(msg, flags) \
|
||||
{ \
|
||||
} \
|
||||
TSS_BEGIN_EXCEPTION_EXPLICIT except(const except& rhs) : base(rhs) \
|
||||
{ \
|
||||
} \
|
||||
explicit except() : base() \
|
||||
{ \
|
||||
} \
|
||||
\
|
||||
virtual uint32 GetID() const \
|
||||
{\
|
||||
return CalcHash( #except ); \
|
||||
}\
|
||||
{ \
|
||||
return CalcHash(#except); \
|
||||
}
|
||||
|
||||
#define TSS_END_EXCEPTION( ) \
|
||||
};
|
||||
#define TSS_END_EXCEPTION() \
|
||||
} \
|
||||
;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// TSS_BEGIN_EXCEPTION_NO_CTOR
|
||||
//
|
||||
// Same as TSS_BEGIN_EXCEPTION, but doesn't define any ctors.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define TSS_BEGIN_EXCEPTION_NO_CTOR( except, base ) \
|
||||
#define TSS_BEGIN_EXCEPTION_NO_CTOR(except, base) \
|
||||
class except : public base \
|
||||
{\
|
||||
public:\
|
||||
explicit except() : base() {} \
|
||||
{ \
|
||||
public: \
|
||||
explicit except() : base() \
|
||||
{ \
|
||||
} \
|
||||
\
|
||||
virtual uint32 GetID() const \
|
||||
{\
|
||||
return CalcHash( #except ); \
|
||||
}\
|
||||
{ \
|
||||
return CalcHash(#except); \
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// TSS_EXCEPTION
|
||||
|
@ -178,8 +184,8 @@ protected:
|
|||
// TODO (mdb) -- do we want to cache the CRC? if we store it in a class static
|
||||
// variable, then we will need to define it in the cpp file as well ...
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define TSS_EXCEPTION( except, base ) \
|
||||
TSS_BEGIN_EXCEPTION( except, base ) \
|
||||
#define TSS_EXCEPTION(except, base) \
|
||||
TSS_BEGIN_EXCEPTION(except, base) \
|
||||
TSS_END_EXCEPTION()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -189,38 +195,29 @@ protected:
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// eError
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline eError::eError( const TSTRING& msg, uint32 flags )
|
||||
: mMsg ( msg ),
|
||||
mFlags ( flags )
|
||||
inline eError::eError(const TSTRING& msg, uint32 flags) : mMsg(msg), mFlags(flags)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// eError
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline eError::eError( const eError& rhs )
|
||||
: mMsg ( rhs.mMsg ),
|
||||
mFlags ( rhs.mFlags )
|
||||
inline eError::eError(const eError& rhs) : mMsg(rhs.mMsg), mFlags(rhs.mFlags)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// eError
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline eError::eError( )
|
||||
: mMsg ( _T("") ),
|
||||
mFlags ( 0 )
|
||||
inline eError::eError() : mMsg(_T("")), mFlags(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// operator=
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline void eError::operator=( const eError& rhs )
|
||||
inline void eError::operator=(const eError& rhs)
|
||||
{
|
||||
mMsg = rhs.mMsg;
|
||||
mFlags = rhs.mFlags;
|
||||
|
@ -231,7 +228,6 @@ inline void eError::operator=( const eError& rhs )
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline eError::~eError()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -253,7 +249,7 @@ inline uint32 eError::GetFlags() const
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// SetFlags
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline void eError::SetFlags( uint32 flags )
|
||||
inline void eError::SetFlags(uint32 flags)
|
||||
{
|
||||
mFlags = flags;
|
||||
}
|
||||
|
@ -275,7 +271,6 @@ inline void eError::SetFatality(bool fatal)
|
|||
inline bool eError::IsFatal() const
|
||||
{
|
||||
return (mFlags & (uint32)NON_FATAL) == 0;
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -298,6 +293,4 @@ inline bool eError::SupressThird() const
|
|||
}
|
||||
|
||||
|
||||
|
||||
#endif //__ERROR_H
|
||||
|
||||
|
|
|
@ -57,7 +57,9 @@ class cErrorBucket
|
|||
{
|
||||
public:
|
||||
cErrorBucket();
|
||||
virtual ~cErrorBucket() {}
|
||||
virtual ~cErrorBucket()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void AddError(const eError& error);
|
||||
// add an error to the bucket
|
||||
|
@ -81,8 +83,7 @@ protected:
|
|||
///////////////////
|
||||
// cErrorBucket
|
||||
///////////////////
|
||||
inline cErrorBucket::cErrorBucket() :
|
||||
mpChild(0)
|
||||
inline cErrorBucket::cErrorBucket() : mpChild(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -99,4 +100,3 @@ inline cErrorBucket* cErrorBucket::SetChild(cErrorBucket* pNewChild)
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
void cErrorBucket::AddError(const eError& error)
|
||||
{
|
||||
HandleError(error);
|
||||
if(mpChild)
|
||||
if (mpChild)
|
||||
mpChild->AddError(error);
|
||||
}
|
||||
|
||||
|
@ -52,9 +52,7 @@ void cErrorBucket::AddError(const eError& error)
|
|||
//#############################################################################
|
||||
void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
|
||||
{
|
||||
cDisplayEncoder e(
|
||||
(cDisplayEncoder::Flags) ( cDisplayEncoder::NON_ROUNDTRIP |
|
||||
cDisplayEncoder::ALLOW_WHITESPACE ) );
|
||||
cDisplayEncoder e((cDisplayEncoder::Flags)(cDisplayEncoder::NON_ROUNDTRIP | cDisplayEncoder::ALLOW_WHITESPACE));
|
||||
TSTRING errStr;
|
||||
|
||||
//
|
||||
|
@ -68,19 +66,18 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
|
|||
// point is when we throw ePoly() with no constructor arguments. At some point we want
|
||||
// to stop using the mechanism have non-printing errors, thus we leave in the ASSERT below.
|
||||
// But we don't want to break any release code, thus we return on the next line - June 2, 1999 DMB.
|
||||
ASSERT( error.GetID() != 0 );
|
||||
ASSERT(error.GetID() != 0);
|
||||
|
||||
if( error.GetID() == 0 )
|
||||
if (error.GetID() == 0)
|
||||
return;
|
||||
|
||||
// "First Part" header
|
||||
errStr = TSS_GetString( cCore, error.IsFatal() ? core::STR_ERROR_ERROR
|
||||
: core::STR_ERROR_WARNING );
|
||||
errStr = TSS_GetString(cCore, error.IsFatal() ? core::STR_ERROR_ERROR : core::STR_ERROR_WARNING);
|
||||
|
||||
if (errStr.empty())
|
||||
{
|
||||
TOSTRINGSTREAM strm;
|
||||
ASSERT( sizeof( uint32 ) == sizeof(unsigned int) ); // for cast on next line
|
||||
ASSERT(sizeof(uint32) == sizeof(unsigned int)); // for cast on next line
|
||||
strm << _T("Unknown Error ID ") << (unsigned int)error.GetID();
|
||||
errStr = strm.str();
|
||||
}
|
||||
|
@ -91,10 +88,10 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
|
|||
// "First Part" error string
|
||||
TSTRING prependToSecond;
|
||||
|
||||
// #pragma message("errorbucketimpl.cpp needs a little help in the mb arena, with the findfirst/last and such")
|
||||
// #pragma message("errorbucketimpl.cpp needs a little help in the mb arena, with the findfirst/last and such")
|
||||
|
||||
errStr = cErrorTable::GetInstance()->Get( error.GetID() );
|
||||
if(! errStr.empty())
|
||||
errStr = cErrorTable::GetInstance()->Get(error.GetID());
|
||||
if (!errStr.empty())
|
||||
{
|
||||
// If the first part has a '\n' in it, we take everything following and prepend it to the
|
||||
// second part. This was added to allow specifing a verbose string as the second part
|
||||
|
@ -108,7 +105,7 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
|
|||
|
||||
ASSERT(errStr.length() + len + 6 < 80); // line too big for terminal?
|
||||
// Add 6 to account for "### ' and ': '
|
||||
TCERR << TSS_GetString( cCore, core::STR_ERROR_COLON ) << _T(" ") << errStr;
|
||||
TCERR << TSS_GetString(cCore, core::STR_ERROR_COLON) << _T(" ") << errStr;
|
||||
TCERR << std::endl;
|
||||
}
|
||||
|
||||
|
@ -117,8 +114,8 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
|
|||
const TCHAR SPACE = _T(' ');
|
||||
|
||||
errStr = prependToSecond + error.GetMsg() + strExtra;
|
||||
e.Encode( errStr );
|
||||
if (! errStr.empty())
|
||||
e.Encode(errStr);
|
||||
if (!errStr.empty())
|
||||
{
|
||||
do
|
||||
{
|
||||
|
@ -132,11 +129,12 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
|
|||
{
|
||||
if (currentStr.length() <= (unsigned int)WIDTH)
|
||||
{
|
||||
TCERR << TSS_GetString( cCore, core::STR_ERROR_HEADER ) << currentStr << std::endl;
|
||||
TCERR << TSS_GetString(cCore, core::STR_ERROR_HEADER) << currentStr << std::endl;
|
||||
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)
|
||||
{
|
||||
// can't find space to break at so this string will just have to be longer than screen width.
|
||||
|
@ -148,28 +146,21 @@ void cErrorReporter::PrintErrorMsg(const eError& error, const TSTRING& strExtra)
|
|||
lastSpace = currentStr.length();
|
||||
}
|
||||
|
||||
TCERR << TSS_GetString( cCore, core::STR_ERROR_HEADER )
|
||||
<< currentStr.substr( 0, lastSpace )
|
||||
<< std::endl;
|
||||
TCERR << TSS_GetString(cCore, core::STR_ERROR_HEADER) << currentStr.substr(0, lastSpace) << std::endl;
|
||||
|
||||
currentStr.erase( 0, lastSpace + 1 );
|
||||
}
|
||||
while ( !currentStr.empty() );
|
||||
}
|
||||
while ( !errStr.empty() );
|
||||
currentStr.erase(0, lastSpace + 1);
|
||||
} while (!currentStr.empty());
|
||||
} while (!errStr.empty());
|
||||
}
|
||||
|
||||
// "Third Part" print 'exiting' or 'continuing'
|
||||
// note that we supress this part if the appropriate flag is set...
|
||||
//
|
||||
if( (error.GetFlags() & eError::SUPRESS_THIRD_MSG) == 0 )
|
||||
if ((error.GetFlags() & eError::SUPRESS_THIRD_MSG) == 0)
|
||||
{
|
||||
TCERR << TSS_GetString( cCore, core::STR_ERROR_HEADER)
|
||||
<< TSS_GetString(
|
||||
cCore,
|
||||
error.IsFatal()
|
||||
? core::STR_ERROR_EXITING
|
||||
: core::STR_ERROR_CONTINUING ) << std::endl;
|
||||
TCERR << TSS_GetString(cCore, core::STR_ERROR_HEADER)
|
||||
<< TSS_GetString(cCore, 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");
|
||||
|
||||
d.TraceError( _T("%s : %s\n"),
|
||||
cErrorTable::GetInstance()->Get( error.GetID() ).c_str(),
|
||||
error.GetMsg().c_str() );
|
||||
d.TraceError(_T("%s : %s\n"), cErrorTable::GetInstance()->Get(error.GetID()).c_str(), error.GetMsg().c_str());
|
||||
}
|
||||
|
||||
//#############################################################################
|
||||
|
@ -207,17 +196,15 @@ int cErrorQueue::GetNumErrors() const
|
|||
|
||||
void cErrorQueue::HandleError(const eError& error)
|
||||
{
|
||||
mList.push_back( ePoly( error ) );
|
||||
mList.push_back(ePoly(error));
|
||||
}
|
||||
|
||||
cErrorQueueIter::cErrorQueueIter(cErrorQueue& queue) :
|
||||
mList(queue.mList)
|
||||
cErrorQueueIter::cErrorQueueIter(cErrorQueue& queue) : mList(queue.mList)
|
||||
{
|
||||
SeekBegin();
|
||||
}
|
||||
|
||||
cErrorQueueIter::cErrorQueueIter(const cErrorQueue& queue)
|
||||
: mList( ((cErrorQueue*)&queue)->mList )
|
||||
cErrorQueueIter::cErrorQueueIter(const cErrorQueue& queue) : mList(((cErrorQueue*)&queue)->mList)
|
||||
{
|
||||
SeekBegin();
|
||||
}
|
||||
|
@ -240,7 +227,7 @@ bool cErrorQueueIter::Done() const
|
|||
|
||||
const ePoly& cErrorQueueIter::GetError() const
|
||||
{
|
||||
ASSERT(! Done());
|
||||
ASSERT(!Done());
|
||||
return (*mIter);
|
||||
}
|
||||
|
||||
|
@ -255,19 +242,18 @@ void cErrorQueue::Read(iSerializer* pSerializer, int32 version)
|
|||
int32 size;
|
||||
mList.clear();
|
||||
pSerializer->ReadInt32(size);
|
||||
for(int i = 0; i < size; ++i)
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
int32 errorNumber;
|
||||
TSTRING errorString;
|
||||
int32 flags;
|
||||
|
||||
pSerializer->ReadInt32 (errorNumber);
|
||||
pSerializer->ReadString (errorString);
|
||||
pSerializer->ReadInt32 (flags);
|
||||
pSerializer->ReadInt32(errorNumber);
|
||||
pSerializer->ReadString(errorString);
|
||||
pSerializer->ReadInt32(flags);
|
||||
|
||||
mList.push_back( ePoly( errorNumber, errorString, flags ) );
|
||||
mList.push_back(ePoly(errorNumber, errorString, flags));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -277,13 +263,12 @@ void cErrorQueue::Write(iSerializer* pSerializer) const
|
|||
{
|
||||
pSerializer->WriteInt32(mList.size());
|
||||
ListType::const_iterator i;
|
||||
for( i = mList.begin(); i != mList.end(); ++i)
|
||||
for (i = mList.begin(); i != mList.end(); ++i)
|
||||
{
|
||||
pSerializer->WriteInt32 ((*i).GetID());
|
||||
pSerializer->WriteInt32((*i).GetID());
|
||||
pSerializer->WriteString((*i).GetMsg());
|
||||
pSerializer->WriteInt32 ((*i).GetFlags());
|
||||
pSerializer->WriteInt32((*i).GetFlags());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -292,15 +277,14 @@ void cErrorQueue::Write(iSerializer* pSerializer) const
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cErrorQueue::TraceContents(int dl) const
|
||||
{
|
||||
if(dl < 0)
|
||||
if (dl < 0)
|
||||
dl = cDebug::D_DEBUG;
|
||||
|
||||
cDebug d("cFCOErrorQueue::TraceContents");
|
||||
ListType::const_iterator i;
|
||||
int counter = 0;
|
||||
for(i = mList.begin(); i != mList.end(); i++, counter++)
|
||||
for (i = mList.begin(); i != mList.end(); i++, counter++)
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ protected:
|
|||
class cErrorQueue : public cErrorBucket, public iTypedSerializable
|
||||
{
|
||||
friend class cErrorQueueIter;
|
||||
|
||||
public:
|
||||
void Clear();
|
||||
// remove all errors from the queue
|
||||
|
@ -109,7 +110,7 @@ public:
|
|||
//
|
||||
// iSerializable interface
|
||||
//
|
||||
virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Read(iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
||||
|
||||
//
|
||||
|
@ -119,6 +120,7 @@ public:
|
|||
|
||||
protected:
|
||||
virtual void HandleError(const eError& error);
|
||||
|
||||
private:
|
||||
typedef std::list<ePoly> ListType;
|
||||
ListType mList;
|
||||
|
@ -131,7 +133,9 @@ class cErrorQueueIter
|
|||
public:
|
||||
cErrorQueueIter(cErrorQueue& queue);
|
||||
cErrorQueueIter(const cErrorQueue& queue);
|
||||
~cErrorQueueIter() {}
|
||||
~cErrorQueueIter()
|
||||
{
|
||||
}
|
||||
|
||||
// iteration methods
|
||||
void SeekBegin();
|
||||
|
@ -153,9 +157,14 @@ private:
|
|||
//////////////////////////////////////////////////////
|
||||
class cErrorBucketNull : public cErrorBucket
|
||||
{
|
||||
virtual void AddError(const eError& ) {}
|
||||
virtual void AddError(const eError&)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void HandleError(const eError& ) {}
|
||||
virtual void HandleError(const eError&)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
|
@ -165,10 +174,10 @@ protected:
|
|||
class cErrorBucketPassThru : public cErrorBucket
|
||||
{
|
||||
protected:
|
||||
virtual void HandleError(const eError& ) {}
|
||||
virtual void HandleError(const eError&)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -38,12 +38,11 @@
|
|||
|
||||
#include "error.h"
|
||||
|
||||
TSS_EXCEPTION( eErrorGeneral, eError );
|
||||
TSS_EXCEPTION( eOpen, eErrorGeneral );
|
||||
TSS_EXCEPTION( eOpenRead, eErrorGeneral );
|
||||
TSS_EXCEPTION( eOpenWrite, eErrorGeneral );
|
||||
TSS_EXCEPTION( eBadCmdLine, eErrorGeneral );
|
||||
TSS_EXCEPTION( eBadModeSwitch, eErrorGeneral );
|
||||
TSS_EXCEPTION(eErrorGeneral, eError);
|
||||
TSS_EXCEPTION(eOpen, eErrorGeneral);
|
||||
TSS_EXCEPTION(eOpenRead, eErrorGeneral);
|
||||
TSS_EXCEPTION(eOpenWrite, eErrorGeneral);
|
||||
TSS_EXCEPTION(eBadCmdLine, eErrorGeneral);
|
||||
TSS_EXCEPTION(eBadModeSwitch, eErrorGeneral);
|
||||
|
||||
#endif //#ifndef __ERRORGENERAL_H
|
||||
|
||||
|
|
|
@ -64,18 +64,18 @@ void cErrorTable::AssertMsgValidity(const TCHAR* msg)
|
|||
if (errSize == TSTRING::npos)
|
||||
errSize = errStr.length();
|
||||
|
||||
#if 0 //TODO: Figure out how to do this properly.
|
||||
# if 0 //TODO: Figure out how to do this properly.
|
||||
TSTRING::size_type errorSize = TSS_GetString( cCore, core::STR_ERROR_ERROR ).length();
|
||||
TSTRING::size_type warningSize = TSS_GetString( cCore, core::STR_ERROR_WARNING ).length();
|
||||
TSTRING::size_type maxHeaderSize = (errorSize > warningSize ? errorSize : warningSize) + 6; // Add 6 to account for "### ' and ': '
|
||||
#else
|
||||
# else
|
||||
// Sunpro got stuck in an infinite loop when we called GetString from this func;
|
||||
TSTRING::size_type errorSize = 9;
|
||||
TSTRING::size_type warningSize = 10;
|
||||
TSTRING::size_type maxHeaderSize = (errorSize > warningSize ? errorSize : warningSize) + 6; // Add 6 to account for "### ' and ': '
|
||||
#endif
|
||||
TSTRING::size_type maxHeaderSize =
|
||||
(errorSize > warningSize ? errorSize : warningSize) + 6; // Add 6 to account for "### ' and ': '
|
||||
# endif
|
||||
|
||||
ASSERT(maxHeaderSize + errSize < 80);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -59,25 +59,25 @@ public:
|
|||
//
|
||||
// Convenience Methods
|
||||
//
|
||||
void Put( const eError& e, const TCHAR* msg );
|
||||
void Put(const eError& e, const TCHAR* msg);
|
||||
//
|
||||
// Singleton Interface
|
||||
//
|
||||
static cErrorTable* GetInstance();
|
||||
|
||||
private:
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
static void AssertMsgValidity(const TCHAR* msg);
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
inline void cErrorTable::Put( const eError& e, const TCHAR* msg )
|
||||
inline void cErrorTable::Put(const eError& e, const TCHAR* msg)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
AssertMsgValidity(msg);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
inherited::Put( e.GetID(), msg );
|
||||
inherited::Put(e.GetID(), msg);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -109,32 +109,27 @@ inline void cErrorTable::Put( const eError& e, const TCHAR* msg )
|
|||
//===================
|
||||
// cpp file macros
|
||||
//===================
|
||||
#define TSS_BEGIN_ERROR_REGISTRATION( pkgName ) \
|
||||
# define TSS_BEGIN_ERROR_REGISTRATION(pkgName) \
|
||||
RegisterErrors##pkgName::RegisterErrors##pkgName() \
|
||||
{
|
||||
|
||||
#define TSS_REGISTER_ERROR( err, str ) \
|
||||
cErrorTable::GetInstance()->Put \
|
||||
( err, str );
|
||||
# define TSS_REGISTER_ERROR(err, str) cErrorTable::GetInstance()->Put(err, str);
|
||||
|
||||
#define TSS_END_ERROR_REGISTRATION() \
|
||||
}
|
||||
# define TSS_END_ERROR_REGISTRATION() }
|
||||
|
||||
//===================
|
||||
// h file macros
|
||||
//===================
|
||||
#define TSS_DECLARE_ERROR_REGISTRATION( pkgName ) \
|
||||
# define TSS_DECLARE_ERROR_REGISTRATION(pkgName) \
|
||||
struct RegisterErrors##pkgName \
|
||||
{\
|
||||
{ \
|
||||
RegisterErrors##pkgName(); \
|
||||
};
|
||||
|
||||
//===================
|
||||
// package init macros
|
||||
//===================
|
||||
#define TSS_REGISTER_PKG_ERRORS( pkgName ) \
|
||||
RegisterErrors##pkgName register##pkgName;
|
||||
# define TSS_REGISTER_PKG_ERRORS(pkgName) RegisterErrors##pkgName register##pkgName;
|
||||
|
||||
|
||||
#endif //__ERRORTABLE_H
|
||||
|
||||
|
|
|
@ -42,15 +42,14 @@
|
|||
|
||||
namespace //unique
|
||||
{
|
||||
TCHAR* tw_itot( int value, TCHAR* string, int radix, int size)
|
||||
{
|
||||
snprintf( string, size, "%d", value );
|
||||
TCHAR* tw_itot(int value, TCHAR* string, int radix, int size)
|
||||
{
|
||||
snprintf(string, size, "%d", value);
|
||||
return string;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
eInternal::eInternal(TCHAR* sourceFile, int lineNum)
|
||||
: eError(_T(""))
|
||||
eInternal::eInternal(TCHAR* sourceFile, int lineNum) : eError(_T(""))
|
||||
{
|
||||
TCHAR buf[256];
|
||||
|
||||
|
@ -67,18 +66,17 @@ eInternal::eInternal(TCHAR* sourceFile, int lineNum)
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// MakeFileError
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
TSTRING cErrorUtil::MakeFileError( const TSTRING& msg, const TSTRING& fileName )
|
||||
TSTRING cErrorUtil::MakeFileError(const TSTRING& msg, const TSTRING& fileName)
|
||||
{
|
||||
TSTRING ret;
|
||||
ret = TSS_GetString( cCore, core::STR_ERR2_FILENAME );
|
||||
ret.append( fileName );
|
||||
ret.append( 1, _T('\n') );
|
||||
ret = TSS_GetString(cCore, core::STR_ERR2_FILENAME);
|
||||
ret.append(fileName);
|
||||
ret.append(1, _T('\n'));
|
||||
|
||||
if ( msg.length() > 0 )
|
||||
if (msg.length() > 0)
|
||||
{
|
||||
ret.append(msg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,16 +58,16 @@ public:
|
|||
//-------------------------------------------------------------------------
|
||||
// Construction and Assignment
|
||||
//-------------------------------------------------------------------------
|
||||
ePoly( uint32 id, const TSTRING& msg, uint32 flags = 0 );
|
||||
explicit ePoly( const eError& rhs );
|
||||
ePoly(uint32 id, const TSTRING& msg, uint32 flags = 0);
|
||||
explicit ePoly(const eError& rhs);
|
||||
explicit ePoly();
|
||||
void operator=( const eError& rhs );
|
||||
void operator=(const eError& rhs);
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// ID manipulation
|
||||
//-------------------------------------------------------------------------
|
||||
virtual uint32 GetID() const;
|
||||
void SetID( uint32 id );
|
||||
void SetID(uint32 id);
|
||||
|
||||
private:
|
||||
uint32 mID;
|
||||
|
@ -76,9 +76,9 @@ private:
|
|||
//-----------------------------------------------------------------------------
|
||||
// eInternal
|
||||
//-----------------------------------------------------------------------------
|
||||
TSS_BEGIN_EXCEPTION( eInternal, eError )
|
||||
TSS_BEGIN_EXCEPTION(eInternal, eError)
|
||||
public:
|
||||
eInternal( TCHAR* file, int lineNum );
|
||||
eInternal(TCHAR* file, int lineNum);
|
||||
TSS_END_EXCEPTION()
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -87,7 +87,7 @@ TSS_END_EXCEPTION()
|
|||
class cErrorUtil
|
||||
{
|
||||
public:
|
||||
static TSTRING MakeFileError( const TSTRING& msg, const TSTRING& fileName );
|
||||
static TSTRING MakeFileError(const TSTRING& msg, const TSTRING& fileName);
|
||||
// constructs an error message of the form:
|
||||
// File: <fileName> \n <msg>
|
||||
// This is useful for constructing strings to pass as the msg parameter
|
||||
|
@ -108,7 +108,11 @@ public:
|
|||
|
||||
// TODO: ASSERT is always fatal in Unix, perhaps we could #ifdef the ASSERT
|
||||
// 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,17 +122,14 @@ public:
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ePoly
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline ePoly::ePoly( uint32 id, const TSTRING& msg, uint32 flags )
|
||||
: eError( msg, flags ),
|
||||
mID( id )
|
||||
inline ePoly::ePoly(uint32 id, const TSTRING& msg, uint32 flags) : eError(msg, flags), mID(id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ePoly
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline ePoly::ePoly( const eError& rhs )
|
||||
inline ePoly::ePoly(const eError& rhs)
|
||||
{
|
||||
*this = rhs;
|
||||
}
|
||||
|
@ -136,17 +137,14 @@ inline ePoly::ePoly( const eError& rhs )
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ePoly
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline ePoly::ePoly()
|
||||
: eError( _T("") ),
|
||||
mID( 0 )
|
||||
inline ePoly::ePoly() : eError(_T("")), mID(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// operator=
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline void ePoly::operator=( const eError& rhs )
|
||||
inline void ePoly::operator=(const eError& rhs)
|
||||
{
|
||||
mMsg = rhs.GetMsg();
|
||||
mFlags = rhs.GetFlags();
|
||||
|
@ -164,10 +162,9 @@ inline uint32 ePoly::GetID() const
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// SetID
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline void ePoly::SetID( uint32 id )
|
||||
inline void ePoly::SetID(uint32 id)
|
||||
{
|
||||
mID = id;
|
||||
}
|
||||
|
||||
#endif //__ERRORUTIL_H
|
||||
|
||||
|
|
|
@ -55,17 +55,17 @@
|
|||
// eFile exception class
|
||||
//=============================================================================
|
||||
|
||||
TSS_FILE_EXCEPTION( eFile, eFileError );
|
||||
TSS_FILE_EXCEPTION( eFileOpen, eFile );
|
||||
TSS_FILE_EXCEPTION( eFileWrite, eFile );
|
||||
TSS_FILE_EXCEPTION( eFileRead, eFile );
|
||||
TSS_FILE_EXCEPTION( eFileEOF, eFile ); // never used!
|
||||
TSS_FILE_EXCEPTION( eFileSeek, eFile );
|
||||
TSS_FILE_EXCEPTION( eFileInvalidOp, eFile ); // never used!
|
||||
TSS_FILE_EXCEPTION( eFileTrunc, eFile );
|
||||
TSS_FILE_EXCEPTION( eFileClose, eFile ); // never used!
|
||||
TSS_FILE_EXCEPTION( eFileFlush, eFile );
|
||||
TSS_FILE_EXCEPTION( eFileRewind, eFile );
|
||||
TSS_FILE_EXCEPTION(eFile, eFileError);
|
||||
TSS_FILE_EXCEPTION(eFileOpen, eFile);
|
||||
TSS_FILE_EXCEPTION(eFileWrite, eFile);
|
||||
TSS_FILE_EXCEPTION(eFileRead, eFile);
|
||||
TSS_FILE_EXCEPTION(eFileEOF, eFile); // never used!
|
||||
TSS_FILE_EXCEPTION(eFileSeek, eFile);
|
||||
TSS_FILE_EXCEPTION(eFileInvalidOp, eFile); // never used!
|
||||
TSS_FILE_EXCEPTION(eFileTrunc, eFile);
|
||||
TSS_FILE_EXCEPTION(eFileClose, eFile); // never used!
|
||||
TSS_FILE_EXCEPTION(eFileFlush, eFile);
|
||||
TSS_FILE_EXCEPTION(eFileRewind, eFile);
|
||||
|
||||
//=============================================================================
|
||||
// cFile
|
||||
|
@ -88,8 +88,10 @@ public:
|
|||
// note that reading from the file is implicit
|
||||
OPEN_READ = 0x00000001, // not needed, but makes calls nice...
|
||||
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_TRUNCATE = 0x00000008, // opens an empty file. creates it if it doesn't exist. Doesn't make much sense without OF_WRITE
|
||||
OPEN_LOCKED_TEMP =
|
||||
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_TEXT = 0x00000020,
|
||||
OPEN_EXCLUSIVE = 0x00000040, // Use O_CREAT | O_EXCL
|
||||
|
@ -98,37 +100,37 @@ public:
|
|||
};
|
||||
|
||||
//Ctor, Dtor, CpyCtor, Operator=:
|
||||
cFile ( void );
|
||||
~cFile ( void );
|
||||
cFile(void);
|
||||
~cFile(void);
|
||||
|
||||
/************ User Interface **************************/
|
||||
|
||||
// Both Open methods ALWAYS open files in BINARY mode!
|
||||
void Open ( const TSTRING& sFileName, uint32 flags = OPEN_READ ); //throw(eFile)
|
||||
void Close ( void ); //throw(eFile)
|
||||
bool IsOpen ( void ) const;
|
||||
void Open(const TSTRING& sFileName, uint32 flags = OPEN_READ); //throw(eFile)
|
||||
void Close(void); //throw(eFile)
|
||||
bool IsOpen(void) const;
|
||||
|
||||
File_t Seek ( File_t offset, SeekFrom From ) const; //throw(eFile)
|
||||
File_t Seek(File_t offset, SeekFrom From) const; //throw(eFile)
|
||||
// Seek returns the current offset after completion
|
||||
File_t Read ( void* buffer, File_t nBytes ) const; //throw(eFile)
|
||||
File_t Read(void* buffer, File_t nBytes) const; //throw(eFile)
|
||||
// Read returns the number of bytes that are actually read. If the nBytes
|
||||
// parameter is 0, 0 bytes will be read and buffer will remain untouched.
|
||||
// If the read head is at EOF, no bytes will be read and 0 will be returned.
|
||||
File_t Write ( const void* buffer, File_t nBytes ); //throw(eFile)
|
||||
File_t Write(const void* buffer, File_t nBytes); //throw(eFile)
|
||||
// Write returns the number of bytes that are actually written.
|
||||
File_t Tell ( void ) const;
|
||||
File_t Tell(void) const;
|
||||
// Tell returns the current offset.
|
||||
bool Flush ( void ); //throw(eFile)
|
||||
bool Flush(void); //throw(eFile)
|
||||
// Flush returns 0 if the currently defined stream is successfully flushed.
|
||||
void Rewind ( void ) const; //throw(eFile)
|
||||
void Rewind(void) const; //throw(eFile)
|
||||
// Sets the offset to 0.
|
||||
File_t GetSize ( void ) const;
|
||||
File_t GetSize(void) const;
|
||||
// Returns the size of the current file in bytes. Returns -1 if no file is defined.
|
||||
void Truncate ( File_t offset ); // throw(eFile)
|
||||
void Truncate(File_t offset); // throw(eFile)
|
||||
|
||||
private:
|
||||
cFile ( const cFile& rhs ); //not impl.
|
||||
cFile& operator= ( const cFile& rhs); //not impl.
|
||||
cFile(const cFile& rhs); //not impl.
|
||||
cFile& operator=(const cFile& rhs); //not impl.
|
||||
|
||||
//Pointer to the insulated implementation
|
||||
cFile_i* mpData;
|
||||
|
@ -171,16 +173,15 @@ public:
|
|||
static bool IsAbsolutePath(const TSTRING& in);
|
||||
};
|
||||
|
||||
#if IS_DOS_DJGPP
|
||||
#define cDevicePath cDosPath
|
||||
#elif IS_AROS
|
||||
#define cDevicePath cArosPath
|
||||
#elif IS_RISCOS
|
||||
#define cDevicePath cRiscosPath
|
||||
#elif IS_REDOX
|
||||
#define cDevicePath cRedoxPath
|
||||
#endif
|
||||
# if IS_DOS_DJGPP
|
||||
# define cDevicePath cDosPath
|
||||
# elif IS_AROS
|
||||
# define cDevicePath cArosPath
|
||||
# elif IS_RISCOS
|
||||
# define cDevicePath cRiscosPath
|
||||
# elif IS_REDOX
|
||||
# define cDevicePath cRedoxPath
|
||||
# endif
|
||||
|
||||
|
||||
#endif //__FILE_H
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include "core/stdcore.h"
|
||||
|
||||
#if !IS_UNIX
|
||||
#error Need to be unix to use unixfsservices
|
||||
# error Need to be unix to use unixfsservices
|
||||
#endif
|
||||
|
||||
#include "core/file.h"
|
||||
|
@ -54,7 +54,7 @@
|
|||
#include <errno.h>
|
||||
|
||||
#if HAVE_SYS_FS_VX_IOCTL_H
|
||||
# include <sys/fs/vx_ioctl.h>
|
||||
#include <sys/fs/vx_ioctl.h>
|
||||
#endif
|
||||
|
||||
#include "core/debug.h"
|
||||
|
@ -82,25 +82,25 @@ struct cFile_i
|
|||
};
|
||||
|
||||
//Ctor
|
||||
cFile_i::cFile_i() :
|
||||
m_fd(-1), mpCurrStream(NULL), mFlags(0)
|
||||
{}
|
||||
cFile_i::cFile_i() : m_fd(-1), mpCurrStream(NULL), mFlags(0)
|
||||
{
|
||||
}
|
||||
|
||||
//Dtor
|
||||
cFile_i::~cFile_i()
|
||||
{
|
||||
if (mpCurrStream != NULL)
|
||||
{
|
||||
fclose( mpCurrStream );
|
||||
fclose(mpCurrStream);
|
||||
mpCurrStream = NULL;
|
||||
|
||||
#if !CAN_UNLINK_WHILE_OPEN // so unlink after close instead
|
||||
if( mFlags & cFile::OPEN_LOCKED_TEMP )
|
||||
if (mFlags & cFile::OPEN_LOCKED_TEMP)
|
||||
{
|
||||
// unlink this file
|
||||
if( 0 != unlink(mFileName.c_str()))
|
||||
if (0 != unlink(mFileName.c_str()))
|
||||
{
|
||||
throw( eFileOpen( mFileName, iFSServices::GetInstance()->GetErrString() ) );
|
||||
throw(eFileOpen(mFileName, iFSServices::GetInstance()->GetErrString()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -113,15 +113,14 @@ cFile_i::~cFile_i()
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cFile::cFile() :
|
||||
mpData(NULL), isWritable(false)
|
||||
cFile::cFile() : mpData(NULL), isWritable(false)
|
||||
{
|
||||
mpData = new cFile_i;
|
||||
}
|
||||
|
||||
cFile::~cFile()
|
||||
{
|
||||
if( mpData != NULL)
|
||||
if (mpData != NULL)
|
||||
{
|
||||
delete mpData;
|
||||
mpData = NULL;
|
||||
|
@ -133,10 +132,10 @@ cFile::~cFile()
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !USES_DEVICE_PATH
|
||||
void cFile::Open( const TSTRING& sFileName, uint32 flags )
|
||||
void cFile::Open(const TSTRING& sFileName, uint32 flags)
|
||||
{
|
||||
#else
|
||||
void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
|
||||
void cFile::Open(const TSTRING& sFileNameC, uint32 flags)
|
||||
{
|
||||
TSTRING sFileName = cDevicePath::AsNative(sFileNameC);
|
||||
#endif
|
||||
|
@ -174,9 +173,10 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
|
|||
mode = _T("rb");
|
||||
}
|
||||
|
||||
if (flags & OPEN_EXCLUSIVE) {
|
||||
if (flags & OPEN_EXCLUSIVE)
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
if (flags & OPEN_CREATE)
|
||||
|
@ -202,22 +202,22 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
|
|||
//
|
||||
// actually open the file
|
||||
//
|
||||
int fh = _topen( sFileName.c_str(), perm, openmode );
|
||||
if( fh == -1 )
|
||||
int fh = _topen(sFileName.c_str(), perm, openmode);
|
||||
if (fh == -1)
|
||||
{
|
||||
throw( eFileOpen( sFileName, iFSServices::GetInstance()->GetErrString() ) );
|
||||
throw(eFileOpen(sFileName, iFSServices::GetInstance()->GetErrString()));
|
||||
}
|
||||
mpData->m_fd = fh;
|
||||
|
||||
#if CAN_UNLINK_WHILE_OPEN
|
||||
if( flags & OPEN_LOCKED_TEMP )
|
||||
if (flags & OPEN_LOCKED_TEMP)
|
||||
{
|
||||
// unlink this file
|
||||
if( 0 != unlink( sFileName.c_str() ) )
|
||||
if (0 != unlink(sFileName.c_str()))
|
||||
{
|
||||
// we weren't able to unlink file, so close handle and fail
|
||||
close( fh );
|
||||
throw( eFileOpen( sFileName, iFSServices::GetInstance()->GetErrString() ) );
|
||||
close(fh);
|
||||
throw(eFileOpen(sFileName, iFSServices::GetInstance()->GetErrString()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -244,8 +244,8 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
|
|||
#if HAVE_POSIX_FADVISE
|
||||
if (flags & OPEN_SCANNING && !(flags & OPEN_DIRECT))
|
||||
{
|
||||
posix_fadvise(fh,0,0, POSIX_FADV_SEQUENTIAL);
|
||||
posix_fadvise(fh,0,0, POSIX_FADV_NOREUSE);
|
||||
posix_fadvise(fh, 0, 0, POSIX_FADV_SEQUENTIAL);
|
||||
posix_fadvise(fh, 0, 0, POSIX_FADV_NOREUSE);
|
||||
}
|
||||
|
||||
#elif HAVE_SYS_FS_VX_IOCTL_H
|
||||
|
@ -257,7 +257,6 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
|
|||
ioctl(fh, VX_SETCACHE, VX_SEQ | VX_NOREUSE);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -266,13 +265,13 @@ void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
void cFile::Close() //throw(eFile)
|
||||
{
|
||||
if(mpData->mpCurrStream != NULL)
|
||||
if (mpData->mpCurrStream != NULL)
|
||||
{
|
||||
#ifdef HAVE_POSIX_FADVISE
|
||||
posix_fadvise(fileno(mpData->mpCurrStream),0,0, POSIX_FADV_DONTNEED);
|
||||
posix_fadvise(fileno(mpData->mpCurrStream), 0, 0, POSIX_FADV_DONTNEED);
|
||||
#endif
|
||||
|
||||
fclose( mpData->mpCurrStream );
|
||||
fclose(mpData->mpCurrStream);
|
||||
mpData->mpCurrStream = NULL;
|
||||
}
|
||||
|
||||
|
@ -280,23 +279,23 @@ void cFile::Close() //throw(eFile)
|
|||
mpData->mFileName.empty();
|
||||
}
|
||||
|
||||
bool cFile::IsOpen( void ) const
|
||||
bool cFile::IsOpen(void) const
|
||||
{
|
||||
return( mpData->mpCurrStream != NULL );
|
||||
return (mpData->mpCurrStream != NULL);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Seek -- Positions the read/write offset in mpCurrStream. Returns the
|
||||
// current offset upon completion. Returns 0 if no stream is defined.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
cFile::File_t cFile::Seek( File_t offset, SeekFrom From) const //throw(eFile)
|
||||
cFile::File_t cFile::Seek(File_t offset, SeekFrom From) const //throw(eFile)
|
||||
{
|
||||
//Check to see if a file as been opened yet...
|
||||
ASSERT( mpData->mpCurrStream != 0);
|
||||
ASSERT(mpData->mpCurrStream != 0);
|
||||
|
||||
int apiFrom;
|
||||
|
||||
switch( From )
|
||||
switch (From)
|
||||
{
|
||||
case cFile::SEEK_BEGIN:
|
||||
apiFrom = SEEK_SET;
|
||||
|
@ -309,11 +308,11 @@ cFile::File_t cFile::Seek( File_t offset, SeekFrom From) const //throw(eFile)
|
|||
break;
|
||||
default:
|
||||
//An invalid SeekFrom parameter was passed.
|
||||
throw( eInternal( _T("file_unix") ) );
|
||||
throw(eInternal(_T("file_unix")));
|
||||
}
|
||||
|
||||
// this is a hack to simulate running out of disk space
|
||||
#if 0
|
||||
// this is a hack to simulate running out of disk space
|
||||
#if 0
|
||||
static int blowupCount = 1;
|
||||
if (++blowupCount == 1075)
|
||||
{
|
||||
|
@ -322,14 +321,14 @@ cFile::File_t cFile::Seek( File_t offset, SeekFrom From) const //throw(eFile)
|
|||
throw std::bad_alloc();
|
||||
}
|
||||
fprintf(stderr, "%d\n", blowupCount);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (fseeko( mpData->mpCurrStream, offset, apiFrom ) != 0)
|
||||
if (fseeko(mpData->mpCurrStream, offset, apiFrom) != 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
cDebug d("cFile::Seek");
|
||||
d.TraceDebug("Seek failed!\n");
|
||||
#endif
|
||||
#endif
|
||||
throw eFileSeek();
|
||||
}
|
||||
|
||||
|
@ -340,26 +339,31 @@ cFile::File_t cFile::Seek( File_t offset, SeekFrom From) const //throw(eFile)
|
|||
// Read -- Returns the actual bytes read from mpCurrStream. Returns 0 if
|
||||
// mpCurrStream is undefined.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
cFile::File_t cFile::Read( void* buffer, File_t nBytes ) const //throw(eFile)
|
||||
cFile::File_t cFile::Read(void* buffer, File_t nBytes) const //throw(eFile)
|
||||
{
|
||||
File_t iBytesRead;
|
||||
|
||||
// Has a file been opened?
|
||||
ASSERT( mpData->mpCurrStream != NULL );
|
||||
ASSERT(mpData->mpCurrStream != NULL);
|
||||
|
||||
// Is the nBytes parameter 0? If so, return without touching buffer:
|
||||
if( nBytes == 0 )
|
||||
if (nBytes == 0)
|
||||
return 0;
|
||||
|
||||
if (mpData->mFlags & OPEN_DIRECT) {
|
||||
if (mpData->mFlags & OPEN_DIRECT)
|
||||
{
|
||||
iBytesRead = read(mpData->m_fd, buffer, nBytes);
|
||||
if (iBytesRead<0) {
|
||||
if (iBytesRead < 0)
|
||||
{
|
||||
throw eFileRead(mpData->mFileName, iFSServices::GetInstance()->GetErrString());
|
||||
}
|
||||
} else {
|
||||
iBytesRead = fread( buffer, sizeof(byte), nBytes, mpData->mpCurrStream );
|
||||
if( ferror( mpData->mpCurrStream ) != 0 ) {
|
||||
throw eFileRead( mpData->mFileName, iFSServices::GetInstance()->GetErrString() ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
iBytesRead = fread(buffer, sizeof(byte), nBytes, mpData->mpCurrStream);
|
||||
if (ferror(mpData->mpCurrStream) != 0)
|
||||
{
|
||||
throw eFileRead(mpData->mFileName, iFSServices::GetInstance()->GetErrString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -370,16 +374,16 @@ cFile::File_t cFile::Read( void* buffer, File_t nBytes ) const //throw(eFile)
|
|||
// Write -- Returns the actual number of bytes written to mpCurrStream
|
||||
// Returns 0 if no file has been opened.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
cFile::File_t cFile::Write( const void* buffer, File_t nBytes ) //throw(eFile)
|
||||
cFile::File_t cFile::Write(const void* buffer, File_t nBytes) //throw(eFile)
|
||||
{
|
||||
File_t actual_count = 0;
|
||||
|
||||
// Has a file been opened? Is it writable?
|
||||
ASSERT( mpData->mpCurrStream != NULL );
|
||||
ASSERT( isWritable );
|
||||
ASSERT(mpData->mpCurrStream != NULL);
|
||||
ASSERT(isWritable);
|
||||
|
||||
if( ( actual_count = fwrite( buffer, sizeof(byte), nBytes, mpData->mpCurrStream ) ) < nBytes )
|
||||
throw eFileWrite( mpData->mFileName, iFSServices::GetInstance()->GetErrString() );
|
||||
if ((actual_count = fwrite(buffer, sizeof(byte), nBytes, mpData->mpCurrStream)) < nBytes)
|
||||
throw eFileWrite(mpData->mFileName, iFSServices::GetInstance()->GetErrString());
|
||||
else
|
||||
return actual_count;
|
||||
}
|
||||
|
@ -390,9 +394,9 @@ cFile::File_t cFile::Write( const void* buffer, File_t nBytes ) //throw(eFil
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
cFile::File_t cFile::Tell() const
|
||||
{
|
||||
ASSERT( mpData->mpCurrStream != 0);
|
||||
ASSERT(mpData->mpCurrStream != 0);
|
||||
|
||||
return ftell( mpData->mpCurrStream );
|
||||
return ftell(mpData->mpCurrStream);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@ -400,10 +404,10 @@ cFile::File_t cFile::Tell() const
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
bool cFile::Flush() //throw(eFile)
|
||||
{
|
||||
if ( mpData->mpCurrStream == NULL )
|
||||
throw eFileFlush( mpData->mFileName, iFSServices::GetInstance()->GetErrString() );
|
||||
if (mpData->mpCurrStream == NULL)
|
||||
throw eFileFlush(mpData->mFileName, iFSServices::GetInstance()->GetErrString());
|
||||
|
||||
return ( fflush( mpData->mpCurrStream) == 0 );
|
||||
return (fflush(mpData->mpCurrStream) == 0);
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Rewind -- Sets the offset to the beginning of the file. If mpCurrStream
|
||||
|
@ -412,11 +416,11 @@ bool cFile::Flush() //throw(eFile)
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
void cFile::Rewind() const //throw(eFile)
|
||||
{
|
||||
ASSERT( mpData->mpCurrStream != 0);
|
||||
ASSERT(mpData->mpCurrStream != 0);
|
||||
|
||||
rewind( mpData->mpCurrStream );
|
||||
if( ftell( mpData->mpCurrStream ) != 0 )
|
||||
throw( eFileRewind( mpData->mFileName, iFSServices::GetInstance()->GetErrString() ) );
|
||||
rewind(mpData->mpCurrStream);
|
||||
if (ftell(mpData->mpCurrStream) != 0)
|
||||
throw(eFileRewind(mpData->mFileName, iFSServices::GetInstance()->GetErrString()));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@ -429,11 +433,11 @@ cFile::File_t cFile::GetSize() const
|
|||
File_t ret;
|
||||
|
||||
//Has a file been opened? If not, return -1
|
||||
if( mpData->mpCurrStream == NULL )
|
||||
if (mpData->mpCurrStream == NULL)
|
||||
return -1;
|
||||
|
||||
ret = Seek( 0, cFile::SEEK_EOF );
|
||||
Seek( vCurrentOffset, cFile::SEEK_BEGIN );
|
||||
ret = Seek(0, cFile::SEEK_EOF);
|
||||
Seek(vCurrentOffset, cFile::SEEK_BEGIN);
|
||||
//return the offset to it's position prior to GetSize call.
|
||||
|
||||
return ret;
|
||||
|
@ -442,14 +446,14 @@ cFile::File_t cFile::GetSize() const
|
|||
/////////////////////////////////////////////////////////////////////////
|
||||
// Truncate
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
void cFile::Truncate( File_t offset ) // throw(eFile)
|
||||
void cFile::Truncate(File_t offset) // throw(eFile)
|
||||
{
|
||||
ASSERT( mpData->mpCurrStream != 0);
|
||||
ASSERT( isWritable );
|
||||
ASSERT(mpData->mpCurrStream != 0);
|
||||
ASSERT(isWritable);
|
||||
|
||||
ftruncate( fileno(mpData->mpCurrStream), offset );
|
||||
if( GetSize() != offset )
|
||||
throw( eFileTrunc( mpData->mFileName, iFSServices::GetInstance()->GetErrString() ) );
|
||||
ftruncate(fileno(mpData->mpCurrStream), offset);
|
||||
if (GetSize() != offset)
|
||||
throw(eFileTrunc(mpData->mFileName, iFSServices::GetInstance()->GetErrString()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -472,7 +476,7 @@ bool cDosPath::IsAbsolutePath(const TSTRING& in)
|
|||
}
|
||||
|
||||
// For paths of type C:\DOS
|
||||
TSTRING cDosPath::AsPosix( const TSTRING& in )
|
||||
TSTRING cDosPath::AsPosix(const TSTRING& in)
|
||||
{
|
||||
if (in[0] == '/')
|
||||
{
|
||||
|
@ -481,12 +485,12 @@ TSTRING cDosPath::AsPosix( const TSTRING& in )
|
|||
|
||||
TSTRING out = (cDosPath::IsAbsolutePath(in)) ? ("/dev/" + in) : in;
|
||||
std::replace(out.begin(), out.end(), '\\', '/');
|
||||
out.erase( std::remove(out.begin(), out.end(), ':'), out.end());
|
||||
out.erase(std::remove(out.begin(), out.end(), ':'), out.end());
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
TSTRING cDosPath::AsNative( const TSTRING& in )
|
||||
TSTRING cDosPath::AsNative(const TSTRING& in)
|
||||
{
|
||||
if (in[0] != '/')
|
||||
{
|
||||
|
@ -507,15 +511,15 @@ TSTRING cDosPath::AsNative( const TSTRING& in )
|
|||
return out;
|
||||
}
|
||||
|
||||
TSTRING cDosPath::BackupName( const TSTRING& in )
|
||||
TSTRING cDosPath::BackupName(const TSTRING& in)
|
||||
{
|
||||
TSTRING out = in;
|
||||
std::string::size_type pos = out.find_last_of("\\");
|
||||
if( std::string::npos == pos)
|
||||
if (std::string::npos == pos)
|
||||
return in;
|
||||
|
||||
TSTRING path = in.substr(0, pos);
|
||||
TSTRING name = in.substr(pos,9);
|
||||
TSTRING name = in.substr(pos, 9);
|
||||
std::replace(name.begin(), name.end(), '.', '_');
|
||||
path.append(name);
|
||||
|
||||
|
@ -538,7 +542,7 @@ bool cArosPath::IsAbsolutePath(const TSTRING& in)
|
|||
}
|
||||
|
||||
// For paths of type DH0:dir/file
|
||||
TSTRING cArosPath::AsPosix( const TSTRING& in )
|
||||
TSTRING cArosPath::AsPosix(const TSTRING& in)
|
||||
{
|
||||
if (in[0] == '/')
|
||||
{
|
||||
|
@ -551,7 +555,7 @@ TSTRING cArosPath::AsPosix( const TSTRING& in )
|
|||
return out;
|
||||
}
|
||||
|
||||
TSTRING cArosPath::AsNative( const TSTRING& in )
|
||||
TSTRING cArosPath::AsNative(const TSTRING& in)
|
||||
{
|
||||
if (in[0] != '/')
|
||||
{
|
||||
|
@ -561,7 +565,7 @@ TSTRING cArosPath::AsNative( const TSTRING& in )
|
|||
std::string::size_type drive = in.find_first_not_of("/");
|
||||
TSTRING out = (drive != std::string::npos) ? in.substr(drive) : in;
|
||||
TSTRING::size_type t = out.find_first_of('/');
|
||||
if(t != std::string::npos)
|
||||
if (t != std::string::npos)
|
||||
out[t] = ':';
|
||||
else
|
||||
out.append(":");
|
||||
|
@ -585,7 +589,7 @@ bool cRiscosPath::IsAbsolutePath(const TSTRING& in)
|
|||
}
|
||||
|
||||
// For paths of type SDFS::Volume.$.dir.file
|
||||
TSTRING cRiscosPath::AsPosix( const TSTRING& in )
|
||||
TSTRING cRiscosPath::AsPosix(const TSTRING& in)
|
||||
{
|
||||
#if IS_RISCOS
|
||||
if (in[0] == '/')
|
||||
|
@ -594,8 +598,8 @@ TSTRING cRiscosPath::AsPosix( const TSTRING& in )
|
|||
}
|
||||
|
||||
TSTRING out;
|
||||
char* unixified = __unixify(in.c_str(), 0,0,0,0);
|
||||
if(unixified)
|
||||
char* unixified = __unixify(in.c_str(), 0, 0, 0, 0);
|
||||
if (unixified)
|
||||
{
|
||||
out.assign(unixified);
|
||||
free(unixified);
|
||||
|
@ -608,7 +612,7 @@ TSTRING cRiscosPath::AsPosix( const TSTRING& in )
|
|||
#endif
|
||||
}
|
||||
|
||||
TSTRING cRiscosPath::AsNative( const TSTRING& in )
|
||||
TSTRING cRiscosPath::AsNative(const TSTRING& in)
|
||||
{
|
||||
#if IS_RISCOS
|
||||
if (in[0] != '/')
|
||||
|
@ -619,8 +623,8 @@ TSTRING cRiscosPath::AsNative( const TSTRING& in )
|
|||
TSTRING out;
|
||||
int buf_size = in.length() + 100; // examples pad by 100
|
||||
std::vector<char> buf(buf_size);
|
||||
__riscosify(in.c_str(), 0,0, &buf[0], buf_size, 0);
|
||||
if(buf[0])
|
||||
__riscosify(in.c_str(), 0, 0, &buf[0], buf_size, 0);
|
||||
if (buf[0])
|
||||
{
|
||||
out.assign(&buf[0]);
|
||||
return out;
|
||||
|
@ -648,7 +652,7 @@ bool cRedoxPath::IsAbsolutePath(const TSTRING& in)
|
|||
}
|
||||
|
||||
// For paths of type file:/dir/file
|
||||
TSTRING cRedoxPath::AsPosix( const TSTRING& in )
|
||||
TSTRING cRedoxPath::AsPosix(const TSTRING& in)
|
||||
{
|
||||
if (in[0] == '/')
|
||||
{
|
||||
|
@ -657,12 +661,12 @@ TSTRING cRedoxPath::AsPosix( const TSTRING& in )
|
|||
|
||||
TSTRING out = IsAbsolutePath(in) ? '/' + in : in;
|
||||
std::string::size_type colon = out.find_first_of(":");
|
||||
if( colon != std::string::npos )
|
||||
if (colon != std::string::npos)
|
||||
out.erase(colon, 1);
|
||||
return out;
|
||||
}
|
||||
|
||||
TSTRING cRedoxPath::AsNative( const TSTRING& in )
|
||||
TSTRING cRedoxPath::AsNative(const TSTRING& in)
|
||||
{
|
||||
if (in[0] != '/')
|
||||
{
|
||||
|
@ -672,7 +676,7 @@ TSTRING cRedoxPath::AsNative( const TSTRING& in )
|
|||
std::string::size_type drive = in.find_first_not_of("/");
|
||||
TSTRING out = (drive != std::string::npos) ? in.substr(drive) : in;
|
||||
TSTRING::size_type slash = out.find_first_of('/');
|
||||
if(slash != std::string::npos)
|
||||
if (slash != std::string::npos)
|
||||
out.insert(slash, ":");
|
||||
else
|
||||
out.append(":/");
|
||||
|
|
|
@ -37,8 +37,7 @@
|
|||
#include "corestrings.h"
|
||||
|
||||
// TODO: Make this use MakeFileError() for consistency
|
||||
eFileError::eFileError( const TSTRING& filename, const TSTRING& description, uint32 flags )
|
||||
: eError( _T(""), flags )
|
||||
eFileError::eFileError(const TSTRING& filename, const TSTRING& description, uint32 flags) : eError(_T(""), flags)
|
||||
{
|
||||
mFilename = filename;
|
||||
mMsg = description;
|
||||
|
@ -58,14 +57,14 @@ TSTRING eFileError::GetDescription() const
|
|||
{
|
||||
TSTRING ret;
|
||||
|
||||
if( ! mFilename.empty() )
|
||||
if (!mFilename.empty())
|
||||
{
|
||||
ret = TSS_GetString( cCore, core::STR_ERROR_FILENAME ) + mFilename;
|
||||
ret = TSS_GetString(cCore, core::STR_ERROR_FILENAME) + mFilename;
|
||||
}
|
||||
|
||||
if( ! mMsg.empty() )
|
||||
if (!mMsg.empty())
|
||||
{
|
||||
if ( ! mFilename.empty() )
|
||||
if (!mFilename.empty())
|
||||
ret += _T("\n");
|
||||
|
||||
ret += mMsg;
|
||||
|
@ -73,4 +72,3 @@ TSTRING eFileError::GetDescription() const
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,30 +51,33 @@
|
|||
// ### Insufficient permission to open file. <-- constructor parameter "msg"
|
||||
// ### Exiting... <-- appropriate third message
|
||||
//=============================================================================
|
||||
TSS_BEGIN_EXCEPTION_NO_CTOR( eFileError, eError )
|
||||
TSS_BEGIN_EXCEPTION_NO_CTOR(eFileError, eError)
|
||||
private:
|
||||
TSTRING mFilename;
|
||||
TSTRING mFilename;
|
||||
|
||||
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 )
|
||||
: eError( rhs ) { mFilename = rhs.mFilename; }
|
||||
eFileError( const TSTRING& msg, uint32 flags = 0 )
|
||||
: eError( msg, flags ) {}
|
||||
explicit eFileError(const eFileError& rhs) : eError(rhs)
|
||||
{
|
||||
mFilename = rhs.mFilename;
|
||||
}
|
||||
eFileError(const TSTRING& msg, uint32 flags = 0) : eError(msg, flags)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TSTRING GetFilename() const;
|
||||
TSTRING GetDescription() const;
|
||||
virtual TSTRING GetMsg() const;
|
||||
TSTRING GetFilename() const;
|
||||
TSTRING GetDescription() const;
|
||||
virtual TSTRING GetMsg() const;
|
||||
|
||||
TSS_END_EXCEPTION()
|
||||
|
||||
#define TSS_FILE_EXCEPTION( except, base ) \
|
||||
TSS_BEGIN_EXCEPTION( except, base ) \
|
||||
except( const TSTRING& filename, const TSTRING& msg, uint32 flags = 0 ) \
|
||||
: base( filename, msg, flags ) {} \
|
||||
# define TSS_FILE_EXCEPTION(except, base) \
|
||||
TSS_BEGIN_EXCEPTION(except, base) \
|
||||
except(const TSTRING& filename, const TSTRING& msg, uint32 flags = 0) : base(filename, msg, flags) \
|
||||
{ \
|
||||
} \
|
||||
TSS_END_EXCEPTION()
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ cFileHeaderID::~cFileHeaderID()
|
|||
{
|
||||
}
|
||||
|
||||
void cFileHeaderID::operator=( const TCHAR* pszId )
|
||||
void cFileHeaderID::operator=(const TCHAR* pszId)
|
||||
{
|
||||
// RAD:10/1/99 -- Not Needed
|
||||
// TODO:BAM -- I'm pretty sure that there's a bug hiding here...
|
||||
|
@ -62,36 +62,34 @@ void cFileHeaderID::operator=( const TCHAR* pszId )
|
|||
// return;
|
||||
//}
|
||||
|
||||
size_t N = ::strlen( pszId );
|
||||
if ( !(N < cFileHeaderID::MAXBYTES) )
|
||||
throw eCharacter( TSS_GetString( cCore, core::STR_ERR_OVERFLOW ) );
|
||||
size_t N = ::strlen(pszId);
|
||||
if (!(N < cFileHeaderID::MAXBYTES))
|
||||
throw eCharacter(TSS_GetString(cCore, core::STR_ERR_OVERFLOW));
|
||||
|
||||
mIDLen = static_cast<int16>( N ); // know len is less than MAXBYTES
|
||||
::memcpy( mID, pszId, N * sizeof(char) );
|
||||
mIDLen = static_cast<int16>(N); // know len is less than MAXBYTES
|
||||
::memcpy(mID, pszId, N * sizeof(char));
|
||||
}
|
||||
|
||||
void cFileHeaderID::operator=( const cFileHeaderID& rhs )
|
||||
void cFileHeaderID::operator=(const cFileHeaderID& rhs)
|
||||
{
|
||||
ASSERT( rhs.mIDLen < cFileHeaderID::MAXBYTES );
|
||||
ASSERT(rhs.mIDLen < cFileHeaderID::MAXBYTES);
|
||||
mIDLen = rhs.mIDLen;
|
||||
memcpy(mID, rhs.mID, mIDLen * sizeof(char));
|
||||
}
|
||||
|
||||
int cFileHeaderID::operator==( const cFileHeaderID& rhs ) const
|
||||
int cFileHeaderID::operator==(const cFileHeaderID& rhs) const
|
||||
{
|
||||
return
|
||||
( mIDLen == rhs.mIDLen ) &&
|
||||
( ::memcmp( mID, rhs.mID, mIDLen * sizeof(char) ) == 0 );
|
||||
return (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)
|
||||
{
|
||||
int16 len;
|
||||
pSerializer->ReadInt16( len );
|
||||
if ( (len < 0) || (len >= cFileHeaderID::MAXBYTES ))
|
||||
pSerializer->ReadInt16(len);
|
||||
if ((len < 0) || (len >= cFileHeaderID::MAXBYTES))
|
||||
{
|
||||
// this is invalid!
|
||||
throw eSerializerInputStreamFmt( _T("File Header ID invalid") );
|
||||
throw eSerializerInputStreamFmt(_T("File Header ID invalid"));
|
||||
}
|
||||
pSerializer->ReadBlob(mID, len * sizeof(char));
|
||||
mIDLen = len;
|
||||
|
@ -99,17 +97,16 @@ void cFileHeaderID::Read(iSerializer* pSerializer, int32 /*version*/ ) // throw
|
|||
|
||||
void cFileHeaderID::Write(iSerializer* pSerializer) const // throw (eSerializer, eArchive)
|
||||
{
|
||||
ASSERT( mIDLen >= 0 && mIDLen < cFileHeaderID::MAXBYTES );
|
||||
ASSERT(mIDLen >= 0 && mIDLen < cFileHeaderID::MAXBYTES);
|
||||
|
||||
pSerializer->WriteInt16( mIDLen );
|
||||
pSerializer->WriteBlob( mID, mIDLen * sizeof(char) );
|
||||
pSerializer->WriteInt16(mIDLen);
|
||||
pSerializer->WriteBlob(mID, mIDLen * sizeof(char));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// class cFileHeader
|
||||
|
||||
cFileHeader::cFileHeader()
|
||||
: mVersion(0)
|
||||
cFileHeader::cFileHeader() : mVersion(0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
mEncoding = LAST_ENCODING; // set to invalid value so we can assert on write
|
||||
|
@ -119,20 +116,14 @@ cFileHeader::cFileHeader()
|
|||
}
|
||||
|
||||
cFileHeader::cFileHeader(const cFileHeader& rhs)
|
||||
: iSerializable(),
|
||||
mID(rhs.mID),
|
||||
mVersion(rhs.mVersion),
|
||||
mEncoding(rhs.mEncoding)
|
||||
: iSerializable(), mID(rhs.mID), mVersion(rhs.mVersion), mEncoding(rhs.mEncoding)
|
||||
{
|
||||
if (rhs.mBaggage.Length() > 0)
|
||||
{
|
||||
mBaggage.MapArchive(0, rhs.mBaggage.Length());
|
||||
rhs.mBaggage.MapArchive(0, rhs.mBaggage.Length());
|
||||
|
||||
::memcpy(
|
||||
mBaggage.GetMap(),
|
||||
rhs.mBaggage.GetMap(),
|
||||
static_cast<size_t>( rhs.mBaggage.Length() ) );
|
||||
::memcpy(mBaggage.GetMap(), rhs.mBaggage.GetMap(), static_cast<size_t>(rhs.mBaggage.Length()));
|
||||
|
||||
mBaggage.MapArchive(0, 0);
|
||||
rhs.mBaggage.MapArchive(0, 0);
|
||||
|
@ -171,7 +162,7 @@ void cFileHeader::Read(iSerializer* pSerializer, int32 /*version*/) // throw (eS
|
|||
if ((unsigned int)magicNumber != FILE_HEADER_MAGIC_NUMBER)
|
||||
{
|
||||
d.TraceDebug("Bad magic number");
|
||||
throw eSerializerInputStreamFmt(pSerializer->GetFileName() );
|
||||
throw eSerializerInputStreamFmt(pSerializer->GetFileName());
|
||||
}
|
||||
|
||||
// Note this version refers to the format of this data structure in the
|
||||
|
@ -182,7 +173,7 @@ void cFileHeader::Read(iSerializer* pSerializer, int32 /*version*/) // throw (eS
|
|||
{
|
||||
// don't understand the version
|
||||
d.TraceDebug("Bad version");
|
||||
throw eSerializerInputStreamFmt(pSerializer->GetFileName() );
|
||||
throw eSerializerInputStreamFmt(pSerializer->GetFileName());
|
||||
}
|
||||
|
||||
mID.Read(pSerializer);
|
||||
|
@ -196,7 +187,7 @@ void cFileHeader::Read(iSerializer* pSerializer, int32 /*version*/) // throw (eS
|
|||
pSerializer->ReadInt32(len);
|
||||
|
||||
if (len < 0 || len > 0xffff)
|
||||
throw eSerializerInputStreamFmt(pSerializer->GetFileName() );
|
||||
throw eSerializerInputStreamFmt(pSerializer->GetFileName());
|
||||
|
||||
mBaggage.MapArchive(0, len);
|
||||
|
||||
|
@ -233,14 +224,14 @@ void cFileHeader::Write(iSerializer* pSerializer) const // throw (eSerializer, e
|
|||
|
||||
pSerializer->WriteInt32(mVersion);
|
||||
|
||||
pSerializer->WriteInt16( static_cast<int16>(mEncoding) );
|
||||
pSerializer->WriteInt16(static_cast<int16>(mEncoding));
|
||||
|
||||
int32 len = static_cast<int32>( mBaggage.Length() );
|
||||
int32 len = static_cast<int32>(mBaggage.Length());
|
||||
|
||||
ASSERT(len >= 0);
|
||||
ASSERT(len <= 0xFFFF);
|
||||
|
||||
if ( len < 0 || len > 0xFFFF )
|
||||
if (len < 0 || len > 0xFFFF)
|
||||
throw eSerializerOutputStreamFmt();
|
||||
|
||||
pSerializer->WriteInt32(len);
|
||||
|
@ -250,4 +241,3 @@ void cFileHeader::Write(iSerializer* pSerializer) const // throw (eSerializer, e
|
|||
pSerializer->WriteBlob(mBaggage.GetMap(), len);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,12 +54,12 @@ public:
|
|||
cFileHeaderID(const cFileHeaderID& rhs);
|
||||
virtual ~cFileHeaderID();
|
||||
|
||||
void operator = (const TCHAR* id);
|
||||
void operator = (const cFileHeaderID& rhs);
|
||||
int operator == (const cFileHeaderID& rhs) const;
|
||||
int operator != (const cFileHeaderID& rhs) const;
|
||||
void operator=(const TCHAR* id);
|
||||
void operator=(const cFileHeaderID& rhs);
|
||||
int operator==(const cFileHeaderID& rhs) const;
|
||||
int operator!=(const cFileHeaderID& rhs) const;
|
||||
|
||||
virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Read(iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
||||
|
||||
private:
|
||||
|
@ -70,8 +70,11 @@ private:
|
|||
// the program is the only person who will see them.
|
||||
int16 mIDLen;
|
||||
|
||||
enum { MAXBYTES = 256 };
|
||||
char mID[ MAXBYTES ];
|
||||
enum
|
||||
{
|
||||
MAXBYTES = 256
|
||||
};
|
||||
char mID[MAXBYTES];
|
||||
};
|
||||
|
||||
inline cFileHeaderID::cFileHeaderID()
|
||||
|
@ -84,14 +87,12 @@ inline cFileHeaderID::cFileHeaderID(const TCHAR* id)
|
|||
*this = id;
|
||||
}
|
||||
|
||||
inline
|
||||
cFileHeaderID::cFileHeaderID( const cFileHeaderID& rhs ) :
|
||||
iSerializable(), mIDLen( rhs.mIDLen )
|
||||
inline cFileHeaderID::cFileHeaderID(const cFileHeaderID& rhs) : iSerializable(), mIDLen(rhs.mIDLen)
|
||||
{
|
||||
memcpy( mID, rhs.mID, MAXBYTES );
|
||||
memcpy(mID, rhs.mID, MAXBYTES);
|
||||
}
|
||||
|
||||
inline int cFileHeaderID::operator != (const cFileHeaderID& rhs) const
|
||||
inline int cFileHeaderID::operator!=(const cFileHeaderID& rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
@ -127,7 +128,7 @@ public:
|
|||
cMemoryArchive& GetBaggage();
|
||||
const cMemoryArchive& GetBaggage() const;
|
||||
|
||||
virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Read(iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
||||
|
||||
protected:
|
||||
|
@ -163,4 +164,3 @@ inline const cMemoryArchive& cFileHeader::GetBaggage() const
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -47,5 +47,4 @@
|
|||
#include <fstream>
|
||||
#define fixed_basic_ofstream std::basic_ofstream
|
||||
|
||||
#endif//__FIXED_FILEBUF_H
|
||||
|
||||
#endif //__FIXED_FILEBUF_H
|
||||
|
|
|
@ -43,5 +43,3 @@ iFSServices* iFSServices::mpInstance = 0;
|
|||
//#############################################################################
|
||||
// eFSServices
|
||||
//#############################################################################
|
||||
|
||||
|
||||
|
|
|
@ -66,11 +66,11 @@
|
|||
//=========================================================================
|
||||
|
||||
#if HAVE_SYS_PARAM_H
|
||||
# include <sys/param.h>
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -80,18 +80,18 @@
|
|||
|
||||
// macros for extracting the major and minor portions of int64's:
|
||||
#if !defined(major)
|
||||
#if !USES_GLIBC
|
||||
#define major(x) ((int)((x) >> 8) & 0xff)
|
||||
#define minor(x) ((int)((x) & 0xff))
|
||||
#else
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define major(x) (int)(((char*)&(x))[2])
|
||||
#define minor(x) (int)(((char*)&(x))[3])
|
||||
#else
|
||||
#define major(x) (int)(((char*)&(x))[1])
|
||||
#define minor(x) (int)(((char*)&(x))[0])
|
||||
#endif
|
||||
#endif
|
||||
# if !USES_GLIBC
|
||||
# define major(x) ((int)((x) >> 8) & 0xff)
|
||||
# define minor(x) ((int)((x)&0xff))
|
||||
# else
|
||||
# ifdef WORDS_BIGENDIAN
|
||||
# define major(x) (int)(((char*)&(x))[2])
|
||||
# define minor(x) (int)(((char*)&(x))[3])
|
||||
# else
|
||||
# define major(x) (int)(((char*)&(x))[1])
|
||||
# define minor(x) (int)(((char*)&(x))[0])
|
||||
# endif
|
||||
# endif
|
||||
#endif /* !major */
|
||||
|
||||
//=========================================================================
|
||||
|
@ -122,8 +122,10 @@ typedef int64 cFSType;
|
|||
|
||||
// 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
|
||||
struct cFSStatArgs {
|
||||
enum FileType {
|
||||
struct cFSStatArgs
|
||||
{
|
||||
enum FileType
|
||||
{
|
||||
TY_INVALID, // lazy evaluation
|
||||
TY_FILE,
|
||||
TY_DIR,
|
||||
|
@ -154,7 +156,7 @@ struct cFSStatArgs {
|
|||
int64 fstype; // dep
|
||||
TSTRING usid; // dep
|
||||
TSTRING gsid; // dep
|
||||
// int64 mFileType; // Matt's addition...
|
||||
// int64 mFileType; // Matt's addition...
|
||||
|
||||
FileType mFileType; // redundant with other information in this struct, but
|
||||
// broken out for convenience
|
||||
|
@ -164,15 +166,14 @@ struct cFSStatArgs {
|
|||
};
|
||||
|
||||
|
||||
|
||||
//=========================================================================
|
||||
//
|
||||
// eFSServices -- exception class
|
||||
//
|
||||
//=========================================================================
|
||||
|
||||
TSS_FILE_EXCEPTION( eFSServices, eFileError );
|
||||
TSS_FILE_EXCEPTION( eFSServicesGeneric, eFSServices );
|
||||
TSS_FILE_EXCEPTION(eFSServices, eFileError);
|
||||
TSS_FILE_EXCEPTION(eFSServicesGeneric, eFSServices);
|
||||
|
||||
//=========================================================================
|
||||
//
|
||||
|
@ -184,8 +185,10 @@ TSS_FILE_EXCEPTION( eFSServicesGeneric, eFSServices );
|
|||
|
||||
class iFSServices
|
||||
{
|
||||
public:
|
||||
virtual ~iFSServices() {}
|
||||
public:
|
||||
virtual ~iFSServices()
|
||||
{
|
||||
}
|
||||
///////////////////////////////////////////////////////////////
|
||||
// ENUMS
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
@ -235,21 +238,21 @@ class iFSServices
|
|||
////////////////////////////////////////
|
||||
// process functions
|
||||
////////////////////////////////////////
|
||||
virtual void Sleep( int nSeconds ) const = 0;
|
||||
virtual void Sleep(int nSeconds) const = 0;
|
||||
// makes the current process sleep for the specified number of seconds
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// major filesystem functions
|
||||
////////////////////////////////////////
|
||||
virtual void Stat( const TSTRING& strFileName, cFSStatArgs& pStat ) const = 0;
|
||||
virtual void Stat(const TSTRING& strFileName, cFSStatArgs& pStat) const = 0;
|
||||
// fills out the cFSStatArgs structure with the stat info for the named file
|
||||
virtual void GetTempDirName( TSTRING& strName ) const = 0;
|
||||
virtual void GetTempDirName(TSTRING& strName) const = 0;
|
||||
// makes directory if it doesn't exist already. Dirname will end with a delimiter ( '/' )
|
||||
|
||||
virtual void SetTempDirName( TSTRING& tmpName ) = 0;
|
||||
virtual void SetTempDirName(TSTRING& tmpName) = 0;
|
||||
|
||||
virtual TSTRING& MakeTempFilename( TSTRING& strName ) const = 0;
|
||||
virtual TSTRING& MakeTempFilename(TSTRING& strName) const = 0;
|
||||
// create temporary file
|
||||
// TSTRING must have the form ("baseXXXXXX"), where the X's are replaced with
|
||||
// characters to make it a unique file. There must be at least 6 Xs.
|
||||
|
@ -258,60 +261,60 @@ class iFSServices
|
|||
////////////////////////////////////////
|
||||
// minor filesystem functions
|
||||
////////////////////////////////////////
|
||||
virtual void GetHostID( TSTRING& name ) const = 0;
|
||||
virtual void GetHostID(TSTRING& name) const = 0;
|
||||
|
||||
virtual void GetMachineName( TSTRING& name ) const = 0;
|
||||
virtual void GetMachineName(TSTRING& name) const = 0;
|
||||
|
||||
virtual void GetMachineNameFullyQualified( TSTRING& name ) const = 0;
|
||||
virtual void GetMachineNameFullyQualified(TSTRING& name) const = 0;
|
||||
|
||||
virtual bool GetCurrentUserName( TSTRING& tstrName ) const = 0;
|
||||
virtual bool GetCurrentUserName(TSTRING& tstrName) const = 0;
|
||||
|
||||
virtual bool GetIPAddress( uint32& uiIPAddress ) = 0;
|
||||
virtual bool GetIPAddress(uint32& uiIPAddress) = 0;
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// directory specific functions
|
||||
////////////////////////////////////////
|
||||
virtual void ReadDir( const TSTRING& strName, std::vector<TSTRING> &vDirContents, bool bFullPaths = true ) const = 0;
|
||||
virtual void ReadDir(const TSTRING& strName, std::vector<TSTRING>& vDirContents, bool bFullPaths = true) const = 0;
|
||||
// puts the contents of the specified directory, except for . and .., into the supplied vector.
|
||||
// if bFullPaths is true, then the vector contains fully qualified path names; otherwise, it only contains the
|
||||
// short names.
|
||||
virtual void GetCurrentDir( TSTRING& strCurDir ) const = 0;
|
||||
virtual void GetCurrentDir(TSTRING& strCurDir) const = 0;
|
||||
// returns the current working directory
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// file specific functions
|
||||
////////////////////////////////////////
|
||||
virtual bool FileDelete( const TSTRING& name ) const = 0;
|
||||
virtual bool FileDelete(const TSTRING& name) const = 0;
|
||||
|
||||
////////////////////////////////////////
|
||||
// directory and file functions
|
||||
////////////////////////////////////////
|
||||
virtual bool Rename( const TSTRING& strOldName, const TSTRING& strNewName, bool fOverWrite = true ) const = 0;
|
||||
virtual bool Rename(const TSTRING& strOldName, const TSTRING& strNewName, bool fOverWrite = true) const = 0;
|
||||
// rename a file
|
||||
|
||||
virtual bool GetUserName( uid_t user_id, TSTRING& tstrUser ) const = 0;
|
||||
virtual bool GetGroupName( gid_t group_id, TSTRING& tstrGroup ) const = 0;
|
||||
virtual bool GetUserName(uid_t user_id, TSTRING& tstrUser) const = 0;
|
||||
virtual bool GetGroupName(gid_t group_id, TSTRING& tstrGroup) const = 0;
|
||||
|
||||
//Set whether we try to resolve uid/gid to a name, since Linux static binaries can
|
||||
//have trouble (read: segfaulting) with name resolution given the right nsswitch.conf setup.
|
||||
//This defaults to true if not specified.
|
||||
virtual void SetResolveNames(bool resolve)=0;
|
||||
virtual void SetResolveNames(bool resolve) = 0;
|
||||
|
||||
////////////////////////////////////////
|
||||
// miscellaneous utility functions
|
||||
////////////////////////////////////////
|
||||
virtual void ConvertModeToString( uint64 perm, TSTRING& tstrPerm ) const = 0;
|
||||
virtual void ConvertModeToString(uint64 perm, TSTRING& tstrPerm) const = 0;
|
||||
// takes a int64 permission (from stat) and changes it to look like UNIX's 'ls -l' (e.g. drwxrwxrwx)
|
||||
virtual bool FullPath( TSTRING& fullPath, const TSTRING& relPath, const TSTRING& pathRelFrom = _T("") ) const = 0;
|
||||
virtual bool FullPath(TSTRING& fullPath, const TSTRING& relPath, const TSTRING& pathRelFrom = _T("")) const = 0;
|
||||
// converts relPath into a fully qualified path, storing it in FullPath. If this
|
||||
// fails, false is returned. if the path to which relPath is relative is not CWD, put it in pathRelFrom.
|
||||
// TODO: In some places we have depended on the behaviour that if relPath.empty() == true then we
|
||||
// fail or return an empty string. Should we add this behaviour to the interface?
|
||||
virtual bool GetExecutableFilename( TSTRING& strFullPath, const TSTRING& strFilename ) const = 0;
|
||||
virtual bool GetExecutableFilename(TSTRING& strFullPath, const TSTRING& strFilename) const = 0;
|
||||
// get the path to the current executable file
|
||||
virtual bool IsRoot( const TSTRING& strPath ) const = 0;
|
||||
virtual bool IsRoot(const TSTRING& strPath) const = 0;
|
||||
// returns true if strPath denotes a root path
|
||||
|
||||
|
||||
|
@ -329,13 +332,13 @@ class iFSServices
|
|||
// singleton manipulation
|
||||
////////////////////////////////////////
|
||||
static iFSServices* GetInstance();
|
||||
static void SetInstance( iFSServices* pInst );
|
||||
static void SetInstance(iFSServices* pInst);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// PRIVATE DATA
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
private:
|
||||
static iFSServices* mpInstance;
|
||||
};
|
||||
|
||||
|
@ -350,11 +353,10 @@ inline iFSServices* iFSServices::GetInstance()
|
|||
return mpInstance;
|
||||
}
|
||||
|
||||
inline void iFSServices::SetInstance( iFSServices* pInst )
|
||||
inline void iFSServices::SetInstance(iFSServices* pInst)
|
||||
{
|
||||
mpInstance = pInst;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -47,7 +47,10 @@ public:
|
|||
size_t mSize;
|
||||
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().
|
||||
};
|
||||
typedef std::vector<cHeap> HeapList;
|
||||
|
@ -58,34 +61,34 @@ public:
|
|||
TSTRING mName;
|
||||
size_t mCurOff;
|
||||
|
||||
cGrowHeap_i( size_t initialSize, size_t growBy, const TCHAR* name );
|
||||
~cGrowHeap_i() { Clear(); }
|
||||
cGrowHeap_i(size_t initialSize, size_t growBy, const TCHAR* name);
|
||||
~cGrowHeap_i()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
size_t AlignSizeRequest( size_t size, size_t alignSize );
|
||||
void* Malloc( size_t size );
|
||||
size_t AlignSizeRequest(size_t size, size_t alignSize);
|
||||
void* Malloc(size_t size);
|
||||
void Clear();
|
||||
};
|
||||
|
||||
|
||||
cGrowHeap_i::cGrowHeap_i( size_t initialSize, size_t growBy, const TCHAR* name )
|
||||
: mInitialSize( initialSize ),
|
||||
mGrowBy ( growBy ),
|
||||
mName ( name ),
|
||||
mCurOff ( 0 )
|
||||
cGrowHeap_i::cGrowHeap_i(size_t initialSize, size_t growBy, const TCHAR* name)
|
||||
: mInitialSize(initialSize), mGrowBy(growBy), mName(name), mCurOff(0)
|
||||
{
|
||||
// assure that initial size and growby are aligned
|
||||
ASSERT( 0 == ( initialSize % BYTE_ALIGN ) );
|
||||
ASSERT( 0 == ( growBy % BYTE_ALIGN ) );
|
||||
ASSERT(0 == (initialSize % BYTE_ALIGN));
|
||||
ASSERT(0 == (growBy % BYTE_ALIGN));
|
||||
}
|
||||
|
||||
size_t cGrowHeap::TotalMemUsage() const
|
||||
{
|
||||
size_t usage = 0;
|
||||
for( cGrowHeap_i::HeapList::const_iterator i = mpData->mHeaps.begin(); i != mpData->mHeaps.end(); i++ )
|
||||
for (cGrowHeap_i::HeapList::const_iterator i = mpData->mHeaps.begin(); i != mpData->mHeaps.end(); i++)
|
||||
{
|
||||
usage += i->mSize;
|
||||
}
|
||||
if( ! mpData->mHeaps.empty() )
|
||||
if (!mpData->mHeaps.empty())
|
||||
{
|
||||
// take off the unused portion...
|
||||
usage -= (mpData->mHeaps.back().mSize - mpData->mCurOff);
|
||||
|
@ -94,23 +97,23 @@ size_t cGrowHeap::TotalMemUsage() const
|
|||
}
|
||||
|
||||
|
||||
void* cGrowHeap_i::Malloc( size_t size )
|
||||
void* cGrowHeap_i::Malloc(size_t size)
|
||||
{
|
||||
size = AlignSizeRequest( size, BYTE_ALIGN );
|
||||
size = AlignSizeRequest(size, BYTE_ALIGN);
|
||||
|
||||
ASSERT( ( size > 0 ) && ( size < mGrowBy ) );
|
||||
ASSERT((size > 0) && (size < mGrowBy));
|
||||
|
||||
if( size >= mGrowBy )
|
||||
if (size >= mGrowBy)
|
||||
return NULL;
|
||||
|
||||
if( mHeaps.empty() )
|
||||
if (mHeaps.empty())
|
||||
{
|
||||
mHeaps.push_back( cHeap( mInitialSize ) );
|
||||
mHeaps.push_back(cHeap(mInitialSize));
|
||||
ASSERT(mHeaps.back().mpData != 0);
|
||||
mCurOff = 0;
|
||||
}
|
||||
|
||||
if( mCurOff + size < mHeaps.back().mSize )
|
||||
if (mCurOff + size < mHeaps.back().mSize)
|
||||
{
|
||||
// we have room to add this to the current heap.
|
||||
//
|
||||
|
@ -122,43 +125,43 @@ void* cGrowHeap_i::Malloc( size_t size )
|
|||
}
|
||||
else
|
||||
{
|
||||
mHeaps.push_back( cHeap( mGrowBy ) );
|
||||
mHeaps.push_back(cHeap(mGrowBy));
|
||||
ASSERT(mHeaps.back().mpData != 0);
|
||||
mCurOff = 0;
|
||||
|
||||
#ifdef _DEUBG
|
||||
void* ret = Malloc( size );
|
||||
#ifdef _DEUBG
|
||||
void* ret = Malloc(size);
|
||||
ASSERT(ret != 0);
|
||||
return ret;
|
||||
#else
|
||||
return Malloc( size );
|
||||
#endif
|
||||
#else
|
||||
return Malloc(size);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
size_t cGrowHeap_i::AlignSizeRequest( size_t size, size_t alignSize )
|
||||
size_t cGrowHeap_i::AlignSizeRequest(size_t size, size_t alignSize)
|
||||
{
|
||||
// The two's complement algorithm requires a non-zero size request size,
|
||||
// so make make all requests require it so that this function
|
||||
// acts the same no matter what the integer representation
|
||||
if( 0 == size )
|
||||
if (0 == size)
|
||||
size = 1;
|
||||
|
||||
#if USES_2S_COMPLEMENT
|
||||
// This efficient algorithm assumes alignSize is power of two AND a
|
||||
// 2's complement representation. Requires non-zero size request
|
||||
ASSERT( 0 == ( alignSize % 2 ) );
|
||||
ASSERT( size > 0 );
|
||||
return( ( size + alignSize - 1 ) & ~( alignSize - 1 ) );
|
||||
ASSERT(0 == (alignSize % 2));
|
||||
ASSERT(size > 0);
|
||||
return ((size + alignSize - 1) & ~(alignSize - 1));
|
||||
#else
|
||||
// this makes no assumption about BYTE_ALIGN or hardware integer representation
|
||||
return( ( ( size / alignSize ) + ( ( size % alignSize ) ? 1 : 0 ) ) * alignSize );
|
||||
return (((size / alignSize) + ((size % alignSize) ? 1 : 0)) * alignSize);
|
||||
#endif
|
||||
}
|
||||
|
||||
void cGrowHeap_i::Clear()
|
||||
{
|
||||
for( HeapList::iterator i = mHeaps.begin(); i != mHeaps.end(); i++ )
|
||||
for (HeapList::iterator i = mHeaps.begin(); i != mHeaps.end(); i++)
|
||||
{
|
||||
delete [] i->mpData;
|
||||
}
|
||||
|
@ -168,27 +171,25 @@ void cGrowHeap_i::Clear()
|
|||
//-----------------------------------------------------------------------------
|
||||
// cGrowHeap
|
||||
//-----------------------------------------------------------------------------
|
||||
cGrowHeap::cGrowHeap( size_t initialSize, size_t growBy, const TCHAR* name ) :
|
||||
mpData( new cGrowHeap_i( initialSize, growBy, name ) )
|
||||
cGrowHeap::cGrowHeap(size_t initialSize, size_t growBy, const TCHAR* name)
|
||||
: mpData(new cGrowHeap_i(initialSize, growBy, name))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
cGrowHeap::~cGrowHeap()
|
||||
{
|
||||
cDebug d("FCO name heap stats");
|
||||
d.TraceDebug( _T("Total heap memory usage for %s: %d\n"), mpData->mName.c_str(), TotalMemUsage() );
|
||||
d.TraceDebug(_T("Total heap memory usage for %s: %d\n"), mpData->mName.c_str(), TotalMemUsage());
|
||||
|
||||
delete mpData;
|
||||
}
|
||||
|
||||
void* cGrowHeap::Malloc( size_t size )
|
||||
void* cGrowHeap::Malloc(size_t size)
|
||||
{
|
||||
return mpData->Malloc( size );
|
||||
return mpData->Malloc(size);
|
||||
}
|
||||
|
||||
void cGrowHeap::Clear()
|
||||
{
|
||||
mpData->Clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -52,13 +52,13 @@ class cGrowHeap_i;
|
|||
class cGrowHeap
|
||||
{
|
||||
public:
|
||||
cGrowHeap( size_t initialSize, size_t growby, const TCHAR* name );
|
||||
cGrowHeap(size_t initialSize, size_t growby, const TCHAR* name);
|
||||
// creates a heap that is initially initialSize big, and increases the
|
||||
// size by growBy every time there is no more room.
|
||||
// initialSize and growby must be a multiple of BYTE_ALIGN
|
||||
~cGrowHeap();
|
||||
|
||||
void* Malloc( size_t size );
|
||||
void* Malloc(size_t size);
|
||||
void Clear();
|
||||
// resets the grow heap's state.
|
||||
size_t TotalMemUsage() const;
|
||||
|
@ -69,4 +69,3 @@ private:
|
|||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -32,5 +32,3 @@
|
|||
//hashtable.cpp : implementation for hashtable which maps const TCHAR*'s to void*'s
|
||||
#include "stdcore.h"
|
||||
#include "hashtable.h"
|
||||
|
||||
|
||||
|
|
|
@ -67,8 +67,7 @@
|
|||
// 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
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
class cDefaultCompare
|
||||
template<class T> class cDefaultCompare
|
||||
{
|
||||
public:
|
||||
bool operator()(const T& lhs, const T& rhs)
|
||||
|
@ -79,8 +78,7 @@ public:
|
|||
/////////////////////////////////////////////////////////
|
||||
// specialization for TSTRINGS
|
||||
/////////////////////////////////////////////////////////
|
||||
template<>
|
||||
inline bool cDefaultCompare<TSTRING>::operator()(const TSTRING& lhs, const TSTRING& rhs)
|
||||
template<> inline bool cDefaultCompare<TSTRING>::operator()(const TSTRING& lhs, const TSTRING& rhs)
|
||||
{
|
||||
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
|
||||
// just does a cast. A specialization is also provided for TSTRINGs.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
class cDefaultConvert
|
||||
template<class T> class cDefaultConvert
|
||||
{
|
||||
public:
|
||||
const byte* operator()(const T& obj, int* const pcbKeyLen)
|
||||
|
@ -104,8 +101,7 @@ public:
|
|||
/////////////////////////////////////////////////////////
|
||||
// specialization for TSTRINGS
|
||||
/////////////////////////////////////////////////////////
|
||||
template<>
|
||||
inline const byte* cDefaultConvert<TSTRING>::operator()(const TSTRING& obj, int* const pcbKeyLen )
|
||||
template<> inline const byte* cDefaultConvert<TSTRING>::operator()(const TSTRING& obj, int* const pcbKeyLen)
|
||||
{
|
||||
*pcbKeyLen = sizeof(TCHAR) * obj.length();
|
||||
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
|
||||
// ie -- mTable(cHashTable<TSTRING, int>::MEDIUM
|
||||
enum cHashTable_TableSize {
|
||||
enum cHashTable_TableSize
|
||||
{
|
||||
HASH_VERY_SMALL = 17,
|
||||
HASH_SMALL = 2007,
|
||||
HASH_MEDIUM = 6007,
|
||||
|
@ -132,17 +129,25 @@ enum cHashTable_TableSize {
|
|||
};
|
||||
|
||||
// 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;
|
||||
|
||||
//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
|
||||
{
|
||||
friend class cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>;
|
||||
friend class cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>;
|
||||
|
||||
public:
|
||||
//structure for hash table nodes.
|
||||
struct node {
|
||||
struct node
|
||||
{
|
||||
KEY_TYPE nKey;
|
||||
VAL_TYPE nData;
|
||||
node* next;
|
||||
|
@ -167,9 +172,12 @@ public:
|
|||
bool Clear(void);
|
||||
//Clears the entire table and sets all node pointers to NULL
|
||||
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
|
||||
int32 GetNumValues() const { return mValuesInTable; };
|
||||
int32 GetNumValues() const
|
||||
{
|
||||
return mValuesInTable;
|
||||
};
|
||||
// returns number of table entries filled
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -190,8 +198,7 @@ private:
|
|||
// cHashTableIter
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
class cHashTableIter
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER> class cHashTableIter
|
||||
{
|
||||
public:
|
||||
cHashTableIter(const cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>& hashTbl);
|
||||
|
@ -214,73 +221,73 @@ private:
|
|||
};
|
||||
|
||||
|
||||
|
||||
//#############################################################################
|
||||
// implementation
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// iterator
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
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) :
|
||||
mHashTable(hashTbl)
|
||||
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)
|
||||
: mHashTable(hashTbl)
|
||||
{
|
||||
SeekBegin();
|
||||
}
|
||||
|
||||
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 void cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::SeekBegin() const
|
||||
{
|
||||
mCurIndex = 0;
|
||||
mpCurNode = mHashTable.mTable[0];
|
||||
if(! mpCurNode)
|
||||
if (!mpCurNode)
|
||||
SeekNextValid();
|
||||
}
|
||||
|
||||
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 bool cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Done() const
|
||||
{
|
||||
return ((mCurIndex < 0) || (mCurIndex >= mHashTable.mTableSize));
|
||||
}
|
||||
|
||||
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 void cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Next() const
|
||||
{
|
||||
SeekNextValid();
|
||||
}
|
||||
|
||||
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 void cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::SeekNextValid() const
|
||||
{
|
||||
if(mpCurNode)
|
||||
if (mpCurNode)
|
||||
mpCurNode = mpCurNode->next;
|
||||
|
||||
// if we're out of range, bail out w/o incrementing index
|
||||
if(mCurIndex >= mHashTable.mTableSize)
|
||||
if (mCurIndex >= mHashTable.mTableSize)
|
||||
return;
|
||||
|
||||
while((! mpCurNode) && (++mCurIndex < mHashTable.mTableSize))
|
||||
while ((!mpCurNode) && (++mCurIndex < mHashTable.mTableSize))
|
||||
{
|
||||
mpCurNode = mHashTable.mTable[mCurIndex];
|
||||
}
|
||||
}
|
||||
|
||||
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 const KEY_TYPE& cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Key() const
|
||||
{
|
||||
ASSERT(! Done());
|
||||
ASSERT(!Done());
|
||||
return mpCurNode->nKey;
|
||||
}
|
||||
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 const VAL_TYPE& cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Val() const
|
||||
{
|
||||
ASSERT(! Done());
|
||||
ASSERT(!Done());
|
||||
return mpCurNode->nData;
|
||||
}
|
||||
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 VAL_TYPE& cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Val()
|
||||
{
|
||||
ASSERT(! Done());
|
||||
ASSERT(!Done());
|
||||
return mpCurNode->nData;
|
||||
}
|
||||
|
||||
|
@ -289,32 +296,32 @@ inline VAL_TYPE& cHashTableIter<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Val(
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Default value for tblSize == 6007
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::cHashTable(int tblSize)
|
||||
{
|
||||
mValuesInTable = 0;
|
||||
mTableSize = tblSize;
|
||||
mTable = new node*[mTableSize];
|
||||
|
||||
for (int i=0; i < mTableSize; ++i)
|
||||
for (int i = 0; i < mTableSize; ++i)
|
||||
mTable[i] = NULL;
|
||||
}
|
||||
|
||||
//Destructor steps through table and deallocates all dynamic memory
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::~cHashTable()
|
||||
{
|
||||
for (int i=0; i<mTableSize; ++i)
|
||||
for (int i = 0; i < mTableSize; ++i)
|
||||
{
|
||||
if (mTable[i] != NULL)
|
||||
{
|
||||
//delete the entire chain:
|
||||
node* curr = mTable[i];
|
||||
node* del;
|
||||
while(curr != NULL)
|
||||
while (curr != NULL)
|
||||
{
|
||||
del = curr;
|
||||
curr=curr->next;
|
||||
curr = curr->next;
|
||||
|
||||
delete del;
|
||||
}
|
||||
|
@ -328,13 +335,14 @@ cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::~cHashTable()
|
|||
// using seperate chaining (link lists).
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Insert(KEY_TYPE key, VAL_TYPE d_in)
|
||||
{
|
||||
COMPARE_OP compare;
|
||||
|
||||
int hindex = Hash( key );
|
||||
if (mTable[hindex] == NULL) {
|
||||
int hindex = Hash(key);
|
||||
if (mTable[hindex] == NULL)
|
||||
{
|
||||
//open index, perform insert
|
||||
mTable[hindex] = new node;
|
||||
(mTable[hindex])->nKey = key;
|
||||
|
@ -354,7 +362,7 @@ bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Insert(KEY_TYPE key,
|
|||
bool found = false;
|
||||
while (true)
|
||||
{
|
||||
if ( compare(nodeptr->nKey, key))
|
||||
if (compare(nodeptr->nKey, key))
|
||||
{
|
||||
// we found a duplicate!
|
||||
found = true;
|
||||
|
@ -362,7 +370,7 @@ bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Insert(KEY_TYPE key,
|
|||
}
|
||||
|
||||
// break if this is the last node in the list
|
||||
if(! nodeptr->next)
|
||||
if (!nodeptr->next)
|
||||
break;
|
||||
|
||||
// otherwise, keep traversing
|
||||
|
@ -370,9 +378,9 @@ bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Insert(KEY_TYPE key,
|
|||
}
|
||||
|
||||
// add a node if the key was not found
|
||||
if (! found)
|
||||
if (!found)
|
||||
{
|
||||
node *prev = nodeptr;
|
||||
node* prev = nodeptr;
|
||||
nodeptr = new node;
|
||||
nodeptr->nKey = key;
|
||||
nodeptr->next = NULL;
|
||||
|
@ -392,20 +400,21 @@ bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Insert(KEY_TYPE key,
|
|||
// Lookup -- Attempts to find 'string' in the hash table.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// General Version:
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool
|
||||
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Lookup(KEY_TYPE key, VAL_TYPE& d_out) const
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Lookup(KEY_TYPE key, VAL_TYPE& d_out) const
|
||||
{
|
||||
COMPARE_OP compare;
|
||||
|
||||
int hindex = Hash( key );
|
||||
int hindex = Hash(key);
|
||||
if (mTable[hindex] == NULL)
|
||||
return false;
|
||||
else {
|
||||
else
|
||||
{
|
||||
node* nodeptr = mTable[hindex];
|
||||
while (nodeptr != NULL)
|
||||
{
|
||||
if( compare(nodeptr->nKey, key)) {
|
||||
if (compare(nodeptr->nKey, key))
|
||||
{
|
||||
d_out = nodeptr->nData;
|
||||
return true;
|
||||
}
|
||||
|
@ -420,24 +429,26 @@ cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Lookup(KEY_TYPE key, VAL_
|
|||
// the nKey is not found in the table.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// General Version -
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool
|
||||
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Remove(KEY_TYPE key)
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Remove(KEY_TYPE key)
|
||||
{
|
||||
COMPARE_OP compare;
|
||||
|
||||
int hindex = Hash( key );
|
||||
if (mTable[hindex] == NULL) {
|
||||
int hindex = Hash(key);
|
||||
if (mTable[hindex] == NULL)
|
||||
{
|
||||
delete (mTable[hindex]);
|
||||
mTable[hindex] = NULL;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
node* nodeptr = mTable[hindex];
|
||||
node* prev;
|
||||
while(nodeptr != NULL) {
|
||||
while (nodeptr != NULL)
|
||||
{
|
||||
prev = nodeptr;
|
||||
if(compare(mTable[hindex]->nKey, key))
|
||||
if (compare(mTable[hindex]->nKey, key))
|
||||
{
|
||||
prev->next = nodeptr->next;
|
||||
delete nodeptr;
|
||||
|
@ -445,48 +456,48 @@ cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Remove(KEY_TYPE key)
|
|||
mTable[hindex] = NULL;
|
||||
nodeptr = NULL;
|
||||
return true;
|
||||
}//end if
|
||||
} //end if
|
||||
nodeptr = nodeptr->next;
|
||||
}//end while
|
||||
}//end else
|
||||
} //end while
|
||||
} //end else
|
||||
return false; //match was not found, no node deleted
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Clear -- Clears entire hash table so that all indices are NULL
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool
|
||||
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Clear(void)
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool 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* del;
|
||||
while(curr != NULL) {
|
||||
while (curr != NULL)
|
||||
{
|
||||
del = curr;
|
||||
curr=curr->next;
|
||||
curr = curr->next;
|
||||
delete del;
|
||||
if (del == mTable[i])
|
||||
mTable[i] = NULL;
|
||||
del = NULL;
|
||||
|
||||
}//end delete chain loop
|
||||
}//end if mTable[i]!= NULL
|
||||
}//end for
|
||||
} //end delete chain loop
|
||||
} //end if mTable[i]!= NULL
|
||||
} //end for
|
||||
return (IsEmpty());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// IsEmpty --
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool
|
||||
cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::IsEmpty(void) const
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
bool cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::IsEmpty(void) const
|
||||
{
|
||||
bool ret = true;
|
||||
for(int i=0; i< mTableSize; ++i)
|
||||
for (int i = 0; i < mTableSize; ++i)
|
||||
ret &= (mTable[i] == NULL);
|
||||
return ret;
|
||||
}
|
||||
|
@ -494,12 +505,12 @@ cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::IsEmpty(void) const
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Hash -- performs hashing on key, returns an integer index val.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
uint32 cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Hash( const KEY_TYPE& key ) const
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
uint32 cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Hash(const KEY_TYPE& key) const
|
||||
{
|
||||
CONVERTER converter;
|
||||
int len;
|
||||
const byte* pb = converter( key, &len ); //locates key
|
||||
const byte* pb = converter(key, &len); //locates key
|
||||
uint32 hindex;
|
||||
|
||||
hindex = *pb;
|
||||
|
@ -510,7 +521,7 @@ uint32 cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::Hash( const KEY_TY
|
|||
|
||||
#ifdef DEBUG
|
||||
|
||||
template <class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
template<class KEY_TYPE, class VAL_TYPE, class COMPARE_OP, class CONVERTER>
|
||||
void cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::TraceDiagnostics() const
|
||||
{
|
||||
cDebug d("cHashTable::Diagnostics");
|
||||
|
@ -518,16 +529,16 @@ void cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::TraceDiagnostics() c
|
|||
int slotsFilled = 0, numItems = 0, numMultiSlot = 0;
|
||||
node* pNode;
|
||||
|
||||
for(int i=0; i < mTableSize; i++)
|
||||
for (int i = 0; i < mTableSize; i++)
|
||||
{
|
||||
if(mTable[i] != NULL)
|
||||
if (mTable[i] != NULL)
|
||||
{
|
||||
slotsFilled++;
|
||||
numItems++;
|
||||
pNode = (mTable[i])->next;
|
||||
if(pNode != NULL)
|
||||
if (pNode != NULL)
|
||||
numMultiSlot++;
|
||||
while(pNode)
|
||||
while (pNode)
|
||||
{
|
||||
numItems++;
|
||||
pNode = pNode->next;
|
||||
|
@ -538,12 +549,15 @@ void cHashTable<KEY_TYPE, VAL_TYPE, COMPARE_OP, CONVERTER>::TraceDiagnostics() c
|
|||
d.TraceDebug("---------------Hash Table Statisics---------------\n");
|
||||
d.TraceDebug("-- Number of slots: %d\n", mTableSize);
|
||||
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 with >1 item: %d (%lf %%)\n",numMultiSlot, ((double)numMultiSlot / (double)slotsFilled) * 100.0);
|
||||
d.TraceDebug("-- Slots filled: %d (%lf %%)\n",
|
||||
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");
|
||||
}
|
||||
#endif // DEBUG
|
||||
# endif // DEBUG
|
||||
|
||||
|
||||
#endif //__HASHTABLE_H
|
||||
|
||||
|
|
158
src/core/ntdbs.h
158
src/core/ntdbs.h
|
@ -51,13 +51,13 @@
|
|||
#include "ntmbs.h"
|
||||
|
||||
#if IS_KAI
|
||||
#define IS_STDLIB_MODENA 1 // Has special char_traits req's!
|
||||
#ifdef MSIPL_WCHART
|
||||
#define MBSTATE_T_DEFINED
|
||||
#endif
|
||||
# define IS_STDLIB_MODENA 1 // Has special char_traits req's!
|
||||
# ifdef MSIPL_WCHART
|
||||
# define MBSTATE_T_DEFINED
|
||||
# endif
|
||||
#else
|
||||
#define IS_STDLIB_MODENA 0
|
||||
#define MBSTATE_T_DEFINED
|
||||
# define IS_STDLIB_MODENA 0
|
||||
# define MBSTATE_T_DEFINED
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -65,15 +65,24 @@
|
|||
// Char traits for WCHAR16 (aka dbchar_t) and NTMBCS (mctype_t)
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
#if ( WCHAR_IS_16_BITS )
|
||||
namespace tss { typedef std::wstring dbstring; }
|
||||
#if (WCHAR_IS_16_BITS)
|
||||
namespace tss
|
||||
{
|
||||
typedef std::wstring dbstring;
|
||||
}
|
||||
|
||||
#elif ( WCHAR_IS_32_BITS )
|
||||
namespace std { template <> struct char_traits< dbchar_t >; }
|
||||
namespace tss { typedef std::basic_string<dbchar_t> dbstring; }
|
||||
#elif (WCHAR_IS_32_BITS)
|
||||
namespace std
|
||||
{
|
||||
template<> struct char_traits<dbchar_t>;
|
||||
}
|
||||
namespace tss
|
||||
{
|
||||
typedef std::basic_string<dbchar_t> dbstring;
|
||||
}
|
||||
|
||||
#else
|
||||
#error "wchar_t is not correctly factored!"
|
||||
# error "wchar_t is not correctly factored!"
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -84,151 +93,140 @@
|
|||
|
||||
// specialize *std*::char_traits!!!
|
||||
|
||||
template<>
|
||||
struct std::char_traits< dbchar_t >
|
||||
template<> struct std::char_traits<dbchar_t>
|
||||
{
|
||||
typedef dbchar_t char_type;
|
||||
typedef wint_t int_type;
|
||||
typedef streampos pos_type;
|
||||
typedef streamoff off_type;
|
||||
|
||||
#ifdef MBSTATE_T_DEFINED
|
||||
# ifdef MBSTATE_T_DEFINED
|
||||
typedef mbstate_t state_type;
|
||||
#else
|
||||
# else
|
||||
typedef int state_type; // Shame on you KAI! This is ANSI-C!
|
||||
#endif
|
||||
# endif
|
||||
|
||||
static
|
||||
void assign( char_type& lhs, const char_type& rhs ) {
|
||||
static void assign(char_type& lhs, const char_type& rhs)
|
||||
{
|
||||
lhs = rhs;
|
||||
}
|
||||
|
||||
static
|
||||
bool eq( const char_type& lhs, const char_type& rhs ) {
|
||||
static bool eq(const char_type& lhs, const char_type& rhs)
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
static
|
||||
bool lt( const char_type& lhs, const char_type& rhs ) {
|
||||
static bool lt(const char_type& lhs, const char_type& rhs)
|
||||
{
|
||||
return lhs < rhs;
|
||||
}
|
||||
|
||||
static
|
||||
int compare( const char_type* lhs, const char_type* rhs, size_t N )
|
||||
static int compare(const char_type* lhs, const char_type* rhs, size_t N)
|
||||
{
|
||||
for ( ; N; ++lhs, ++rhs, --N )
|
||||
if ( *lhs != *rhs )
|
||||
return ( *lhs < *rhs ) ? -1 : +1;
|
||||
for (; N; ++lhs, ++rhs, --N)
|
||||
if (*lhs != *rhs)
|
||||
return (*lhs < *rhs) ? -1 : +1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
size_t length( const char_type* psz )
|
||||
static size_t length(const char_type* psz)
|
||||
{
|
||||
if ( psz == 0 )
|
||||
if (psz == 0)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
const char_type* end;
|
||||
for ( end = psz; *end; end++ );
|
||||
return (size_t)( end - psz );
|
||||
for (end = psz; *end; end++)
|
||||
;
|
||||
return (size_t)(end - psz);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
char_type* copy( char_type* lhs, const char_type* rhs, size_t N )
|
||||
static 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;
|
||||
|
||||
return lhs;
|
||||
}
|
||||
|
||||
static
|
||||
const char_type*
|
||||
find( const char_type* psz, size_t N, const char_type& ch )
|
||||
static const char_type* find(const char_type* psz, size_t N, const char_type& ch)
|
||||
{
|
||||
for ( ; N; ++psz, --N )
|
||||
if ( *psz == ch )
|
||||
for (; N; ++psz, --N)
|
||||
if (*psz == ch)
|
||||
return psz;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
char_type* move( char_type* lhs, const char_type* rhs, size_t N ) {
|
||||
return (char_type*)memmove( lhs, rhs, N * sizeof(char_type) );
|
||||
static char_type* move(char_type* lhs, const char_type* rhs, size_t N)
|
||||
{
|
||||
return (char_type*)memmove(lhs, rhs, N * sizeof(char_type));
|
||||
}
|
||||
|
||||
static
|
||||
char_type* assign( char_type* lhs, size_t N, char_type ch )
|
||||
static 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;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
static
|
||||
int_type not_eof( const int_type& ch ) {
|
||||
return int_type( !eq( ch, eof() ) ? ch : ~ch );
|
||||
}
|
||||
|
||||
static
|
||||
char_type to_char_type( const int_type& ch )
|
||||
static int_type not_eof(const int_type& ch)
|
||||
{
|
||||
return
|
||||
eq_int_type( ch, to_int_type( ch ) )
|
||||
? ch
|
||||
: char_type(0);
|
||||
return int_type(!eq(ch, eof()) ? ch : ~ch);
|
||||
}
|
||||
|
||||
static
|
||||
int_type to_int_type( const char_type& ch ) {
|
||||
static char_type to_char_type(const int_type& ch)
|
||||
{
|
||||
return eq_int_type(ch, to_int_type(ch)) ? ch : char_type(0);
|
||||
}
|
||||
|
||||
static int_type to_int_type(const char_type& ch)
|
||||
{
|
||||
return (int_type)ch;
|
||||
}
|
||||
|
||||
static
|
||||
bool eq_int_type( const int_type& lhs, const int_type& rhs ) {
|
||||
static bool eq_int_type(const int_type& lhs, const int_type& rhs)
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
#if IS_STDLIB_MODENA
|
||||
# if IS_STDLIB_MODENA
|
||||
|
||||
// CAUTION:RAD -- Extra members required by Modena!!
|
||||
|
||||
#ifdef MBSTATE_T_DEFINED // This is ANSI-C *not* ANSI-C++!!
|
||||
static
|
||||
state_type get_state( pos_type pos ) {
|
||||
# ifdef MBSTATE_T_DEFINED // This is ANSI-C *not* ANSI-C++!!
|
||||
static state_type get_state(pos_type pos)
|
||||
{
|
||||
return pos.state();
|
||||
}
|
||||
|
||||
static
|
||||
pos_type get_pos( pos_type pos, state_type state ) {
|
||||
return pos_type( pos.offset(), state );
|
||||
static pos_type get_pos(pos_type pos, state_type state)
|
||||
{
|
||||
return pos_type(pos.offset(), state);
|
||||
}
|
||||
#endif//MBSTATE_T_DEFINED
|
||||
# endif //MBSTATE_T_DEFINED
|
||||
|
||||
static
|
||||
char_type newline() {
|
||||
static char_type newline()
|
||||
{
|
||||
return L'\n';
|
||||
}
|
||||
|
||||
static
|
||||
char_type eos() {
|
||||
static char_type eos()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif//IS_STDLIB_MODENA
|
||||
# endif //IS_STDLIB_MODENA
|
||||
|
||||
static
|
||||
int_type eof() {
|
||||
static int_type eof()
|
||||
{
|
||||
return (wint_t)(0xFFFF);
|
||||
}
|
||||
};
|
||||
|
||||
#endif//WCHAR_IS_16_BITS // We already have a dbstring implicitly in wstring!!!
|
||||
# endif //WCHAR_IS_16_BITS // We already have a dbstring implicitly in wstring!!!
|
||||
|
||||
|
||||
#endif//__NTDBS_H
|
||||
|
||||
#endif //__NTDBS_H
|
||||
|
|
|
@ -47,11 +47,9 @@
|
|||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
#ifndef TSS_Raise // Should add file and line info in DEBUG mode!!!!
|
||||
#define TSS_Raise( Xcpt, pkg, ids ) \
|
||||
throw Xcpt( TSS_GetString( pkg, ids ) )
|
||||
|
||||
#endif//TSS_Raise
|
||||
# define TSS_Raise(Xcpt, pkg, ids) throw Xcpt(TSS_GetString(pkg, ids))
|
||||
|
||||
#endif //TSS_Raise
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -134,32 +132,28 @@ tss::mbsdec( const_ntmbs_t beg, const_ntmbs_t curr )
|
|||
* POSTCONDITIONS:
|
||||
* Returns non-const pointer after moving it.
|
||||
*/
|
||||
ntmbs_t
|
||||
tss::mbsinc( const_ntmbs_t psz )
|
||||
ntmbs_t tss::mbsinc(const_ntmbs_t psz)
|
||||
{
|
||||
cDebug dbg( "tss::mbsinc -" );
|
||||
cDebug dbg("tss::mbsinc -");
|
||||
|
||||
if ( psz == 0 )
|
||||
throw eCharacter( TSS_GetString( cCore, core::STR_ERR_ISNULL ) );
|
||||
if (psz == 0)
|
||||
throw eCharacter(TSS_GetString(cCore, core::STR_ERR_ISNULL));
|
||||
|
||||
int nBytes = ::mblen( (char*)psz, MB_CUR_MAX );
|
||||
if ( nBytes == -1 )
|
||||
int nBytes = ::mblen((char*)psz, MB_CUR_MAX);
|
||||
if (nBytes == -1)
|
||||
{
|
||||
dbg.TraceDebug( "Character Fault: %c\n", *psz );
|
||||
if ( (unsigned char)*psz > 0x7F )
|
||||
dbg.TraceDebug("Character Fault: %c\n", *psz);
|
||||
if ((unsigned char)*psz > 0x7F)
|
||||
{
|
||||
dbg.TraceDebug( "Normalizing.\n" );
|
||||
return (((ntmbs_t)psz) + 1 );
|
||||
dbg.TraceDebug("Normalizing.\n");
|
||||
return (((ntmbs_t)psz) + 1);
|
||||
}
|
||||
|
||||
dbg.TraceDebug( "Incorrectly Formed, Cannot Normalize!\n" );
|
||||
TSS_Raise(
|
||||
eCharacterEncoding,
|
||||
cCore,
|
||||
core::STR_ERR_BADCHAR );
|
||||
dbg.TraceDebug("Incorrectly Formed, Cannot Normalize!\n");
|
||||
TSS_Raise(eCharacterEncoding, cCore, core::STR_ERR_BADCHAR);
|
||||
}
|
||||
|
||||
return ( ((ntmbs_t)psz) + nBytes );
|
||||
return (((ntmbs_t)psz) + nBytes);
|
||||
}
|
||||
|
||||
|
||||
|
@ -180,33 +174,30 @@ tss::mbsinc( const_ntmbs_t psz )
|
|||
* POSTCONDITIONS:
|
||||
* Returns size_t value indicating bytes in the range of [0,nCount).
|
||||
*/
|
||||
size_t
|
||||
tss::mbsbytes( const_ntmbs_t psz, size_t nCount )
|
||||
size_t tss::mbsbytes(const_ntmbs_t psz, size_t nCount)
|
||||
{
|
||||
const_ntmbs_t at = psz;
|
||||
while ( nCount-- )
|
||||
at = tss::mbsinc( at );
|
||||
while (nCount--)
|
||||
at = tss::mbsinc(at);
|
||||
|
||||
return (size_t)((char*)at - (char*)psz);
|
||||
}
|
||||
|
||||
/// To Null terminator
|
||||
|
||||
size_t
|
||||
tss::mbsbytes( const_ntmbs_t psz )
|
||||
size_t tss::mbsbytes(const_ntmbs_t psz)
|
||||
{
|
||||
if ( psz == 0 )
|
||||
throw eCharacter( TSS_GetString( cCore, core::STR_ERR_ISNULL ) );
|
||||
if (psz == 0)
|
||||
throw eCharacter(TSS_GetString(cCore, core::STR_ERR_ISNULL));
|
||||
|
||||
|
||||
const_ntmbs_t at;
|
||||
for ( at = psz; *at; ++at );
|
||||
for (at = psz; *at; ++at)
|
||||
;
|
||||
return (size_t)((char*)at - (char*)psz);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* TSS::mbscount
|
||||
*
|
||||
|
@ -224,25 +215,22 @@ tss::mbsbytes( const_ntmbs_t psz )
|
|||
* POSTCONDITIONS:
|
||||
* Returns size_t value indicating characters in the range of [psz + 0, psz + nBytes).
|
||||
*/
|
||||
size_t
|
||||
tss_mbscount( const_ntmbs_t psz, size_t nBytes )
|
||||
size_t tss_mbscount(const_ntmbs_t psz, size_t nBytes)
|
||||
{
|
||||
size_t nCount = 0;
|
||||
const_ntmbs_t at = psz;
|
||||
const_ntmbs_t end = psz + nBytes;
|
||||
for ( ; at < end; nCount++, at = tss::mbsinc( at ) );
|
||||
for (; at < end; nCount++, at = tss::mbsinc(at))
|
||||
;
|
||||
return nCount;
|
||||
}
|
||||
|
||||
/// To Null terminator
|
||||
|
||||
size_t
|
||||
tss::mbscount( const_ntmbs_t psz )
|
||||
size_t tss::mbscount(const_ntmbs_t psz)
|
||||
{
|
||||
size_t nCount = 0;
|
||||
for ( ; *psz; psz = tss::mbsinc( psz ), nCount++ );
|
||||
for (; *psz; psz = tss::mbsinc(psz), nCount++)
|
||||
;
|
||||
return nCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
458
src/core/ntmbs.h
458
src/core/ntmbs.h
|
@ -55,28 +55,27 @@
|
|||
//--Null-terminated Multibyte Character Sequence
|
||||
|
||||
#ifndef NTMBS_T_DEFINED
|
||||
#define NTMBS_T_DEFINED
|
||||
#ifdef TSS_NTMBS_IS_UNSIGNED // Natural-sign by default
|
||||
typedef unsigned char mbchar_t;
|
||||
typedef unsigned char* ntmbs_t;
|
||||
typedef const unsigned char* const_ntmbs_t;
|
||||
#else //TSS_NTMBS_IS_UNSIGNED
|
||||
typedef char mbchar_t;
|
||||
typedef char* ntmbs_t;
|
||||
typedef const char* const_ntmbs_t;
|
||||
#endif//TSS_NTMBS_IS_UNSIGNED
|
||||
#endif//NTMBS_T_DEFINED
|
||||
# define NTMBS_T_DEFINED
|
||||
# ifdef TSS_NTMBS_IS_UNSIGNED // Natural-sign by default
|
||||
typedef unsigned char mbchar_t;
|
||||
typedef unsigned char* ntmbs_t;
|
||||
typedef const unsigned char* const_ntmbs_t;
|
||||
# else //TSS_NTMBS_IS_UNSIGNED
|
||||
typedef char mbchar_t;
|
||||
typedef char* ntmbs_t;
|
||||
typedef const char* const_ntmbs_t;
|
||||
# endif //TSS_NTMBS_IS_UNSIGNED
|
||||
#endif //NTMBS_T_DEFINED
|
||||
|
||||
|
||||
//--Null-terminated Wide Character Sequence (Could be double or quad byte)
|
||||
|
||||
#ifndef NTWCS_T_DEFINED
|
||||
#define NTWCS_T_DEFINED
|
||||
//typedef wchar_t wchar_t;
|
||||
typedef wchar_t* ntwcs_t;
|
||||
typedef const wchar_t* const_ntwcs_t;
|
||||
#endif//NTWCS_T_DEFINED
|
||||
|
||||
# define NTWCS_T_DEFINED
|
||||
//typedef wchar_t wchar_t;
|
||||
typedef wchar_t* ntwcs_t;
|
||||
typedef const wchar_t* const_ntwcs_t;
|
||||
#endif //NTWCS_T_DEFINED
|
||||
|
||||
|
||||
/// NOTE: Size Specific (2 [double] or 4 [quad] byte wide characters)
|
||||
|
@ -84,57 +83,57 @@
|
|||
//--Null-terminated double(2)-byte Character Sequence
|
||||
|
||||
#ifndef NTDBS_T_DEFINED
|
||||
#define NTDBS_T_DEFINED
|
||||
#if WCHAR_IS_16_BITS
|
||||
typedef wchar_t dbchar_t; // Same size but use NT's type
|
||||
#else
|
||||
typedef uint16 dbchar_t;
|
||||
#endif
|
||||
typedef dbchar_t* ntdbs_t;
|
||||
typedef const dbchar_t* const_ntdbs_t;
|
||||
#endif//NTDBS_T_DEFINED
|
||||
# define NTDBS_T_DEFINED
|
||||
# if WCHAR_IS_16_BITS
|
||||
typedef wchar_t dbchar_t; // Same size but use NT's type
|
||||
# else
|
||||
typedef uint16 dbchar_t;
|
||||
# endif
|
||||
typedef dbchar_t* ntdbs_t;
|
||||
typedef const dbchar_t* const_ntdbs_t;
|
||||
#endif //NTDBS_T_DEFINED
|
||||
|
||||
|
||||
//--Internal, "size-specific" types for type dispatched specializations
|
||||
|
||||
#ifndef NTQBS_T_DEFINED
|
||||
#define NTQBS_T_DEFINED
|
||||
#if WCHAR_IS_32_BITS
|
||||
typedef wchar_t qbchar_t; // Same size but use NT's type
|
||||
#else
|
||||
typedef uint32 qbchar_t;
|
||||
#endif
|
||||
typedef qbchar_t* ntqbs_t;
|
||||
typedef const qbchar_t* const_ntqbs_t;
|
||||
#endif//NTQBS_T_DEFINED
|
||||
|
||||
# define NTQBS_T_DEFINED
|
||||
# if WCHAR_IS_32_BITS
|
||||
typedef wchar_t qbchar_t; // Same size but use NT's type
|
||||
# else
|
||||
typedef uint32 qbchar_t;
|
||||
# endif
|
||||
typedef qbchar_t* ntqbs_t;
|
||||
typedef const qbchar_t* const_ntqbs_t;
|
||||
#endif //NTQBS_T_DEFINED
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// NTMBS Manipulators
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
TSS_EXCEPTION( eCharacter, eError );
|
||||
TSS_EXCEPTION( eCharacterEncoding, eCharacter );
|
||||
TSS_EXCEPTION(eCharacter, eError);
|
||||
TSS_EXCEPTION(eCharacterEncoding, eCharacter);
|
||||
|
||||
|
||||
namespace tss
|
||||
{
|
||||
/// Specific Routines (Add as needed)
|
||||
/// Specific Routines (Add as needed)
|
||||
|
||||
//ntmbs_t mbsdec( const_ntmbs_t, const_ntmbs_t );
|
||||
ntmbs_t mbsinc( const_ntmbs_t );
|
||||
//ntmbs_t mbsdec( const_ntmbs_t, const_ntmbs_t );
|
||||
ntmbs_t mbsinc(const_ntmbs_t);
|
||||
|
||||
size_t mbsbytes( const_ntmbs_t, size_t );
|
||||
size_t mbscount( const_ntmbs_t, size_t );
|
||||
size_t mbsbytes(const_ntmbs_t, size_t);
|
||||
size_t mbscount(const_ntmbs_t, size_t);
|
||||
|
||||
size_t mbsbytes( const_ntmbs_t );
|
||||
size_t mbscount( const_ntmbs_t );
|
||||
size_t mbsbytes(const_ntmbs_t);
|
||||
size_t mbscount(const_ntmbs_t);
|
||||
|
||||
inline size_t mbslen( const_ntmbs_t psz ) { // RAD: Yeesh!
|
||||
return tss::mbscount( psz );
|
||||
}
|
||||
}//tss::
|
||||
inline size_t mbslen(const_ntmbs_t psz)
|
||||
{ // RAD: Yeesh!
|
||||
return tss::mbscount(psz);
|
||||
}
|
||||
} // namespace tss
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -145,15 +144,14 @@ namespace tss
|
|||
|
||||
namespace tss
|
||||
{
|
||||
/// Increment and Decrement Pointers by (N)
|
||||
/// Increment and Decrement Pointers by (N)
|
||||
|
||||
//--DEC
|
||||
//--DEC
|
||||
|
||||
template< class CT >
|
||||
inline
|
||||
CT* strdec( const CT*, const CT* psz ) {
|
||||
return const_cast<CT*>( psz - 1 );
|
||||
}
|
||||
template<class CT> inline CT* strdec(const CT*, const CT* psz)
|
||||
{
|
||||
return const_cast<CT*>(psz - 1);
|
||||
}
|
||||
|
||||
#if 0
|
||||
template<>
|
||||
|
@ -164,96 +162,86 @@ namespace tss
|
|||
#endif
|
||||
|
||||
|
||||
//--INC
|
||||
//--INC
|
||||
|
||||
template< class CT >
|
||||
inline
|
||||
CT* strinc( const CT* psz )
|
||||
{
|
||||
ASSERT( psz );
|
||||
return const_cast<CT*>( ( *psz ? psz + 1 : psz ) );
|
||||
}
|
||||
template<class CT> inline CT* strinc(const CT* psz)
|
||||
{
|
||||
ASSERT(psz);
|
||||
return const_cast<CT*>((*psz ? psz + 1 : psz));
|
||||
}
|
||||
|
||||
template< class CT, class SIZET >
|
||||
inline
|
||||
CT* strinc( const CT* psz, SIZET N )
|
||||
{
|
||||
ASSERT( psz );
|
||||
return const_cast<CT*>( ( *psz ? psz + N : psz ) );
|
||||
}
|
||||
template<class CT, class SIZET> inline CT* strinc(const CT* psz, SIZET N)
|
||||
{
|
||||
ASSERT(psz);
|
||||
return const_cast<CT*>((*psz ? psz + N : psz));
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
inline
|
||||
ntmbs_t strinc( const_ntmbs_t psz )
|
||||
{
|
||||
return tss::mbsinc( psz );
|
||||
}
|
||||
template<> inline ntmbs_t strinc(const_ntmbs_t psz)
|
||||
{
|
||||
return tss::mbsinc(psz);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline
|
||||
ntmbs_t strinc( const_ntmbs_t psz, size_t N )
|
||||
{
|
||||
ntmbs_t at = const_cast<ntmbs_t>( psz );
|
||||
while ( N-- )
|
||||
at = tss::mbsinc( at );
|
||||
template<> inline ntmbs_t strinc(const_ntmbs_t psz, size_t N)
|
||||
{
|
||||
ntmbs_t at = const_cast<ntmbs_t>(psz);
|
||||
while (N--)
|
||||
at = tss::mbsinc(at);
|
||||
return at;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Byte and Character Count Mappings
|
||||
/// Byte and Character Count Mappings
|
||||
|
||||
|
||||
//--BYTES
|
||||
//--BYTES
|
||||
|
||||
template< class CT >
|
||||
size_t strsize( const CT* psz )
|
||||
{
|
||||
template<class CT> size_t strsize(const CT* psz)
|
||||
{
|
||||
const CT* at = psz;
|
||||
while ( *at ) at++;
|
||||
while (*at)
|
||||
at++;
|
||||
return (size_t)((char*)at - (char*)psz);
|
||||
}
|
||||
}
|
||||
|
||||
template< class CT >
|
||||
size_t strsize( const CT*, size_t N )
|
||||
{
|
||||
template<class CT> size_t strsize(const CT*, size_t N)
|
||||
{
|
||||
return N * sizeof(CT);
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
inline size_t strsize( const_ntmbs_t psz ) {
|
||||
return mbsbytes( psz );
|
||||
}
|
||||
template<>
|
||||
inline size_t strsize( const_ntmbs_t psz, size_t N ) {
|
||||
return mbsbytes( psz, N );
|
||||
}
|
||||
template<> inline size_t strsize(const_ntmbs_t psz)
|
||||
{
|
||||
return mbsbytes(psz);
|
||||
}
|
||||
template<> inline size_t strsize(const_ntmbs_t psz, size_t N)
|
||||
{
|
||||
return mbsbytes(psz, N);
|
||||
}
|
||||
|
||||
|
||||
//--COUNT
|
||||
//--COUNT
|
||||
|
||||
template< class CT >
|
||||
size_t strcount( const CT* psz )
|
||||
{
|
||||
template<class CT> size_t strcount(const CT* psz)
|
||||
{
|
||||
const CT* at = psz;
|
||||
while ( *at ) at++;
|
||||
while (*at)
|
||||
at++;
|
||||
return (size_t)(at - psz);
|
||||
}
|
||||
}
|
||||
|
||||
template< class CT >
|
||||
size_t strcount( const CT*, size_t N )
|
||||
{
|
||||
template<class CT> size_t strcount(const CT*, size_t N)
|
||||
{
|
||||
return N;
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
inline size_t strcount( const_ntmbs_t psz ) {
|
||||
return mbscount( psz );
|
||||
}
|
||||
template<>
|
||||
inline size_t strcount( const_ntmbs_t psz, size_t N ) {
|
||||
return mbscount( psz, N );
|
||||
}
|
||||
template<> inline size_t strcount(const_ntmbs_t psz)
|
||||
{
|
||||
return mbscount(psz);
|
||||
}
|
||||
template<> inline size_t strcount(const_ntmbs_t psz, size_t N)
|
||||
{
|
||||
return mbscount(psz, N);
|
||||
}
|
||||
|
||||
|
||||
/* These are needed! However, it would be better to just create
|
||||
|
@ -262,7 +250,7 @@ done with it */
|
|||
|
||||
#ifdef TSS_NTMBS_AWARE_SEACH_COMPLETE
|
||||
|
||||
/* CAUTION:RAD -- I changed the traversal logic from "!=" to
|
||||
/* CAUTION:RAD -- I changed the traversal logic from "!=" to
|
||||
"<" to accomodate a basic_string whose end() member does not
|
||||
correctly point after the last valid trail-byte in a string.
|
||||
Really, at != end should be correct, but I don't want to leave
|
||||
|
@ -270,197 +258,169 @@ done with it */
|
|||
under unit test and have all occurances of "at < end" changed
|
||||
to the "more on-purpose" "at != end". */
|
||||
|
||||
/// Various MULTIBYTE aware string searching routines..
|
||||
/// Various MULTIBYTE aware string searching routines..
|
||||
|
||||
//--FIND_FIRST: ITER
|
||||
//--FIND_FIRST: ITER
|
||||
|
||||
template< class InputT, class E >
|
||||
InputT
|
||||
find_first( InputT beg, InputT end, const E& item )
|
||||
{
|
||||
for ( ; beg < end && *beg != item; beg = (InputT)tss::strinc( beg ) );
|
||||
template<class InputT, class E> InputT find_first(InputT beg, InputT end, const E& item)
|
||||
{
|
||||
for (; beg < end && *beg != item; beg = (InputT)tss::strinc(beg))
|
||||
;
|
||||
return beg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--FIND_LAST: ITER
|
||||
//--FIND_LAST: ITER
|
||||
|
||||
template< class InputT, class E >
|
||||
InputT
|
||||
find_last( InputT beg, InputT end, const E& item )
|
||||
{
|
||||
template<class InputT, class E> InputT find_last(InputT beg, InputT end, const E& item)
|
||||
{
|
||||
InputT at = end;
|
||||
for ( ; beg < end ; beg = (InputT)tss::strinc( beg ) );
|
||||
if ( *beg == item )
|
||||
for (; beg < end; beg = (InputT)tss::strinc(beg))
|
||||
;
|
||||
if (*beg == item)
|
||||
at = beg;
|
||||
|
||||
return at;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--FIND_FIRST: STRING
|
||||
//--FIND_FIRST: STRING
|
||||
|
||||
template< class StrT >
|
||||
StrT::size_type
|
||||
find_first( const StrT& sin, StrT::const_reference item )
|
||||
{
|
||||
StrT::const_iterator
|
||||
beg = sin.begin();
|
||||
template<class StrT> StrT::size_type find_first(const StrT& sin, StrT::const_reference item)
|
||||
{
|
||||
StrT::const_iterator beg = sin.begin();
|
||||
end = sin.end();
|
||||
|
||||
StrT::size_type N;
|
||||
for ( N = 0; beg < end; ++N, beg = (InputT)tss::strinc( beg ) )
|
||||
if ( *beg == item )
|
||||
for (N = 0; beg < end; ++N, beg = (InputT)tss::strinc(beg))
|
||||
if (*beg == item)
|
||||
return N;
|
||||
|
||||
return StrT::npos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--FIND_LAST: STRING
|
||||
//--FIND_LAST: STRING
|
||||
|
||||
template< class StrT >
|
||||
StrT::size_type
|
||||
find_last( const StrT& sin, StrT::const_reference item )
|
||||
{
|
||||
template<class StrT> StrT::size_type find_last(const StrT& sin, StrT::const_reference item)
|
||||
{
|
||||
StrT::size_type N = 0;
|
||||
StrT::size_type nResult = StrT::npos;
|
||||
StrT::const_iterator
|
||||
beg = sin.begin();
|
||||
StrT::const_iterator beg = sin.begin();
|
||||
end = sin.end();
|
||||
|
||||
for ( ; beg < end ; beg = (InputT)tss::strinc( beg ) );
|
||||
if ( *beg == item )
|
||||
for (; beg < end; beg = (InputT)tss::strinc(beg))
|
||||
;
|
||||
if (*beg == item)
|
||||
nResult = N;
|
||||
|
||||
return N;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--FIND_FIRST_OF: ITER
|
||||
//--FIND_FIRST_OF: ITER
|
||||
|
||||
template< class InputT >
|
||||
InputT
|
||||
find_first_of(
|
||||
InputT beg,
|
||||
InputT end,
|
||||
InputT setbeg,
|
||||
InputT setend )
|
||||
{
|
||||
template<class InputT> InputT find_first_of(InputT beg, InputT end, InputT setbeg, InputT setend)
|
||||
{
|
||||
InputT at;
|
||||
for ( ; beg < end; beg = (InputT)tss::strinc( beg ) );
|
||||
for ( at = setbeg; setbeg < setend; at = (InputT)tss::strinc( at ) )
|
||||
if ( *beg == *at )
|
||||
for (; beg < end; beg = (InputT)tss::strinc(beg))
|
||||
;
|
||||
for (at = setbeg; setbeg < setend; at = (InputT)tss::strinc(at))
|
||||
if (*beg == *at)
|
||||
return beg;
|
||||
|
||||
return end;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--FIND_FIRST_OF: STRING (SAFE!!!)
|
||||
//--FIND_FIRST_OF: STRING (SAFE!!!)
|
||||
|
||||
template< class StrT >
|
||||
StrT::size_type
|
||||
find_first_of( const StrT& sin, StrT::const_iterator set )
|
||||
{
|
||||
template<class StrT> StrT::size_type find_first_of(const StrT& sin, StrT::const_iterator set)
|
||||
{
|
||||
// Point to beg of input
|
||||
StrT::iterator beg = sin.begin();
|
||||
|
||||
// Start Search
|
||||
StrT::size_type N = 0;
|
||||
for ( ; beg < sin.end(); ++N, beg = tss::strinc( beg ) )
|
||||
for ( StrT::const_iterator at = set; *at; at = tss::strinc( at ) )
|
||||
if ( *beg == *at )
|
||||
for (; beg < sin.end(); ++N, beg = tss::strinc(beg))
|
||||
for (StrT::const_iterator at = set; *at; at = tss::strinc(at))
|
||||
if (*beg == *at)
|
||||
return N;
|
||||
|
||||
return StrT::npos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--FIND_FIRST_OF: STRING (NOT SAFE!!!)
|
||||
//--FIND_FIRST_OF: STRING (NOT SAFE!!!)
|
||||
|
||||
template< class StrT >
|
||||
StrT::size_type
|
||||
find_first_of(
|
||||
const StrT& sin,
|
||||
StrT::const_iterator set,
|
||||
StrT::size_type nPos,
|
||||
StrT::size_type nCount )
|
||||
{
|
||||
template<class StrT>
|
||||
StrT::size_type find_first_of(const StrT& sin, StrT::const_iterator set, StrT::size_type nPos, StrT::size_type nCount)
|
||||
{
|
||||
ASSERT( nPos < tss::strcount( sin.begin() );
|
||||
|
||||
if ( nCount > 0 && nPos < sin.size() )
|
||||
{
|
||||
ASSERT( nCount > tss::strcount( set ) );
|
||||
ASSERT(nCount > tss::strcount(set));
|
||||
StrT::const_iterator endset; // Get end of set
|
||||
while ( nCount-- ) endset++;
|
||||
while (nCount--)
|
||||
endset++;
|
||||
|
||||
// Advance to nPos
|
||||
StrT::const_iterator at = tss::strinc( sin.begin(), nPos );
|
||||
StrT::const_iterator at = tss::strinc(sin.begin(), nPos);
|
||||
StrT::const_iterator end = sin.end();
|
||||
|
||||
// Start Search
|
||||
StrT::size_type N = 0;
|
||||
for ( ; at < end; ++N, at = tss::strinc( at ) )
|
||||
for (; at < end; ++N, at = tss::strinc(at))
|
||||
{
|
||||
if ( tss::find( set, endset, *at ) != 0 )
|
||||
if (tss::find(set, endset, *at) != 0)
|
||||
return N;
|
||||
}
|
||||
}
|
||||
|
||||
return StrT::npos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--FIND_LAST_OF: ITER
|
||||
//--FIND_LAST_OF: ITER
|
||||
|
||||
template< class InputT1, class InputT2 >
|
||||
InputT
|
||||
find_last_of(
|
||||
const InputT1 beg, const InputT1 end,
|
||||
const InputT2 setbeg, const InputT2 setend )
|
||||
{
|
||||
template<class InputT1, class InputT2>
|
||||
InputT find_last_of(const InputT1 beg, const InputT1 end, const InputT2 setbeg, const InputT2 setend)
|
||||
{
|
||||
const InputT1 ans = end;
|
||||
for ( ; beg < end; beg = tss::strinc( beg ) );
|
||||
for ( InputT2 at = setbeg; setbeg != setend; at = tss::strinc( at ) )
|
||||
if ( *beg == *at )
|
||||
for (; beg < end; beg = tss::strinc(beg))
|
||||
;
|
||||
for (InputT2 at = setbeg; setbeg != setend; at = tss::strinc(at))
|
||||
if (*beg == *at)
|
||||
ans = beg;
|
||||
|
||||
return ans;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--FIND_LAST_OF: STRING (SAFE!!!)
|
||||
//--FIND_LAST_OF: STRING (SAFE!!!)
|
||||
|
||||
template< class StrT >
|
||||
StrT::size_type
|
||||
find_last_of( const StrT& sin, StrT::const_iterator set )
|
||||
{
|
||||
template<class StrT> StrT::size_type find_last_of(const StrT& sin, StrT::const_iterator set)
|
||||
{
|
||||
StrT::size_type nResult = StrT::npos;
|
||||
StrT::size_type N = 0;
|
||||
for ( ; at < end; ++N, at = tss::strinc( at ) )
|
||||
for (; at < end; ++N, at = tss::strinc(at))
|
||||
{
|
||||
for ( StrT::const_iterator at = set; *at; at = tss::strinc( at ) )
|
||||
if ( *beg == *at )
|
||||
for (StrT::const_iterator at = set; *at; at = tss::strinc(at))
|
||||
if (*beg == *at)
|
||||
nResult = N;
|
||||
}
|
||||
|
||||
return nResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template< class StrT >
|
||||
StrT::size_type
|
||||
find_last_of(
|
||||
const StrT& sin,
|
||||
StrT::const_iterator set,
|
||||
StrT::size_type nStart,
|
||||
StrT::size_type nCount )
|
||||
template<class StrT>
|
||||
StrT::size_type 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()
|
||||
+ (nStart < _Len ? nStart : _Len - 1); ; --_U)
|
||||
for (StrT::const_iterator at = sin.begin() + (nStart < _Len ? nStart : _Len - 1);; --_U)
|
||||
if (_Tr::find(set, nCount, *_U) != 0)
|
||||
return (_U - _Ptr);
|
||||
else if (_U == _Ptr)
|
||||
|
@ -468,45 +428,39 @@ done with it */
|
|||
}
|
||||
|
||||
return StrT::npos;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:RAD -- find_first_not_of;
|
||||
// TODO:RAD -- find_last_not_of;
|
||||
// TODO:RAD -- find_first_not_of;
|
||||
// TODO:RAD -- find_last_not_of;
|
||||
|
||||
#endif//TSS_NTMBS_AWARE_SEACH_COMPLETE
|
||||
#endif //TSS_NTMBS_AWARE_SEACH_COMPLETE
|
||||
|
||||
namespace util
|
||||
{
|
||||
// Preserves bit values when enlarging a type to a size_t
|
||||
// Good for preventing sign extension
|
||||
template< class E >
|
||||
inline
|
||||
size_t
|
||||
char_to_size( E ch )
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
// Preserves bit values when enlarging a type to a size_t
|
||||
// Good for preventing sign extension
|
||||
template<class E> inline size_t char_to_size(E ch)
|
||||
{
|
||||
// if this fails, 'ch' can't be cast to a
|
||||
// size_t and preserve bit values
|
||||
// if this fails, then you must find another way
|
||||
ASSERT( sizeof( size_t ) >= sizeof( E ) );
|
||||
ASSERT(sizeof(size_t) >= sizeof(E));
|
||||
|
||||
// assert that either 'ch' is an unsigned value (no sign extension possible)
|
||||
// or that 'ch' is the same size as a size_t (no sign extension is possible as well)
|
||||
// if this fails, then you must specialize this function like we did for 'char'
|
||||
ASSERT( (int)(E)-1 > (int)0 || sizeof( size_t ) == sizeof( E ) );
|
||||
ASSERT((int)(E)-1 > (int)0 || sizeof(size_t) == sizeof(E));
|
||||
|
||||
return (size_t)ch;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
size_t
|
||||
char_to_size( char ch )
|
||||
{
|
||||
inline size_t char_to_size(char ch)
|
||||
{
|
||||
return (size_t)(unsigned char)ch;
|
||||
}
|
||||
}
|
||||
}//tss::
|
||||
}
|
||||
} // namespace util
|
||||
} // namespace tss
|
||||
|
||||
|
||||
#endif//__NTMBS_H
|
||||
|
||||
#endif //__NTMBS_H
|
||||
|
|
|
@ -91,30 +91,28 @@
|
|||
|
||||
//--PACKAGE Helpers
|
||||
|
||||
#define TSS_Package( pkg ) \
|
||||
pkg::GetInstance() // Access "the" Package obj
|
||||
#define TSS_Package(pkg) 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 ) \
|
||||
class pkg : public cPackageBase_< TCHAR > \
|
||||
#define TSS_BeginPackage(pkg) \
|
||||
class pkg : public cPackageBase_<TCHAR> \
|
||||
{ \
|
||||
public: \
|
||||
static pkg& GetInstance();
|
||||
|
||||
|
||||
#define TSS_EndPackage( pkg ) \
|
||||
};
|
||||
#define TSS_EndPackage(pkg) \
|
||||
} \
|
||||
;
|
||||
|
||||
#define TSS_ImplementPackage( pkg ) \
|
||||
#define TSS_ImplementPackage(pkg) \
|
||||
pkg& pkg::GetInstance() \
|
||||
{ \
|
||||
static bool bConstructed = false; \
|
||||
static pkg x; \
|
||||
if ( !bConstructed ) \
|
||||
if (!bConstructed) \
|
||||
{ \
|
||||
bConstructed = true; \
|
||||
x.LoadStrings(); \
|
||||
|
@ -123,52 +121,56 @@
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//--STRINGTABLE Helperfs
|
||||
|
||||
#define TSS_GetString( pkg, id ) \
|
||||
TSS_Package( pkg ).GetString( id ) // Access the Message String
|
||||
#define TSS_GetString(pkg, id) TSS_Package(pkg).GetString(id) // Access the Message String
|
||||
|
||||
|
||||
#define TSS_DECLARE_STRINGTABLE \
|
||||
public: \
|
||||
Messages::String \
|
||||
GetString( \
|
||||
Messages::ConstKeyRef id ) const { \
|
||||
return m_messages.Get( id ); } \
|
||||
public: \
|
||||
Messages::String GetString(Messages::ConstKeyRef id) const \
|
||||
{ \
|
||||
return m_messages.Get(id); \
|
||||
} \
|
||||
void LoadStrings(); \
|
||||
private: \
|
||||
\
|
||||
private: \
|
||||
Messages m_messages // Decare a Stringtable
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
#define TSS_BeginStringtable( pkg ) \
|
||||
# define TSS_BeginStringtable(pkg) \
|
||||
void pkg::LoadStrings() \
|
||||
{ cDebug d( #pkg "::LoadStrings()" ); \
|
||||
{ \
|
||||
cDebug d(#pkg "::LoadStrings()"); \
|
||||
d.TraceDebug("Loading strings for " #pkg " package.\n"); \
|
||||
Messages::Pair astr[] = { // Define a Stringtable
|
||||
#else // DEBUG
|
||||
#define TSS_BeginStringtable( pkg ) \
|
||||
# define TSS_BeginStringtable(pkg) \
|
||||
void pkg::LoadStrings() \
|
||||
{ Messages::Pair astr[] = { // Define a Stringtable
|
||||
{ \
|
||||
Messages::Pair astr[] = { // Define a Stringtable
|
||||
#endif // DEBUG
|
||||
|
||||
#define TSS_EndStringtable( pkg ) \
|
||||
}; m_messages.Put( \
|
||||
astr, astr + countof(astr) ); } // End define Strintable
|
||||
#define TSS_EndStringtable(pkg) \
|
||||
} \
|
||||
; \
|
||||
m_messages.Put(astr, astr + countof(astr)); \
|
||||
} // End define Strintable
|
||||
|
||||
|
||||
#define TSS_StringEntry( id, s ) \
|
||||
Messages::Pair( id, s ) // Stringtable Entry
|
||||
#define TSS_StringEntry(id, s) Messages::Pair(id, s) // Stringtable Entry
|
||||
|
||||
#define TSS_BeginStringIds( pns ) \
|
||||
namespace pns { \
|
||||
enum { // Define String IDs
|
||||
|
||||
#define TSS_EndStringIds( pns ) \
|
||||
}; } // End define String IDs
|
||||
#define TSS_BeginStringIds(pns) \
|
||||
namespace pns \
|
||||
{ \
|
||||
enum \
|
||||
{ // Define String IDs
|
||||
|
||||
#define TSS_EndStringIds(pns) \
|
||||
} \
|
||||
; \
|
||||
} // End define String IDs
|
||||
|
||||
|
||||
//=============================================================================
|
||||
|
@ -194,12 +196,10 @@
|
|||
//
|
||||
//
|
||||
|
||||
template< class CharT >
|
||||
class cPackageBase_
|
||||
template<class CharT> class cPackageBase_
|
||||
{
|
||||
public:
|
||||
|
||||
typedef cMessages_< int, CharT > Messages;
|
||||
public:
|
||||
typedef cMessages_<int, CharT> Messages;
|
||||
|
||||
void LoadStrings()
|
||||
{
|
||||
|
@ -207,5 +207,4 @@ class cPackageBase_
|
|||
};
|
||||
|
||||
|
||||
#endif//__PACKAGE_H
|
||||
|
||||
#endif //__PACKAGE_H
|
||||
|
|
|
@ -34,11 +34,11 @@
|
|||
//
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifndef __PLATFORM_H
|
||||
#define __PLATFORM_H
|
||||
# define __PLATFORM_H
|
||||
|
||||
//NOTE: Autoconf is strongly preferred as the Right Way to detect platform-specific features/behaviors.
|
||||
// These macros should really only be used when autoconf can't get the job done.
|
||||
|
@ -49,57 +49,57 @@
|
|||
// For each of these "enumerations" we create unique integers identifying each
|
||||
// variation. We group similar items together, such as OS_REDHAT and OS_SLACKWARE
|
||||
|
||||
#define OS_UNKNOWN 0
|
||||
# define OS_UNKNOWN 0
|
||||
|
||||
#define OS_WIN32 0x0101
|
||||
#define OS_CYGWIN 0x0102
|
||||
#define OS_DOS_DJGPP 0x0103
|
||||
# define OS_WIN32 0x0101
|
||||
# define OS_CYGWIN 0x0102
|
||||
# define OS_DOS_DJGPP 0x0103
|
||||
|
||||
#define OS_LINUX 0x0201
|
||||
#define OS_ANDROID 0x0202
|
||||
# define OS_LINUX 0x0201
|
||||
# define OS_ANDROID 0x0202
|
||||
|
||||
#define OS_FREEBSD 0x0301
|
||||
#define OS_NETBSD 0x0302
|
||||
#define OS_OPENBSD 0x0303
|
||||
#define OS_DARWIN 0x0304
|
||||
#define OS_DRAGONFLYBSD 0x0305
|
||||
#define OS_MIDNIGHTBSD 0x0306
|
||||
#define OS_MIRBSD 0x0307
|
||||
#define OS_BITRIG 0x0308
|
||||
#define OS_LIBERTYBSD 0x0309
|
||||
# define OS_FREEBSD 0x0301
|
||||
# define OS_NETBSD 0x0302
|
||||
# define OS_OPENBSD 0x0303
|
||||
# define OS_DARWIN 0x0304
|
||||
# define OS_DRAGONFLYBSD 0x0305
|
||||
# define OS_MIDNIGHTBSD 0x0306
|
||||
# define OS_MIRBSD 0x0307
|
||||
# define OS_BITRIG 0x0308
|
||||
# define OS_LIBERTYBSD 0x0309
|
||||
|
||||
#define OS_SOLARIS 0x0400
|
||||
#define OS_AIX 0x0401
|
||||
#define OS_HPUX 0x0402
|
||||
#define OS_IRIX 0x0403
|
||||
#define OS_OSF1 0x0404
|
||||
# define OS_SOLARIS 0x0400
|
||||
# define OS_AIX 0x0401
|
||||
# define OS_HPUX 0x0402
|
||||
# define OS_IRIX 0x0403
|
||||
# define OS_OSF1 0x0404
|
||||
|
||||
#define OS_MINIX 0x0501
|
||||
#define OS_HURD 0x0502
|
||||
#define OS_HAIKU 0x0503
|
||||
#define OS_SYLLABLE 0x0504
|
||||
#define OS_SKYOS 0x0505
|
||||
#define OS_SORTIX 0x0506
|
||||
#define OS_MINT 0x0507
|
||||
#define OS_AROS 0x0508
|
||||
#define OS_RTEMS 0x0509
|
||||
#define OS_RISCOS 0x050A
|
||||
#define OS_REDOX 0x050B
|
||||
#define OS_QNX 0x050C
|
||||
# define OS_MINIX 0x0501
|
||||
# define OS_HURD 0x0502
|
||||
# define OS_HAIKU 0x0503
|
||||
# define OS_SYLLABLE 0x0504
|
||||
# define OS_SKYOS 0x0505
|
||||
# define OS_SORTIX 0x0506
|
||||
# define OS_MINT 0x0507
|
||||
# define OS_AROS 0x0508
|
||||
# define OS_RTEMS 0x0509
|
||||
# define OS_RISCOS 0x050A
|
||||
# define OS_REDOX 0x050B
|
||||
# define OS_QNX 0x050C
|
||||
|
||||
#define COMP_UNKNOWN 0
|
||||
#define COMP_GCC 0x0001
|
||||
#define COMP_CLANG 0x0002
|
||||
# define COMP_UNKNOWN 0
|
||||
# define COMP_GCC 0x0001
|
||||
# define COMP_CLANG 0x0002
|
||||
|
||||
#define COMP_MSVC 0x0101
|
||||
#define COMP_KAI_GCC 0x0201
|
||||
#define COMP_KAI_SUNPRO 0x0202
|
||||
#define COMP_KAI_GLIBC 0x0203
|
||||
#define COMP_KAI_VISUALAGE 0x0204
|
||||
#define COMP_KAI_HPANSIC 0x0205
|
||||
#define COMP_KAI_IRIX 0x0206
|
||||
#define COMP_KAI_OSF1ALPHA 0x0207
|
||||
#define COMP_SUNPRO 0x0301
|
||||
# define COMP_MSVC 0x0101
|
||||
# define COMP_KAI_GCC 0x0201
|
||||
# define COMP_KAI_SUNPRO 0x0202
|
||||
# define COMP_KAI_GLIBC 0x0203
|
||||
# define COMP_KAI_VISUALAGE 0x0204
|
||||
# define COMP_KAI_HPANSIC 0x0205
|
||||
# define COMP_KAI_IRIX 0x0206
|
||||
# define COMP_KAI_OSF1ALPHA 0x0207
|
||||
# define COMP_SUNPRO 0x0301
|
||||
|
||||
//=============================================================================
|
||||
// Platform detection
|
||||
|
@ -116,138 +116,137 @@
|
|||
// section. Use the following sections for anything that does not fall into
|
||||
// the above catagories.
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define OS OS_WIN32
|
||||
#define IS_WIN32 1
|
||||
# if defined(_WIN32)
|
||||
# define OS OS_WIN32
|
||||
# define IS_WIN32 1
|
||||
|
||||
#elif defined(__CYGWIN__)
|
||||
#define OS OS_CYGWIN
|
||||
#define IS_CYGWIN 1
|
||||
# elif defined(__CYGWIN__)
|
||||
# define OS OS_CYGWIN
|
||||
# define IS_CYGWIN 1
|
||||
|
||||
#elif defined(__DJGPP__)
|
||||
#define OS OS_DOS_DJGPP
|
||||
#define IS_DOS_DJGPP 1
|
||||
# elif defined(__DJGPP__)
|
||||
# define OS OS_DOS_DJGPP
|
||||
# define IS_DOS_DJGPP 1
|
||||
|
||||
|
||||
#elif defined(__ANDROID__)
|
||||
#define OS OS_ANDROID
|
||||
#define IS_ANDROID 1
|
||||
# elif defined(__ANDROID__)
|
||||
# define OS OS_ANDROID
|
||||
# define IS_ANDROID 1
|
||||
|
||||
#elif defined(__linux__)
|
||||
#define OS OS_LINUX
|
||||
#define IS_LINUX 1
|
||||
# elif defined(__linux__)
|
||||
# define OS OS_LINUX
|
||||
# define IS_LINUX 1
|
||||
|
||||
|
||||
// A herd of BSDs. Have to detect MidnightBSD before FreeBSD, and MirOS & Bitrig before OpenBSD
|
||||
// because they also define symbols for their ancestor BSDs.
|
||||
#elif defined(__DragonFly__)
|
||||
#define OS OS_DRAGONFLYBSD
|
||||
#define IS_DRAGONFLYBSD 1
|
||||
# elif defined(__DragonFly__)
|
||||
# define OS OS_DRAGONFLYBSD
|
||||
# define IS_DRAGONFLYBSD 1
|
||||
|
||||
#elif defined(__MidnightBSD__)
|
||||
#define OS OS_MIDNIGHTBSD
|
||||
#define IS_MIDNIGHTBSD 1
|
||||
# elif defined(__MidnightBSD__)
|
||||
# define OS OS_MIDNIGHTBSD
|
||||
# define IS_MIDNIGHTBSD 1
|
||||
|
||||
#elif defined(__FreeBSD__)
|
||||
#define OS OS_FREEBSD
|
||||
#define IS_FREEBSD 1
|
||||
# elif defined(__FreeBSD__)
|
||||
# define OS OS_FREEBSD
|
||||
# define IS_FREEBSD 1
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
#define OS OS_NETBSD
|
||||
#define IS_NETBSD 1
|
||||
# elif defined(__NetBSD__)
|
||||
# define OS OS_NETBSD
|
||||
# define IS_NETBSD 1
|
||||
|
||||
#elif defined(__MirBSD__)
|
||||
#define OS OS_MIRBSD
|
||||
#define IS_MIRBSD 1
|
||||
# elif defined(__MirBSD__)
|
||||
# define OS OS_MIRBSD
|
||||
# define IS_MIRBSD 1
|
||||
|
||||
#elif defined(__Bitrig__)
|
||||
#define OS OS_BITRIG
|
||||
#define IS_BITRIG 1
|
||||
# elif defined(__Bitrig__)
|
||||
# define OS OS_BITRIG
|
||||
# define IS_BITRIG 1
|
||||
|
||||
#elif defined(TW_LibertyBSD)
|
||||
#define OS OS_LIBERTYBSD
|
||||
#define IS_LIBERTYBSD 1
|
||||
# elif defined(TW_LibertyBSD)
|
||||
# define OS OS_LIBERTYBSD
|
||||
# define IS_LIBERTYBSD 1
|
||||
|
||||
#elif defined(__OpenBSD__)
|
||||
#define OS OS_OPENBSD
|
||||
#define IS_OPENBSD 1
|
||||
# elif defined(__OpenBSD__)
|
||||
# define OS OS_OPENBSD
|
||||
# define IS_OPENBSD 1
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
#define OS OS_DARWIN
|
||||
#define IS_DARWIN 1
|
||||
# elif defined(__APPLE__)
|
||||
# define OS OS_DARWIN
|
||||
# define IS_DARWIN 1
|
||||
|
||||
|
||||
#elif defined(__sun)
|
||||
#define OS OS_SOLARIS
|
||||
#define IS_SOLARIS 1
|
||||
# elif defined(__sun)
|
||||
# define OS OS_SOLARIS
|
||||
# define IS_SOLARIS 1
|
||||
|
||||
#elif defined(_AIX)
|
||||
#define OS OS_AIX
|
||||
#define IS_AIX 1
|
||||
# elif defined(_AIX)
|
||||
# define OS OS_AIX
|
||||
# define IS_AIX 1
|
||||
|
||||
#elif defined (__hpux)
|
||||
#define OS OS_HPUX
|
||||
#define IS_HPUX 1
|
||||
# elif defined(__hpux)
|
||||
# define OS OS_HPUX
|
||||
# define IS_HPUX 1
|
||||
|
||||
#elif defined(__sgi)
|
||||
#define OS OS_IRIX
|
||||
#define IS_IRIX 1
|
||||
# elif defined(__sgi)
|
||||
# define OS OS_IRIX
|
||||
# define IS_IRIX 1
|
||||
|
||||
#elif defined(TRU64) || defined(__OSF1__)
|
||||
#define OS OS_OSF1
|
||||
#define IS_OSF1 1
|
||||
# elif defined(TRU64) || defined(__OSF1__)
|
||||
# define OS OS_OSF1
|
||||
# define IS_OSF1 1
|
||||
|
||||
|
||||
#elif defined(__minix__)
|
||||
#define OS OS_MINIX
|
||||
#define IS_MINIX 1
|
||||
# elif defined(__minix__)
|
||||
# define OS OS_MINIX
|
||||
# define IS_MINIX 1
|
||||
|
||||
#elif defined(__gnu_hurd__)
|
||||
#define OS OS_HURD
|
||||
#define IS_HURD 1
|
||||
# elif defined(__gnu_hurd__)
|
||||
# define OS OS_HURD
|
||||
# define IS_HURD 1
|
||||
|
||||
#elif defined(__HAIKU__)
|
||||
#define OS OS_HAIKU
|
||||
#define IS_HAIKU 1
|
||||
# elif defined(__HAIKU__)
|
||||
# define OS OS_HAIKU
|
||||
# define IS_HAIKU 1
|
||||
|
||||
#elif defined(__SYLLABLE__)
|
||||
#define OS OS_SYLLABLE
|
||||
#define IS_SYLLABLE 1
|
||||
# elif defined(__SYLLABLE__)
|
||||
# define OS OS_SYLLABLE
|
||||
# define IS_SYLLABLE 1
|
||||
|
||||
#elif defined(SKYOS)
|
||||
#define OS OS_SKYOS
|
||||
#define IS_SKYOS 1
|
||||
# elif defined(SKYOS)
|
||||
# define OS OS_SKYOS
|
||||
# define IS_SKYOS 1
|
||||
|
||||
#elif defined(_SORTIX_SOURCE)
|
||||
#define OS OS_SORTIX
|
||||
#define IS_SORTIX 1
|
||||
# elif defined(_SORTIX_SOURCE)
|
||||
# define OS OS_SORTIX
|
||||
# define IS_SORTIX 1
|
||||
|
||||
#elif defined(__MINT__)
|
||||
#define OS OS_MINT
|
||||
#define IS_MINT 1
|
||||
# elif defined(__MINT__)
|
||||
# define OS OS_MINT
|
||||
# define IS_MINT 1
|
||||
|
||||
#elif defined(__AROS__)
|
||||
#define OS OS_AROS
|
||||
#define IS_AROS 1
|
||||
# elif defined(__AROS__)
|
||||
# define OS OS_AROS
|
||||
# define IS_AROS 1
|
||||
|
||||
#elif defined(__rtems__)
|
||||
#define OS OS_RTEMS
|
||||
#define IS_RTEMS 1
|
||||
# elif defined(__rtems__)
|
||||
# define OS OS_RTEMS
|
||||
# define IS_RTEMS 1
|
||||
|
||||
#elif defined(__riscos__)
|
||||
#define OS OS_RISCOS
|
||||
#define IS_RISCOS 1
|
||||
# elif defined(__riscos__)
|
||||
# define OS OS_RISCOS
|
||||
# define IS_RISCOS 1
|
||||
|
||||
#elif defined(__redox__)
|
||||
#define OS OS_REDOX
|
||||
#define IS_REDOX 1
|
||||
# elif defined(__redox__)
|
||||
# define OS OS_REDOX
|
||||
# define IS_REDOX 1
|
||||
|
||||
#elif defined(__QNX__)
|
||||
#define OS OS_QNX
|
||||
#define IS_QNX 1
|
||||
|
||||
#endif
|
||||
# elif defined(__QNX__)
|
||||
# define OS OS_QNX
|
||||
# define IS_QNX 1
|
||||
|
||||
# endif
|
||||
|
||||
|
||||
/* XXX: COMP may now not resolve, because autoconf may
|
||||
|
@ -262,9 +261,9 @@
|
|||
*
|
||||
* PH - 20010311
|
||||
*/
|
||||
#if !defined(COMP) && !defined(HAVE_GCC)
|
||||
#error COMP definition did not resolve. Check "platform.h".
|
||||
#endif
|
||||
# if !defined(COMP) && !defined(HAVE_GCC)
|
||||
# error COMP definition did not resolve. Check "platform.h".
|
||||
# endif
|
||||
|
||||
//=============================================================================
|
||||
// Platform Macros (a.k.a. "IS_" macros)
|
||||
|
@ -293,89 +292,91 @@
|
|||
|
||||
|
||||
// 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_MSVC (COMP == COMP_MSVC)
|
||||
#define IS_SUNPRO (COMP == COMP_SUNPRO)
|
||||
# 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_SUNPRO (COMP == COMP_SUNPRO)
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
// Unicode
|
||||
#define SUPPORTS_UNICODE IS_WIN32 // The OS supports Unicode
|
||||
# define SUPPORTS_UNICODE IS_WIN32 // The OS supports Unicode
|
||||
|
||||
// KAI 3.4 uses a much improved stl
|
||||
#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
|
||||
#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 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_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 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))
|
||||
|
||||
// Threading API
|
||||
// TODO:mdb -- this is not complete or rigorous on the unix side!!!
|
||||
#define SUPPORTS_WIN32_THREADS IS_WIN32
|
||||
#define SUPPORTS_POSIX_THREADS (!SUPPORTS_WIN32_THREADS)
|
||||
# define SUPPORTS_WIN32_THREADS IS_WIN32
|
||||
# define SUPPORTS_POSIX_THREADS (!SUPPORTS_WIN32_THREADS)
|
||||
|
||||
// Miscellaneous
|
||||
#define WCHAR_IS_16_BITS IS_WIN32
|
||||
#define WCHAR_IS_32_BITS IS_UNIX
|
||||
#define WCHAR_REP_IS_UCS2 IS_WIN32
|
||||
# define WCHAR_IS_16_BITS IS_WIN32
|
||||
# define WCHAR_IS_32_BITS IS_UNIX
|
||||
# define WCHAR_REP_IS_UCS2 IS_WIN32
|
||||
// msystem+mpopen fail on Syllable, so use the libc equivalents until we figure out why.
|
||||
// TODO: Figure out why.
|
||||
#define USES_MPOPEN (IS_UNIX && !IS_SYLLABLE)
|
||||
#define USES_MSYSTEM (IS_UNIX && !IS_SYLLABLE)
|
||||
#define SUPPORTS_WCHART IS_WIN32 // TODO: Remove after getting new ver of KAI
|
||||
#define USES_GLIBC ((COMP == COMP_KAI_GLIBC) || HAVE_GCC)
|
||||
#define SUPPORTS_MEMBER_TEMPLATES ( ! IS_SUNPRO )
|
||||
#define SUPPORTS_EXPLICIT_TEMPLATE_FUNC_INST ( ! IS_SUNPRO )
|
||||
# define USES_MPOPEN (IS_UNIX && !IS_SYLLABLE)
|
||||
# define USES_MSYSTEM (IS_UNIX && !IS_SYLLABLE)
|
||||
# define SUPPORTS_WCHART IS_WIN32 // TODO: Remove after getting new ver of KAI
|
||||
# define USES_GLIBC ((COMP == COMP_KAI_GLIBC) || HAVE_GCC)
|
||||
# define SUPPORTS_MEMBER_TEMPLATES (!IS_SUNPRO)
|
||||
# define SUPPORTS_EXPLICIT_TEMPLATE_FUNC_INST (!IS_SUNPRO)
|
||||
|
||||
#define SUPPORTS_POSIX_SIGNALS (!IS_DOS_DJGPP)
|
||||
#define SUPPORTS_NETWORKING (!IS_SORTIX && !IS_DOS_DJGPP && !IS_REDOX)
|
||||
#define SUPPORTS_SYSLOG (HAVE_SYSLOG_H && !IS_SKYOS && !IS_RISCOS)
|
||||
#define NEEDS_SWAB_IMPL (IS_CYGWIN || IS_SYLLABLE || IS_ANDROID || IS_SORTIX)
|
||||
#define USES_MBLEN (!IS_ANDROID && !IS_AROS)
|
||||
#define USES_DEVICE_PATH (IS_AROS || IS_DOS_DJGPP || IS_RISCOS || IS_REDOX)
|
||||
#define ICONV_CONST_SOURCE (IS_MINIX)
|
||||
#define SUPPORTS_DIRECT_IO (IS_LINUX)
|
||||
# define SUPPORTS_POSIX_SIGNALS (!IS_DOS_DJGPP)
|
||||
# define SUPPORTS_NETWORKING (!IS_SORTIX && !IS_DOS_DJGPP && !IS_REDOX)
|
||||
# define SUPPORTS_SYSLOG (HAVE_SYSLOG_H && !IS_SKYOS && !IS_RISCOS)
|
||||
# define NEEDS_SWAB_IMPL (IS_CYGWIN || IS_SYLLABLE || IS_ANDROID || IS_SORTIX)
|
||||
# define USES_MBLEN (!IS_ANDROID && !IS_AROS)
|
||||
# define USES_DEVICE_PATH (IS_AROS || IS_DOS_DJGPP || IS_RISCOS || IS_REDOX)
|
||||
# define ICONV_CONST_SOURCE (IS_MINIX)
|
||||
# define SUPPORTS_DIRECT_IO (IS_LINUX)
|
||||
// Linux is the only platform where direct i/o hashing has been tested & works properly so far.
|
||||
|
||||
#define SUPPORTS_TERMIOS (!IS_RTEMS && !IS_REDOX)
|
||||
# define SUPPORTS_TERMIOS (!IS_RTEMS && !IS_REDOX)
|
||||
// RTEMS errors are probably just a buildsys issue & this will change or go away.
|
||||
// Redox will probably implement this in the future.
|
||||
|
||||
#define CAN_UNLINK_WHILE_OPEN (!IS_AROS && !IS_RISCOS && !IS_REDOX && !IS_DOS_DJGPP)
|
||||
# define CAN_UNLINK_WHILE_OPEN (!IS_AROS && !IS_RISCOS && !IS_REDOX && !IS_DOS_DJGPP)
|
||||
|
||||
#define SUPPORTS_DOUBLE_SLASH_PATH (IS_CYGWIN)
|
||||
# define SUPPORTS_DOUBLE_SLASH_PATH (IS_CYGWIN)
|
||||
// POSIX standard says paths beginning with 2 slashes are "implementation defined"
|
||||
// (see http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11 )
|
||||
// The only platform OST works on (afaik) that actually defines a double-slash behavior is Cygwin
|
||||
// which uses this syntax for UNC paths. So we'll allow leading double slashes there, but
|
||||
// continue removing them on all other platforms
|
||||
|
||||
#define USE_DEV_URANDOM (HAVE_DEV_URANDOM && ENABLE_DEV_URANDOM)
|
||||
# define USE_DEV_URANDOM (HAVE_DEV_URANDOM && ENABLE_DEV_URANDOM)
|
||||
|
||||
//=============================================================================
|
||||
// Miscellaneous
|
||||
//
|
||||
// Put all items that are not an "IS_" macro here.
|
||||
|
||||
#if IS_BYTE_ALIGNED
|
||||
#define BYTE_ALIGN 8
|
||||
#else
|
||||
#error Unknown Byte alignment
|
||||
#endif
|
||||
# if IS_BYTE_ALIGNED
|
||||
# define BYTE_ALIGN 8
|
||||
# else
|
||||
# error Unknown Byte alignment
|
||||
# endif
|
||||
|
||||
// A scalar that matches the sizeof a pointer
|
||||
typedef unsigned long ptr_size_type; // true for all of our current platforms
|
||||
// TODO: I would like to use a XXXX_t like name
|
||||
|
||||
// Check integer representation
|
||||
#if !(USES_2S_COMPLEMENT)
|
||||
#error "Tripwire will only work on a 2's complement CPU. Check \"platform.h\"."
|
||||
#endif
|
||||
|
||||
|
||||
# if !(USES_2S_COMPLEMENT)
|
||||
# error "Tripwire will only work on a 2's complement CPU. Check \"platform.h\"."
|
||||
# endif
|
||||
|
||||
|
||||
#endif // __PLATFORM_H
|
||||
|
||||
|
|
|
@ -58,9 +58,9 @@ struct cRefCountObj_Debug
|
|||
{
|
||||
RefSet::iterator i;
|
||||
cDebug d("cRefCountObj_Debug");
|
||||
if(gpRefCountObj_Objects)
|
||||
if (gpRefCountObj_Objects)
|
||||
{
|
||||
for(i = gpRefCountObj_Objects->begin(); i != gpRefCountObj_Objects->end(); i++)
|
||||
for (i = gpRefCountObj_Objects->begin(); i != gpRefCountObj_Objects->end(); i++)
|
||||
{
|
||||
d.TraceNever("Refrence Counted Object %p still exists\n", *i);
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ cRefCountObj::cRefCountObj()
|
|||
{
|
||||
mRefCount = 1;
|
||||
|
||||
//std::cout << "Allocated RefObj(" << std::hex << (int)this << ")\n";
|
||||
//std::cout << "Allocated RefObj(" << std::hex << (int)this << ")\n";
|
||||
|
||||
#ifdef DEBUG
|
||||
++objectCounter;
|
||||
|
@ -83,7 +83,7 @@ cRefCountObj::cRefCountObj()
|
|||
cDebug d("cRefCountObj::cRefCountObj");
|
||||
d.TraceNever("Object Created[%p] %s\n", this, typeid(*this).name());
|
||||
|
||||
if(! gpRefCountObj_Objects)
|
||||
if (!gpRefCountObj_Objects)
|
||||
gpRefCountObj_Objects = new RefSet;
|
||||
gpRefCountObj_Objects->insert(this);
|
||||
#endif
|
||||
|
@ -93,22 +93,22 @@ cRefCountObj::~cRefCountObj()
|
|||
{
|
||||
ASSERT(mRefCount == 0);
|
||||
|
||||
//std::cout << "Deleted RefObj(" << std::hex << (int)this << ")\n";
|
||||
//std::cout << "Deleted RefObj(" << std::hex << (int)this << ")\n";
|
||||
|
||||
#ifdef DEBUG
|
||||
--objectCounter;
|
||||
cDebug d("cRefCountObj::~cRefCountObj");
|
||||
d.TraceNever("Object Destroyed[%p] %s Objects Left = %d\n", this, typeid(*this).name(), objectCounter);
|
||||
if(objectCounter == 0)
|
||||
if (objectCounter == 0)
|
||||
{
|
||||
d.TraceDebug("****** All Reference Counted Objects Destroyed! ******\n") ;
|
||||
d.TraceDebug("****** All Reference Counted Objects Destroyed! ******\n");
|
||||
}
|
||||
|
||||
ASSERT(gpRefCountObj_Objects);
|
||||
RefSet::const_iterator i = gpRefCountObj_Objects->find(this);
|
||||
ASSERT(i != gpRefCountObj_Objects->end());
|
||||
gpRefCountObj_Objects->erase(this);
|
||||
if(gpRefCountObj_Objects->size() == 0)
|
||||
if (gpRefCountObj_Objects->size() == 0)
|
||||
{
|
||||
delete gpRefCountObj_Objects;
|
||||
gpRefCountObj_Objects = 0;
|
||||
|
@ -128,9 +128,9 @@ void cRefCountObj::AddRef() const
|
|||
|
||||
++mRefCount;
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
++referenceCounter;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void cRefCountObj::Release() const
|
||||
|
@ -140,13 +140,12 @@ void cRefCountObj::Release() const
|
|||
Delete();
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
--referenceCounter;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void cRefCountObj::Delete() const
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,10 @@ public:
|
|||
virtual void AddRef() 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
|
||||
protected:
|
||||
virtual ~cRefCountObj();
|
||||
|
@ -82,6 +85,7 @@ private:
|
|||
static int objectCounter;
|
||||
static int referenceCounter;
|
||||
friend void TestRefCountObj();
|
||||
|
||||
public:
|
||||
static bool AllRefCountObjDestoryed()
|
||||
{
|
||||
|
@ -91,4 +95,3 @@ public:
|
|||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -51,13 +51,12 @@
|
|||
#include "error.h" // for: eInternal
|
||||
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Classes Declared in this module
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
template< class KEY, class RSC > class cResources_;
|
||||
template< class KEY, class CHR > class cMessages_;
|
||||
template<class KEY, class RSC> class cResources_;
|
||||
template<class KEY, class CHR> class cMessages_;
|
||||
|
||||
|
||||
//=============================================================================
|
||||
|
@ -75,19 +74,15 @@ template< class KEY, class CHR > class cMessages_;
|
|||
// INVARIANTS:
|
||||
//
|
||||
//
|
||||
template< class KeyT, class RscT >
|
||||
class cResources_
|
||||
template<class KeyT, class RscT> class cResources_
|
||||
{
|
||||
//--Type Definitions
|
||||
|
||||
private:
|
||||
|
||||
typedef
|
||||
std::map< KeyT, RscT > Table; // Storage Rep
|
||||
private:
|
||||
typedef std::map<KeyT, RscT> Table; // Storage Rep
|
||||
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
// Type definitions
|
||||
|
||||
typedef KeyT Key; // The resource id
|
||||
|
@ -101,35 +96,30 @@ class cResources_
|
|||
typedef typename Table::value_type Pair;
|
||||
|
||||
|
||||
|
||||
//--Interface.
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
// Observers
|
||||
|
||||
ConstValueRef Get( ConstKeyRef ) const;
|
||||
ConstValueRef Get(ConstKeyRef) const;
|
||||
|
||||
|
||||
// Modifiers
|
||||
|
||||
void Put( const Pair*, const Pair* );
|
||||
void Put( ConstKeyRef, Value );
|
||||
void Put(const Pair*, const Pair*);
|
||||
void Put(ConstKeyRef, Value);
|
||||
|
||||
|
||||
//--Implementation.
|
||||
|
||||
protected:
|
||||
|
||||
protected:
|
||||
static ConstValueRef DefaultValueRef(); // NOTE:
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
Table m_table;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//=============================================================================
|
||||
// cMessages_<KEY,CHAR> -- Specialization of Resources_ for message strings
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -168,82 +158,70 @@ class cResources_
|
|||
// must be a valid character type as defined by the STDCPP standard.
|
||||
//
|
||||
//
|
||||
template< class KeyT, class CharT >
|
||||
class cMessages_ : public cResources_< KeyT, const CharT* >
|
||||
template<class KeyT, class CharT> class cMessages_ : public cResources_<KeyT, const CharT*>
|
||||
{
|
||||
//--Type definitions
|
||||
|
||||
protected:
|
||||
|
||||
typedef
|
||||
cResources_<KeyT, const CharT* >
|
||||
Resources;
|
||||
|
||||
public:
|
||||
protected:
|
||||
typedef cResources_<KeyT, const CharT*> Resources;
|
||||
|
||||
public:
|
||||
typedef std::basic_string<CharT> String;
|
||||
typedef const KeyT& ConstKeyRef;
|
||||
|
||||
|
||||
//--Interface.
|
||||
|
||||
public:
|
||||
|
||||
String Get ( ConstKeyRef ) const;
|
||||
std::string GetAnsi( ConstKeyRef ) const;
|
||||
public:
|
||||
String Get(ConstKeyRef) const;
|
||||
std::string GetAnsi(ConstKeyRef) const;
|
||||
#if SUPPORTS_WCHART
|
||||
std::wstring GetWide( ConstKeyRef ) const;
|
||||
#endif//SUPPORTS_WCHART
|
||||
std::wstring GetWide(ConstKeyRef) const;
|
||||
#endif //SUPPORTS_WCHART
|
||||
};
|
||||
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// IMPLEMENTATION: cResources_<KEY_TYPE, RESOURCE_TYPE>
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
// NOTE: Macros to ease any changes in template arguments
|
||||
|
||||
#define Resource_Template template< class KeyT, class RscT >
|
||||
#define Resource_Class cResources_< KeyT, RscT >
|
||||
#define Resource_Template template<class KeyT, class RscT>
|
||||
#define Resource_Class cResources_<KeyT, RscT>
|
||||
|
||||
|
||||
Resource_Template
|
||||
void Resource_Class::Put( const Pair* beg, const Pair* end )
|
||||
Resource_Template 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)
|
||||
{
|
||||
if ( !m_table.insert( *at ).second )
|
||||
if (!m_table.insert(*at).second)
|
||||
{
|
||||
ASSERTMSG( 0, "Resource key already exists!" );
|
||||
ASSERTMSG(0, "Resource key already exists!");
|
||||
// throw eInternal( "Resource key already exists!" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// By value allows the user to Resource_table.Put( 6, "Literal" );
|
||||
Resource_Template
|
||||
inline
|
||||
void Resource_Class::Put( ConstKeyRef id, Value sResource )
|
||||
Resource_Template 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)
|
||||
{
|
||||
ASSERTMSG( 0, "Resource key already exists!" );
|
||||
ASSERTMSG(0, "Resource key already exists!");
|
||||
// throw eInternal( "Resource key already exists!" );
|
||||
}
|
||||
}
|
||||
|
||||
Resource_Template
|
||||
typename Resource_Class::ConstValueRef
|
||||
Resource_Class::Get( ConstKeyRef id ) const
|
||||
Resource_Template 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);
|
||||
|
||||
if ( at == m_table.end() )
|
||||
if (at == m_table.end())
|
||||
{
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
std::cerr << "*** Error Resource_Class::Get() [" __FILE__ ":" << __LINE__ << "]: Resource not found\n";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return DefaultValueRef();
|
||||
}
|
||||
|
@ -253,9 +231,7 @@ Resource_Class::Get( ConstKeyRef id ) const
|
|||
}
|
||||
}
|
||||
|
||||
Resource_Template
|
||||
typename Resource_Class::ConstValueRef
|
||||
Resource_Class::DefaultValueRef()
|
||||
Resource_Template typename Resource_Class::ConstValueRef Resource_Class::DefaultValueRef()
|
||||
{
|
||||
static Value _default;
|
||||
return _default;
|
||||
|
@ -266,27 +242,20 @@ Resource_Class::DefaultValueRef()
|
|||
#undef Resource_Class //Resources_<KeyT,RscT>
|
||||
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// IMPLEMENTATION: cMessages_<KEY_TYPE, RESOURCE_TYPE>
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
// NOTE: Macros to ease any changes in template arguments
|
||||
|
||||
#define Message_Template template< class KeyT, class CharT >
|
||||
#define Message_Class cMessages_< KeyT, CharT >
|
||||
#define Message_Template template<class KeyT, class CharT>
|
||||
#define Message_Class cMessages_<KeyT, CharT>
|
||||
|
||||
|
||||
Message_Template
|
||||
inline
|
||||
typename Message_Class::String
|
||||
Message_Class::Get( ConstKeyRef id ) const
|
||||
Message_Template inline typename Message_Class::String Message_Class::Get(ConstKeyRef id) const
|
||||
{
|
||||
typename Message_Class::Value msg = Resources::Get( id );
|
||||
return
|
||||
( msg == this->DefaultValueRef() )
|
||||
? String()
|
||||
: String( msg );
|
||||
typename Message_Class::Value msg = Resources::Get(id);
|
||||
return (msg == this->DefaultValueRef()) ? String() : String(msg);
|
||||
}
|
||||
|
||||
|
||||
|
@ -294,86 +263,69 @@ Message_Class::Get( ConstKeyRef id ) const
|
|||
|
||||
namespace tss
|
||||
{
|
||||
namespace rsc
|
||||
{
|
||||
/* WARNING:RAD -- Cannot use StringUtil or CodeConvert since
|
||||
namespace rsc
|
||||
{
|
||||
/* WARNING:RAD -- Cannot use StringUtil or CodeConvert since
|
||||
these use ErrorMessages and String Resources! */
|
||||
|
||||
inline
|
||||
void
|
||||
ToNTMBS( std::string& nbs, const std::string& src )
|
||||
{
|
||||
nbs.assign( src );
|
||||
}
|
||||
|
||||
#if SUPPORTS_WCHART
|
||||
|
||||
inline
|
||||
void
|
||||
ToNTMBS( std::string& nbs, const std::wstring& wcs )
|
||||
{
|
||||
nbs.resize( MB_CUR_MAX * wcs.size() );
|
||||
|
||||
size_t nWrote =
|
||||
::wcstombs(
|
||||
const_cast< char * >( nbs.c_str() ),
|
||||
wcs.c_str(), nbs.size() + 1 );
|
||||
|
||||
if ( nWrote == (size_t)-1 )
|
||||
{
|
||||
ASSERTMSG( false, "Conversion error in cMessages_!" );
|
||||
// throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
}
|
||||
|
||||
nbs.resize( nWrote );
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
ToNTWCS( std::wstring& dst, const std::wstring& src )
|
||||
{
|
||||
dst.assign( src );
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
ToNTWCS( std::wstring& wcs, const std::string& nbs )
|
||||
{
|
||||
wcs.resize( nbs.size() );
|
||||
|
||||
size_t nWrote =
|
||||
::mbstowcs(
|
||||
const_cast< wchar_t * >( wcs.c_str() ),
|
||||
nbs.c_str(), wcs.size() + 1 );
|
||||
|
||||
if ( nWrote == (size_t)-1 )
|
||||
{
|
||||
ASSERTMSG( false, "Conversion error in cMessages_!" );
|
||||
// throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
}
|
||||
|
||||
wcs.resize( nWrote );
|
||||
}
|
||||
#endif//SUPPORTS_WCHART
|
||||
}//rsc::
|
||||
}//tss::
|
||||
|
||||
|
||||
Message_Template
|
||||
inline
|
||||
std::string
|
||||
Message_Class::GetAnsi( ConstKeyRef id ) const
|
||||
inline void ToNTMBS(std::string& nbs, const std::string& src)
|
||||
{
|
||||
typename Message_Class::Value msg = Resources::Get( id );
|
||||
nbs.assign(src);
|
||||
}
|
||||
|
||||
if ( msg == this->DefaultValueRef() )
|
||||
#if SUPPORTS_WCHART
|
||||
|
||||
inline void ToNTMBS(std::string& nbs, const std::wstring& wcs)
|
||||
{
|
||||
nbs.resize(MB_CUR_MAX * wcs.size());
|
||||
|
||||
size_t nWrote = ::wcstombs(const_cast<char*>(nbs.c_str()), wcs.c_str(), nbs.size() + 1);
|
||||
|
||||
if (nWrote == (size_t)-1)
|
||||
{
|
||||
ASSERTMSG(false, "Conversion error in cMessages_!");
|
||||
// throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
}
|
||||
|
||||
nbs.resize(nWrote);
|
||||
}
|
||||
|
||||
inline void ToNTWCS(std::wstring& dst, const std::wstring& src)
|
||||
{
|
||||
dst.assign(src);
|
||||
}
|
||||
|
||||
inline void ToNTWCS(std::wstring& wcs, const std::string& nbs)
|
||||
{
|
||||
wcs.resize(nbs.size());
|
||||
|
||||
size_t nWrote = ::mbstowcs(const_cast<wchar_t*>(wcs.c_str()), nbs.c_str(), wcs.size() + 1);
|
||||
|
||||
if (nWrote == (size_t)-1)
|
||||
{
|
||||
ASSERTMSG(false, "Conversion error in cMessages_!");
|
||||
// throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
}
|
||||
|
||||
wcs.resize(nWrote);
|
||||
}
|
||||
#endif //SUPPORTS_WCHART
|
||||
} // namespace rsc
|
||||
} // namespace tss
|
||||
|
||||
|
||||
Message_Template inline std::string Message_Class::GetAnsi(ConstKeyRef id) const
|
||||
{
|
||||
typename Message_Class::Value msg = Resources::Get(id);
|
||||
|
||||
if (msg == this->DefaultValueRef())
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string nbs;
|
||||
tss::rsc::ToNTMBS( nbs, String( msg ) );
|
||||
tss::rsc::ToNTMBS(nbs, String(msg));
|
||||
return nbs;
|
||||
}
|
||||
}
|
||||
|
@ -381,33 +333,29 @@ Message_Class::GetAnsi( ConstKeyRef id ) const
|
|||
|
||||
#if SUPPORTS_WCHART
|
||||
|
||||
Message_Template
|
||||
inline
|
||||
std::wstring
|
||||
Message_Class::GetWide( ConstKeyRef id ) const
|
||||
Message_Template inline std::wstring Message_Class::GetWide(ConstKeyRef id) const
|
||||
{
|
||||
Value msg = Resources::Get( id );
|
||||
Value msg = Resources::Get(id);
|
||||
|
||||
if ( msg == DefaultValueRef() )
|
||||
if (msg == DefaultValueRef())
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstring wcs;
|
||||
tss::rsc::ToNTWCS( wcs, String( msg ) );
|
||||
tss::rsc::ToNTWCS(wcs, String(msg));
|
||||
return wcs;
|
||||
}
|
||||
}
|
||||
|
||||
#endif//SUPPORTS_WCHART
|
||||
#endif //SUPPORTS_WCHART
|
||||
|
||||
|
||||
#undef Message_Template
|
||||
#undef Message_Class
|
||||
|
||||
#endif//__RESOURCES_H
|
||||
|
||||
#endif //__RESOURCES_H
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -426,118 +374,100 @@ Message_Class::GetWide( ConstKeyRef id ) const
|
|||
|
||||
// for SUNPro enums are ints, not const ints
|
||||
#if IS_SUNPRO
|
||||
#define ENUM_TYPE int
|
||||
# define ENUM_TYPE int
|
||||
#else
|
||||
#define ENUM_TYPE const int
|
||||
# define ENUM_TYPE const int
|
||||
#endif
|
||||
|
||||
template<>
|
||||
class cMessages_<ENUM_TYPE, char> :
|
||||
public cResources_< ENUM_TYPE, const char* >
|
||||
template<> class cMessages_<ENUM_TYPE, char> : public cResources_<ENUM_TYPE, const char*>
|
||||
{
|
||||
protected:
|
||||
|
||||
typedef
|
||||
cResources_< ENUM_TYPE, const char* >
|
||||
Resources;
|
||||
|
||||
public:
|
||||
protected:
|
||||
typedef cResources_<ENUM_TYPE, const char*> Resources;
|
||||
|
||||
public:
|
||||
typedef std::string String;
|
||||
typedef int ConstKeyRef; // Better than <const int&>
|
||||
|
||||
|
||||
String Get( ConstKeyRef id ) const
|
||||
String Get(ConstKeyRef id) const
|
||||
{
|
||||
Value msg = Resources::Get( id );
|
||||
return ( msg != DefaultValueRef() )
|
||||
? String( msg )
|
||||
: String();
|
||||
Value msg = Resources::Get(id);
|
||||
return (msg != DefaultValueRef()) ? String(msg) : String();
|
||||
}
|
||||
|
||||
String GetAnsi( ConstKeyRef id ) const
|
||||
String GetAnsi(ConstKeyRef id) const
|
||||
{
|
||||
return Get( id );
|
||||
return Get(id);
|
||||
}
|
||||
|
||||
#if SUPPORTS_WCHART
|
||||
std::wstring GetWide( ConstKeyRef id ) const
|
||||
std::wstring GetWide(ConstKeyRef id) const
|
||||
{
|
||||
Value msg = Resources::Get( id );
|
||||
Value msg = Resources::Get(id);
|
||||
|
||||
if ( msg == DefaultValueRef() )
|
||||
if (msg == DefaultValueRef())
|
||||
{
|
||||
return std::wstring();
|
||||
}
|
||||
else
|
||||
{
|
||||
String::size_type
|
||||
N = String::traits_type::length( msg );
|
||||
String::size_type N = String::traits_type::length(msg);
|
||||
|
||||
std::wstring dst( N, 0x00 );
|
||||
std::ctype< wchar_t >().widen( msg, msg + N, dst.begin() );
|
||||
std::wstring dst(N, 0x00);
|
||||
std::ctype<wchar_t>().widen(msg, msg + N, dst.begin());
|
||||
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
#endif//SUPPORTS_WCHART
|
||||
#endif //SUPPORTS_WCHART
|
||||
};
|
||||
|
||||
#if SUPPORTS_WCHART
|
||||
|
||||
template<>
|
||||
class cMessages_<const int, wchar_t> :
|
||||
public cResources_< const int, const wchar_t* >
|
||||
template<> class cMessages_<const int, wchar_t> : public cResources_<const int, const wchar_t*>
|
||||
{
|
||||
protected:
|
||||
|
||||
typedef
|
||||
cResources_<const int, const wchar_t* >
|
||||
Resources;
|
||||
|
||||
public:
|
||||
protected:
|
||||
typedef cResources_<const int, const wchar_t*> Resources;
|
||||
|
||||
public:
|
||||
typedef std::wstring String;
|
||||
typedef int ConstKeyRef; // Better than <const int&>
|
||||
|
||||
|
||||
String Get( ConstKeyRef id ) const
|
||||
String Get(ConstKeyRef id) const
|
||||
{
|
||||
Value msg = Resources::Get( id );
|
||||
if( msg != DefaultValueRef() )
|
||||
return String( msg );
|
||||
Value msg = Resources::Get(id);
|
||||
if (msg != DefaultValueRef())
|
||||
return String(msg);
|
||||
else
|
||||
return String();
|
||||
}
|
||||
|
||||
std::string GetAnsi( ConstKeyRef id ) const
|
||||
std::string GetAnsi(ConstKeyRef id) const
|
||||
{
|
||||
Value msg = Resources::Get( id );
|
||||
Value msg = Resources::Get(id);
|
||||
|
||||
if ( msg == DefaultValueRef() )
|
||||
if (msg == DefaultValueRef())
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
else
|
||||
{
|
||||
String::size_type
|
||||
N = String::traits_type::length( msg );
|
||||
String::size_type N = String::traits_type::length(msg);
|
||||
|
||||
std::string dst( N, 0x00 );
|
||||
std::ctype<CharT>().narrow( msg, msg + N, '?', dst.begin() );
|
||||
std::string dst(N, 0x00);
|
||||
std::ctype<CharT>().narrow(msg, msg + N, '?', dst.begin());
|
||||
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
|
||||
String GetWide( ConstKeyRef id ) const
|
||||
String GetWide(ConstKeyRef id) const
|
||||
{
|
||||
return Get( id );
|
||||
return Get(id);
|
||||
}
|
||||
};
|
||||
|
||||
#endif//SUPPORTS_WCHART
|
||||
|
||||
#endif//RAD_OLDCODE
|
||||
|
||||
# endif //SUPPORTS_WCHART
|
||||
|
||||
#endif //RAD_OLDCODE
|
||||
|
|
|
@ -36,8 +36,13 @@
|
|||
#include "serializable.h"
|
||||
|
||||
#if IS_SUNPRO
|
||||
iTypedSerializable::~iTypedSerializable() {}
|
||||
iSerializable::~iSerializable() {}
|
||||
iTyped::~iTyped() {}
|
||||
iTypedSerializable::~iTypedSerializable()
|
||||
{
|
||||
}
|
||||
iSerializable::~iSerializable()
|
||||
{
|
||||
}
|
||||
iTyped::~iTyped()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -78,11 +78,13 @@ class iSerializer;
|
|||
class iSerializable
|
||||
{
|
||||
public:
|
||||
virtual void Read (iSerializer* pSerializer, int32 version = 0) = 0; // throw (eSerializer, eArchive)
|
||||
virtual void Read(iSerializer* pSerializer, int32 version = 0) = 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.
|
||||
|
||||
virtual ~iSerializable() {}
|
||||
virtual ~iSerializable()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class iTypedSerializable : public iTyped, public iSerializable
|
||||
|
@ -95,22 +97,33 @@ public:
|
|||
// Return the current version of that this serializable object writes.
|
||||
// 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 int16 MajorVersion(int32 version) { return (int16)((uint32)version >> 16); }
|
||||
static int16 MinorVersion(int32 version) { return (int16)version; }
|
||||
static int32 MkVersion(int16 major, int16 minor)
|
||||
{
|
||||
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()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////
|
||||
// convenience macros
|
||||
#define DECLARE_TYPEDSERIALIZABLE() \
|
||||
# define DECLARE_TYPEDSERIALIZABLE() \
|
||||
DECLARE_TYPED() \
|
||||
public: \
|
||||
public: \
|
||||
static iTypedSerializable* Create(); \
|
||||
virtual int32 Version() const;
|
||||
|
||||
#define IMPLEMENT_TYPEDSERIALIZABLE(CLASS, TYPEDSTRING, VERSION_MAJOR, VERSION_MINOR) \
|
||||
# define IMPLEMENT_TYPEDSERIALIZABLE(CLASS, TYPEDSTRING, VERSION_MAJOR, VERSION_MINOR) \
|
||||
IMPLEMENT_TYPED(CLASS, TYPEDSTRING) \
|
||||
iTypedSerializable* CLASS::Create() \
|
||||
{ \
|
||||
|
@ -122,4 +135,3 @@ public: \
|
|||
}
|
||||
|
||||
#endif // __SERIALIZABLE_H
|
||||
|
||||
|
|
|
@ -47,38 +47,38 @@
|
|||
{
|
||||
TSTRING ret;
|
||||
|
||||
if( !eSerializer::mDataSource.empty() )
|
||||
if (!eSerializer::mDataSource.empty())
|
||||
{
|
||||
ret = mMsg;
|
||||
|
||||
switch( eSerializer::mSourceType )
|
||||
switch (eSerializer::mSourceType)
|
||||
{
|
||||
case TY_UNDEFINED:
|
||||
ret.append( mDataSource );
|
||||
ret.append(mDataSource);
|
||||
break;
|
||||
case TY_FILE:
|
||||
ret.append( _T("\nFile: ") );
|
||||
ret.append( mDataSource );
|
||||
ret.append(_T("\nFile: "));
|
||||
ret.append(mDataSource);
|
||||
break;
|
||||
case TY_TEMPFILE:
|
||||
ret.append( _T("\nTemporary File: ") );
|
||||
ret.append( mDataSource );
|
||||
ret.append(_T("\nTemporary File: "));
|
||||
ret.append(mDataSource);
|
||||
break;
|
||||
case TY_MEMORY:
|
||||
ret.append( _T("\nMemory Block: ") ); //uhhh...??
|
||||
ret.append( mDataSource );
|
||||
ret.append(_T("\nMemory Block: ")); //uhhh...??
|
||||
ret.append(mDataSource);
|
||||
break;
|
||||
case TY_PIPE:
|
||||
ret.append( _T("\nNamed Pipe: "));
|
||||
ret.append( mDataSource );
|
||||
ret.append(_T("\nNamed Pipe: "));
|
||||
ret.append(mDataSource);
|
||||
break;
|
||||
case TY_SOCKET:
|
||||
ret.append( _T("\nNetwork Socket: "));
|
||||
ret.append( mDataSource );
|
||||
ret.append(_T("\nNetwork Socket: "));
|
||||
ret.append(mDataSource);
|
||||
break;
|
||||
default:
|
||||
ret.append( _T("\n"));
|
||||
ret.append( mDataSource );
|
||||
ret.append(_T("\n"));
|
||||
ret.append(mDataSource);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,52 +46,51 @@ class iSerializable;
|
|||
////////////////////////////////////////////////////////////
|
||||
// Serializer Base Exception
|
||||
////////////////////////////////////////////////////////////
|
||||
TSS_BEGIN_EXCEPTION_NO_CTOR( eSerializer, eError )
|
||||
// TODO: What else to add to this enumeration? Locked File? Temp file?
|
||||
enum DataSourceType {
|
||||
TSS_BEGIN_EXCEPTION_NO_CTOR(eSerializer, eError)
|
||||
// TODO: What else to add to this enumeration? Locked File? Temp file?
|
||||
enum DataSourceType
|
||||
{
|
||||
TY_UNDEFINED = 0,
|
||||
TY_FILE,
|
||||
TY_TEMPFILE,
|
||||
TY_MEMORY,
|
||||
TY_PIPE,
|
||||
TY_SOCKET
|
||||
};
|
||||
};
|
||||
|
||||
eSerializer( const TSTRING& msg, const TSTRING& dataSource = _T(""), DataSourceType paramType = TY_UNDEFINED )
|
||||
: eError( msg ),
|
||||
mDataSource( dataSource ),
|
||||
mSourceType( paramType )
|
||||
{}
|
||||
eSerializer(const TSTRING& msg, const TSTRING& dataSource = _T(""), DataSourceType paramType = TY_UNDEFINED)
|
||||
: eError(msg), mDataSource(dataSource), mSourceType(paramType)
|
||||
{
|
||||
}
|
||||
|
||||
virtual TSTRING GetMsg() const;
|
||||
virtual TSTRING GetMsg() const;
|
||||
|
||||
private:
|
||||
TSTRING mDataSource;
|
||||
// TSTRING indentifier of the datasource associated with a particular error
|
||||
// (if one exists) EX: a filename.
|
||||
DataSourceType mSourceType;
|
||||
TSTRING mDataSource;
|
||||
// TSTRING indentifier of the datasource associated with a particular error
|
||||
// (if one exists) EX: a filename.
|
||||
DataSourceType mSourceType;
|
||||
TSS_END_EXCEPTION();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Helper Macro For Serializer Exceptions
|
||||
////////////////////////////////////////////////////////////
|
||||
#define TSS_SERIALIZER_EXCEPTION( except ) \
|
||||
TSS_BEGIN_EXCEPTION_NO_CTOR( except, eSerializer ) \
|
||||
except( const TSTRING& msg, const TSTRING& dataSource = _T(""), DataSourceType paramType = TY_UNDEFINED ) \
|
||||
: eSerializer( msg, dataSource, paramType ) \
|
||||
{}; \
|
||||
#define TSS_SERIALIZER_EXCEPTION(except) \
|
||||
TSS_BEGIN_EXCEPTION_NO_CTOR(except, eSerializer) \
|
||||
except(const TSTRING& msg, const TSTRING& dataSource = _T(""), DataSourceType paramType = TY_UNDEFINED) \
|
||||
: eSerializer(msg, dataSource, paramType){}; \
|
||||
TSS_END_EXCEPTION()
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Specific Exceptions
|
||||
////////////////////////////////////////////////////////////
|
||||
TSS_SERIALIZER_EXCEPTION( eSerializerUnknownType );
|
||||
TSS_SERIALIZER_EXCEPTION( eSerializerInputStreamFmt);
|
||||
TSS_SERIALIZER_EXCEPTION( eSerializerOutputStreamFmt );
|
||||
TSS_SERIALIZER_EXCEPTION( eSerializerInputStremTypeArray );
|
||||
TSS_SERIALIZER_EXCEPTION( eSerializerArchive ); // not used
|
||||
TSS_SERIALIZER_EXCEPTION( eSerializerVersionMismatch );
|
||||
TSS_SERIALIZER_EXCEPTION( eSerializerEncryption );
|
||||
TSS_SERIALIZER_EXCEPTION(eSerializerUnknownType);
|
||||
TSS_SERIALIZER_EXCEPTION(eSerializerInputStreamFmt);
|
||||
TSS_SERIALIZER_EXCEPTION(eSerializerOutputStreamFmt);
|
||||
TSS_SERIALIZER_EXCEPTION(eSerializerInputStremTypeArray);
|
||||
TSS_SERIALIZER_EXCEPTION(eSerializerArchive); // not used
|
||||
TSS_SERIALIZER_EXCEPTION(eSerializerVersionMismatch);
|
||||
TSS_SERIALIZER_EXCEPTION(eSerializerEncryption);
|
||||
|
||||
/*
|
||||
E_UNKNOWN_TYPE = 700,
|
||||
|
@ -139,7 +138,10 @@ public:
|
|||
virtual void WriteString(const TSTRING& s) = 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.
|
||||
// it is only used in error reporting.
|
||||
|
||||
|
@ -156,10 +158,10 @@ public:
|
|||
E_NUMITEMS
|
||||
};
|
||||
|
||||
virtual ~iSerializer() {}
|
||||
virtual ~iSerializer()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -38,13 +38,13 @@
|
|||
#include "crc32.h"
|
||||
|
||||
// static members
|
||||
cSerializerImpl::SerMap cSerializerImpl::mSerCreateMap ;
|
||||
cSerializerImpl::SerRefCountMap cSerializerImpl::mSerRefCountCreateMap ;
|
||||
cSerializerImpl::SerMap cSerializerImpl::mSerCreateMap;
|
||||
cSerializerImpl::SerRefCountMap cSerializerImpl::mSerRefCountCreateMap;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// util_GetCrc -- calculates the crc for the narrow version of the type's AsString()
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
static uint32 util_GetCRC( const cType& type )
|
||||
static uint32 util_GetCRC(const cType& type)
|
||||
{
|
||||
//
|
||||
// convert this to narrow...
|
||||
|
@ -59,19 +59,19 @@ static uint32 util_GetCRC( const cType& type )
|
|||
|
||||
// We only need to count the characters
|
||||
// RAD: Yeesh! This is already done for us in cType::mString!!!
|
||||
const uint8* pszType = (const uint8*)( type.AsString() );
|
||||
int nBytes = ::strlen( (const char*)pszType );
|
||||
const uint8* pszType = (const uint8*)(type.AsString());
|
||||
int nBytes = ::strlen((const char*)pszType);
|
||||
|
||||
ASSERT( sizeof(uint8) == sizeof(byte) );
|
||||
ASSERT( pszType && *pszType );
|
||||
ASSERT(sizeof(uint8) == sizeof(byte));
|
||||
ASSERT(pszType && *pszType);
|
||||
|
||||
//
|
||||
// calculate the crc...
|
||||
//
|
||||
CRC_INFO crc;
|
||||
crcInit( crc );
|
||||
crcUpdate( crc, pszType, nBytes );
|
||||
crcFinit( crc );
|
||||
crcInit(crc);
|
||||
crcUpdate(crc, pszType, nBytes);
|
||||
crcFinit(crc);
|
||||
|
||||
return crc.crc;
|
||||
}
|
||||
|
@ -79,11 +79,8 @@ static uint32 util_GetCRC( const cType& type )
|
|||
//#############################################################################
|
||||
// class cSerializerImpl
|
||||
//#############################################################################
|
||||
cSerializerImpl::cSerializerImpl(cArchive& archive, Mode action, const TSTRING& fileName) :
|
||||
mpArchive(&archive),
|
||||
mMode(action),
|
||||
mbInit(false),
|
||||
mFileName( fileName )
|
||||
cSerializerImpl::cSerializerImpl(cArchive& archive, Mode action, const TSTRING& fileName)
|
||||
: mpArchive(&archive), mMode(action), mbInit(false), mFileName(fileName)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -107,13 +104,13 @@ bool cSerializerImpl::IsWriting() const
|
|||
|
||||
void cSerializerImpl::RegisterSerializable(const cType& type, iTypedSerializable::CreateFunc pFunc)
|
||||
{
|
||||
uint32 crc = util_GetCRC( type );
|
||||
uint32 crc = util_GetCRC(type);
|
||||
|
||||
if( cSerializerImpl::mSerCreateMap.find( crc ) != cSerializerImpl::mSerCreateMap.end() )
|
||||
if (cSerializerImpl::mSerCreateMap.find(crc) != cSerializerImpl::mSerCreateMap.end())
|
||||
{
|
||||
// duplicate entry!
|
||||
//
|
||||
ASSERT( false );
|
||||
ASSERT(false);
|
||||
TOSTRINGSTREAM str;
|
||||
str << _T("Duplicate entry in type table: ") << type.AsString() << std::endl;
|
||||
throw eInternal(str.str());
|
||||
|
@ -123,13 +120,13 @@ void cSerializerImpl::RegisterSerializable(const cType& type, iTypedSerializable
|
|||
|
||||
void cSerializerImpl::RegisterSerializableRefCt(const cType& type, iSerRefCountObj::CreateFunc pFunc)
|
||||
{
|
||||
uint32 crc = util_GetCRC( type );
|
||||
uint32 crc = util_GetCRC(type);
|
||||
|
||||
if( cSerializerImpl::mSerRefCountCreateMap.find( crc ) != cSerializerImpl::mSerRefCountCreateMap.end() )
|
||||
if (cSerializerImpl::mSerRefCountCreateMap.find(crc) != cSerializerImpl::mSerRefCountCreateMap.end())
|
||||
{
|
||||
// duplicate entry!
|
||||
//
|
||||
ASSERT( false );
|
||||
ASSERT(false);
|
||||
TOSTRINGSTREAM str;
|
||||
str << _T("Duplicate entry in type table: ") << type.AsString() << std::ends;
|
||||
throw eInternal(str.str());
|
||||
|
@ -184,23 +181,23 @@ void cSerializerImpl::WriteObjectDynCreate(const iTypedSerializable* pObj)
|
|||
|
||||
// get the ident for this class type
|
||||
//
|
||||
uint32 crc = util_GetCRC( pObj->GetType() );
|
||||
uint32 crc = util_GetCRC(pObj->GetType());
|
||||
|
||||
//
|
||||
// make sure this type is registered, and figure out if it is refrence counted
|
||||
//
|
||||
SerRefCountMap::iterator i = mSerRefCountCreateMap.find( crc );
|
||||
SerRefCountMap::iterator i = mSerRefCountCreateMap.find(crc);
|
||||
bool bRefCount = true;
|
||||
if( i == mSerRefCountCreateMap.end() )
|
||||
if (i == mSerRefCountCreateMap.end())
|
||||
{
|
||||
//
|
||||
// maybe it is not refrence counted...
|
||||
//
|
||||
SerMap::iterator si = mSerCreateMap.find( crc );
|
||||
if( si == mSerCreateMap.end() )
|
||||
SerMap::iterator si = mSerCreateMap.find(crc);
|
||||
if (si == mSerCreateMap.end())
|
||||
{
|
||||
d.TraceError("Attempt to serialize unregistered type : %s\n", pObj->GetType().AsString());
|
||||
ThrowAndAssert(eSerializerUnknownType( pObj->GetType().AsString(), mFileName, eSerializer::TY_FILE ));
|
||||
ThrowAndAssert(eSerializerUnknownType(pObj->GetType().AsString(), mFileName, eSerializer::TY_FILE));
|
||||
}
|
||||
bRefCount = false;
|
||||
}
|
||||
|
@ -210,11 +207,11 @@ void cSerializerImpl::WriteObjectDynCreate(const iTypedSerializable* pObj)
|
|||
// write a placeholder for the size; we will come back and fill in the right value later...
|
||||
mpArchive->WriteInt32(0xffffffff);
|
||||
|
||||
if(bRefCount)
|
||||
if (bRefCount)
|
||||
{
|
||||
// see if the object has already been serialized...
|
||||
int idx;
|
||||
if((idx = mRefCtObjTbl.Lookup(static_cast<const iSerRefCountObj*>(pObj))) == 0)
|
||||
if ((idx = mRefCtObjTbl.Lookup(static_cast<const iSerRefCountObj*>(pObj))) == 0)
|
||||
{
|
||||
// it is not in the table yet; add it and serialize the object
|
||||
idx = mRefCtObjTbl.Add(static_cast<const iSerRefCountObj*>(pObj));
|
||||
|
@ -235,7 +232,6 @@ void cSerializerImpl::WriteObjectDynCreate(const iTypedSerializable* pObj)
|
|||
mpArchive->WriteInt32(0);
|
||||
// ... then write the object.
|
||||
pObj->Write(this);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,21 +259,21 @@ iTypedSerializable* cSerializerImpl::ReadObjectDynCreate()
|
|||
//int64 sizePos = mpArchive->CurrentPos();
|
||||
|
||||
mpArchive->ReadInt32(objIdx);
|
||||
if(objIdx == 0)
|
||||
if (objIdx == 0)
|
||||
{
|
||||
// the object is not reference counted; create and read in the object
|
||||
// first, we need to create the object.
|
||||
SerMap::iterator si;
|
||||
si = mSerCreateMap.find(crc);
|
||||
if(si == mSerCreateMap.end())
|
||||
if (si == mSerCreateMap.end())
|
||||
{
|
||||
// unable to find the creation function...
|
||||
d.TraceError("Unable to find creation function for non-ref counted object %d\n", crc);
|
||||
TOSTRINGSTREAM str;
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG
|
||||
// Let's only report the actual crc in debug mode
|
||||
str << (int32)crc << std::ends;
|
||||
#endif
|
||||
#endif
|
||||
ThrowAndAssert(eSerializerUnknownType(str.str(), mFileName, eSerializer::TY_FILE));
|
||||
}
|
||||
iTypedSerializable* pObj = ((*si).second)();
|
||||
|
@ -294,12 +290,12 @@ iTypedSerializable* cSerializerImpl::ReadObjectDynCreate()
|
|||
// refrence counted...
|
||||
iSerRefCountObj* pObj;
|
||||
pObj = mRefCtObjTbl.Lookup(objIdx);
|
||||
if(pObj == NULL)
|
||||
if (pObj == NULL)
|
||||
{
|
||||
// not in table yet...first find the creation function
|
||||
SerRefCountMap::iterator rci;
|
||||
rci = mSerRefCountCreateMap.find(crc);
|
||||
if(rci == mSerRefCountCreateMap.end())
|
||||
if (rci == mSerRefCountCreateMap.end())
|
||||
{
|
||||
// unable to find the creation function...
|
||||
d.TraceError("Unable to find creation function for ref counted object %d\n", crc);
|
||||
|
@ -320,7 +316,10 @@ iTypedSerializable* cSerializerImpl::ReadObjectDynCreate()
|
|||
else
|
||||
{
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
@ -354,7 +353,7 @@ void cSerializerImpl::WriteObject(const iTypedSerializable* pObj)
|
|||
// the object is already created when ReadObject() happens. The only good it might serve is in asserting that
|
||||
// the input stream is valid, but I can do that with the 0xffffffff size below (asserting that it is the same
|
||||
// when it is read back in)
|
||||
/* int i = 0;
|
||||
/* int i = 0;
|
||||
for(; i < mTypeArray.size(); i++)
|
||||
{
|
||||
if(pObj->GetType() == *mTypeArray[i])
|
||||
|
@ -417,7 +416,7 @@ void cSerializerImpl::ReadObject(iTypedSerializable* pObj)
|
|||
mpArchive->ReadInt32(size);
|
||||
|
||||
// use the size to assert that the file format is correct
|
||||
if(size != (int)0xffffffff)
|
||||
if (size != (int)0xffffffff)
|
||||
{
|
||||
// unknown type index!
|
||||
d.TraceError("Encountered bad size: %d\n", size);
|
||||
|
@ -495,4 +494,3 @@ TSTRING cSerializerImpl::GetFileName() const
|
|||
{
|
||||
return mFileName;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,8 +60,12 @@ class cArchive;
|
|||
class cSerializerImpl : public iSerializer
|
||||
{
|
||||
public:
|
||||
enum Mode { S_READ, S_WRITE };
|
||||
cSerializerImpl (cArchive& archive, Mode action, const TSTRING& fileName = _T("") );
|
||||
enum Mode
|
||||
{
|
||||
S_READ,
|
||||
S_WRITE
|
||||
};
|
||||
cSerializerImpl(cArchive& archive, Mode action, const TSTRING& fileName = _T(""));
|
||||
// fileName is only used for error reporting purposes
|
||||
virtual ~cSerializerImpl();
|
||||
|
||||
|
@ -88,10 +92,10 @@ public:
|
|||
|
||||
// members for registering classes to be serialized. One of these must be called exactly once
|
||||
// for each class that is to be serialized.
|
||||
static void RegisterSerializable (const cType& type, iTypedSerializable::CreateFunc pFunc);
|
||||
static void RegisterSerializableRefCt (const cType& type, iSerRefCountObj::CreateFunc pFunc);
|
||||
static void RegisterSerializable(const cType& type, iTypedSerializable::CreateFunc pFunc);
|
||||
static void RegisterSerializableRefCt(const cType& type, iSerRefCountObj::CreateFunc pFunc);
|
||||
|
||||
// writing interface
|
||||
// writing interface
|
||||
// TODO -- I am not sure if I want to keep these or just have the serializer expose the archive. Actually,
|
||||
// I think the best thing might be to have iSerializable only know about the archive
|
||||
// Standard data read/write
|
||||
|
@ -128,7 +132,4 @@ private:
|
|||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -35,39 +35,41 @@
|
|||
#include "archive.h"
|
||||
#include "serializer.h"
|
||||
|
||||
namespace {
|
||||
template<class FROM, class TO>
|
||||
int64 CopyImpl(TO* pTo, FROM* pFrom, int64 amt)
|
||||
namespace
|
||||
{
|
||||
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];
|
||||
int64 amtLeft = amt;
|
||||
|
||||
while(amtLeft > 0)
|
||||
while (amtLeft > 0)
|
||||
{
|
||||
// NOTE: We use int's here rather than int64 because iSerializer and cArchive
|
||||
// only take int's as their size parameter - dmb
|
||||
int amtToRead = amtLeft > BUF_SIZE ? BUF_SIZE : (int)amtLeft;
|
||||
int amtRead = pFrom->ReadBlob(buf, amtToRead );
|
||||
int amtRead = pFrom->ReadBlob(buf, amtToRead);
|
||||
amtLeft -= amtRead;
|
||||
pTo->WriteBlob(buf, amtRead);
|
||||
if(amtRead < amtToRead)
|
||||
if (amtRead < amtToRead)
|
||||
break;
|
||||
}
|
||||
|
||||
// return the amount copied ...
|
||||
return (amt - amtLeft);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
int64 cSerializerUtil::Copy( iSerializer* pDest, cArchive* pSrc, int64 amt )
|
||||
int64 cSerializerUtil::Copy(iSerializer* pDest, cArchive* pSrc, int64 amt)
|
||||
{
|
||||
return CopyImpl( pDest, pSrc, amt );
|
||||
return CopyImpl(pDest, pSrc, amt);
|
||||
}
|
||||
|
||||
int64 cSerializerUtil::Copy( cArchive* pDest, iSerializer* pSrc, int64 amt )
|
||||
int64 cSerializerUtil::Copy(cArchive* pDest, iSerializer* pSrc, int64 amt)
|
||||
{
|
||||
return CopyImpl( pDest, pSrc, amt );
|
||||
return CopyImpl(pDest, pSrc, amt);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,11 +44,10 @@ class iSerializer;
|
|||
class cSerializerUtil
|
||||
{
|
||||
public:
|
||||
static int64 Copy( iSerializer* pDest, cArchive* pSrc, int64 amt ); // throw( eArchvie, eSerilaizer )
|
||||
static int64 Copy( cArchive* pDest, iSerializer* pSrc, int64 amt ); // throw( eArchvie, eSerilaizer )
|
||||
static int64 Copy(iSerializer* pDest, cArchive* pSrc, int64 amt); // throw( eArchvie, eSerilaizer )
|
||||
static int64 Copy(cArchive* pDest, iSerializer* pSrc, int64 amt); // throw( eArchvie, eSerilaizer )
|
||||
// these two methods copy data from archives to serializers and vice-versa. They
|
||||
// throw exceptions on error; the return value is the amount that was copied.
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
IMPLEMENT_TYPEDSERIALIZABLE(cSerializableNString, _T("cSerializableNString"), 0, 1)
|
||||
|
||||
void cSerializableNString::Read (iSerializer* pSerializer, int32 version)
|
||||
void cSerializableNString::Read(iSerializer* pSerializer, int32 version)
|
||||
{
|
||||
int32 len;
|
||||
pSerializer->ReadInt32(len);
|
||||
|
@ -55,7 +55,7 @@ void cSerializableNString::Write(iSerializer* pSerializer) const
|
|||
|
||||
IMPLEMENT_TYPEDSERIALIZABLE(cSerializableWString, _T("cSerializableWString"), 0, 1)
|
||||
|
||||
void cSerializableWString::Read (iSerializer* pSerializer, int32 version)
|
||||
void cSerializableWString::Read(iSerializer* pSerializer, int32 version)
|
||||
{
|
||||
int32 len;
|
||||
pSerializer->ReadInt32(len);
|
||||
|
@ -69,4 +69,3 @@ void cSerializableWString::Write(iSerializer* pSerializer) const
|
|||
pSerializer->WriteInt32(len);
|
||||
pSerializer->WriteBlob(mString.data(), len);
|
||||
}
|
||||
|
||||
|
|
|
@ -56,8 +56,8 @@ class cSerializableNString : public iTypedSerializable
|
|||
public:
|
||||
std::string mString;
|
||||
|
||||
virtual ~cSerializableNString() {};
|
||||
virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual ~cSerializableNString(){};
|
||||
virtual void Read(iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
||||
|
||||
DECLARE_TYPEDSERIALIZABLE()
|
||||
|
@ -71,8 +71,8 @@ class cSerializableWString : public iTypedSerializable
|
|||
public:
|
||||
std::string mString;
|
||||
|
||||
virtual ~cSerializableWString() {};
|
||||
virtual void Read (iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual ~cSerializableWString(){};
|
||||
virtual void Read(iSerializer* pSerializer, int32 version = 0); // throw (eSerializer, eArchive)
|
||||
virtual void Write(iSerializer* pSerializer) const; // throw (eSerializer, eArchive)
|
||||
|
||||
DECLARE_TYPEDSERIALIZABLE()
|
||||
|
@ -81,4 +81,3 @@ public:
|
|||
typedef cSerializableNString cSerializableTSTRING;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -42,4 +42,3 @@
|
|||
iSerRefCountObj::~iSerRefCountObj()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -59,18 +59,17 @@ public:
|
|||
|
||||
protected:
|
||||
virtual ~iSerRefCountObj();
|
||||
|
||||
};
|
||||
|
||||
//////////////////////////////
|
||||
// convenience macros
|
||||
#define DECLARE_SERREFCOUNT() \
|
||||
# define DECLARE_SERREFCOUNT() \
|
||||
DECLARE_TYPED() \
|
||||
public: \
|
||||
public: \
|
||||
static iSerRefCountObj* Create(); \
|
||||
virtual int32 Version() const;
|
||||
|
||||
#define IMPLEMENT_SERREFCOUNT(CLASS, TYPEDSTRING, VERSION_MAJOR, VERSION_MINOR) \
|
||||
# define IMPLEMENT_SERREFCOUNT(CLASS, TYPEDSTRING, VERSION_MAJOR, VERSION_MINOR) \
|
||||
IMPLEMENT_TYPED(CLASS, TYPEDSTRING) \
|
||||
iSerRefCountObj* CLASS::Create() \
|
||||
{ \
|
||||
|
@ -83,4 +82,3 @@ public: \
|
|||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -100,8 +100,8 @@ int cSerRefCountTable::Add(iSerRefCountObj* pObj, int id)
|
|||
ThrowAndAssert(eInternal(_T("cSerRefCountTable::Add() passed ID already in table.")));
|
||||
}
|
||||
|
||||
mIDToObjTbl.insert( MapIDTObj::value_type(id, pObj));
|
||||
mObjToIdTbl.insert( MapObjIDT::value_type(pObj, id));
|
||||
mIDToObjTbl.insert(MapIDTObj::value_type(id, pObj));
|
||||
mObjToIdTbl.insert(MapObjIDT::value_type(pObj, id));
|
||||
|
||||
return id;
|
||||
}
|
||||
|
@ -154,4 +154,3 @@ cSerRefCountTableMap::~cSerRefCountTableMap()
|
|||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
// Add an object to the table, optionally specifying an ID. Returns a
|
||||
// unique ID for the object. ASSERTs and throws exception if object is
|
||||
// already in table or the ID is already taken.
|
||||
int Add( iSerRefCountObj* pObj, int id = 0);
|
||||
int Add(iSerRefCountObj* pObj, int id = 0);
|
||||
int Add(const iSerRefCountObj* pObj, int id = 0);
|
||||
// TODO -- Note that this class is not really const-correct in that the const version of
|
||||
// Add() just casts away the constness. The right thing to do is to make the serializer
|
||||
|
@ -89,4 +89,3 @@ public:
|
|||
};
|
||||
*/
|
||||
#endif
|
||||
|
||||
|
|
|
@ -36,5 +36,3 @@
|
|||
//
|
||||
|
||||
#include "stdcore.h"
|
||||
|
||||
|
||||
|
|
|
@ -49,42 +49,42 @@
|
|||
|
||||
#if IS_MSVC
|
||||
|
||||
#define NOMINMAX //--Disable min/max macros
|
||||
# define NOMINMAX //--Disable min/max macros
|
||||
|
||||
#include <xstddef> // ARGH!! This resumes certain warnings!
|
||||
#include <xstddef> // ARGH!! This resumes certain warnings!
|
||||
|
||||
#pragma warning( disable: 4786 ) // Token Name > 255
|
||||
#pragma warning( disable: 4127 ) // constant expression (e.g. ASSERT)
|
||||
#pragma warning( disable: 4291 ) // Incorrectly called when new(nothrow)!!!
|
||||
#pragma warning( disable: 4097 ) // Type synonyms are good!
|
||||
#pragma warning( disable: 4511 ) // Can't create copy ctor! (e.g.Private CTOR)
|
||||
#pragma warning( disable: 4512 ) // Can't create assignment!(e.g.Private CTOR)
|
||||
#pragma warning( disable: 4100 ) // Formal argument not used
|
||||
#pragma warning( disable: 4710 ) // Compiler did not inline function
|
||||
# pragma warning(disable : 4786) // Token Name > 255
|
||||
# pragma warning(disable : 4127) // constant expression (e.g. ASSERT)
|
||||
# pragma warning(disable : 4291) // Incorrectly called when new(nothrow)!!!
|
||||
# pragma warning(disable : 4097) // Type synonyms are good!
|
||||
# pragma warning(disable : 4511) // Can't create copy ctor! (e.g.Private CTOR)
|
||||
# pragma warning(disable : 4512) // Can't create assignment!(e.g.Private CTOR)
|
||||
# pragma warning(disable : 4100) // Formal argument not used
|
||||
# pragma warning(disable : 4710) // Compiler did not inline function
|
||||
|
||||
#ifndef DEBUG // ASSERT's are disabled give a lot of these
|
||||
#pragma warning( disable: 4702 ) // ---Unreachable Code
|
||||
#endif
|
||||
# ifndef DEBUG // ASSERT's are disabled give a lot of these
|
||||
# pragma warning(disable : 4702) // ---Unreachable Code
|
||||
# endif
|
||||
|
||||
/* NOTE:RAD:05/09/1999 -- Plaguers STDCPP implementation is SOOO bad
|
||||
/* NOTE:RAD:05/09/1999 -- Plaguers STDCPP implementation is SOOO bad
|
||||
it creates all these errors when compiling at W4. By doing a push
|
||||
before disabling them, we can still generate them for ourselves
|
||||
without a lot of noise. The warnings before this push, we want to
|
||||
always disable. */
|
||||
|
||||
#pragma warning( push )
|
||||
# pragma warning(push)
|
||||
|
||||
#pragma warning( disable: 4663 ) // Old template specialization syntax
|
||||
#pragma warning( disable: 4018 ) // Signed unsigned mismatch
|
||||
#pragma warning( disable: 4245 ) // Signed unsigned mismatch
|
||||
#pragma warning( disable: 4663 ) // Use new template specialization syntax: template<>
|
||||
#pragma warning( disable: 4701 ) // local variable 'X' may be used without having been initialized
|
||||
#pragma warning( disable: 4510 ) // 'X' : default constructor could not be generated
|
||||
#pragma warning( disable: 4610 ) // struct 'X' can never be instantiated - user defined constructor required
|
||||
#pragma warning( disable: 4146 ) // unary minus operator applied to unsigned type, result still unsigned
|
||||
#pragma warning( disable: 4244 ) // '=' : conversion from 'unsigned int' to 'char', possible loss of data
|
||||
#pragma warning( disable: 4511 )
|
||||
#pragma warning( disable: 4503 )
|
||||
# pragma warning(disable : 4663) // Old template specialization syntax
|
||||
# pragma warning(disable : 4018) // Signed unsigned mismatch
|
||||
# pragma warning(disable : 4245) // Signed unsigned mismatch
|
||||
# pragma warning(disable : 4663) // Use new template specialization syntax: template<>
|
||||
# pragma warning(disable : 4701) // local variable 'X' may be used without having been initialized
|
||||
# pragma warning(disable : 4510) // 'X' : default constructor could not be generated
|
||||
# pragma warning(disable : 4610) // struct 'X' can never be instantiated - user defined constructor required
|
||||
# pragma warning(disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
|
||||
# pragma warning(disable : 4244) // '=' : conversion from 'unsigned int' to 'char', possible loss of data
|
||||
# pragma warning(disable : 4511)
|
||||
# pragma warning(disable : 4503)
|
||||
|
||||
#endif // #if IS_MSVC
|
||||
|
||||
|
@ -108,13 +108,12 @@
|
|||
#include <limits>
|
||||
|
||||
#if IS_MSVC
|
||||
#pragma warning( pop ) // Resume W4 msgs for TSS code
|
||||
# pragma warning(pop) // Resume W4 msgs for TSS code
|
||||
#endif
|
||||
|
||||
//--Include Platform Specific Declarations
|
||||
|
||||
|
||||
|
||||
//--Include Common Core Declarations
|
||||
|
||||
#include "./tchar.h"
|
||||
|
@ -123,5 +122,4 @@
|
|||
#include "./debug.h"
|
||||
|
||||
|
||||
#endif//__STDCORE_H
|
||||
|
||||
#endif //__STDCORE_H
|
||||
|
|
|
@ -75,7 +75,6 @@
|
|||
#include "hashtable.h"
|
||||
|
||||
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// String Cache
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -85,7 +84,7 @@
|
|||
class tss_hash_key_convert
|
||||
{
|
||||
public:
|
||||
const byte* operator()( const wc16_string& s, int* const pcbKeyLen )
|
||||
const byte* operator()(const wc16_string& s, int* const pcbKeyLen)
|
||||
{
|
||||
*pcbKeyLen = sizeof(WCHAR16) * s.length();
|
||||
return (byte*)s.c_str();
|
||||
|
@ -95,37 +94,32 @@ public:
|
|||
class tss_hash_key_compare
|
||||
{
|
||||
public:
|
||||
bool operator()( const wc16_string& lhs, const wc16_string& rhs )
|
||||
bool operator()(const wc16_string& lhs, const wc16_string& rhs)
|
||||
{
|
||||
return ( lhs.compare( rhs ) == 0 );
|
||||
return (lhs.compare(rhs) == 0);
|
||||
}
|
||||
};
|
||||
|
||||
namespace /* Module Local */
|
||||
{
|
||||
typedef
|
||||
cHashTable< wc16_string,
|
||||
TSTRING,
|
||||
tss_hash_key_compare,
|
||||
tss_hash_key_convert >
|
||||
hashtable_t;
|
||||
typedef 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;
|
||||
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)
|
||||
{
|
||||
tss_GetHashTable().Insert( lhs, rhs );
|
||||
tss_GetHashTable().Insert(lhs, rhs);
|
||||
}
|
||||
|
||||
inline bool tss_find_in_hash( const wc16_string& lhs, TSTRING& rhs )
|
||||
inline bool tss_find_in_hash(const wc16_string& lhs, TSTRING& rhs)
|
||||
{
|
||||
return( tss_GetHashTable().Lookup( lhs, rhs ) );
|
||||
return (tss_GetHashTable().Lookup(lhs, rhs));
|
||||
}
|
||||
|
||||
|
||||
|
@ -134,30 +128,29 @@ inline bool tss_find_in_hash( const wc16_string& lhs, TSTRING& rhs )
|
|||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
/*static*/
|
||||
std::string::const_iterator
|
||||
cStringUtil::Convert( std::string& nbs, const wc16_string& dbs )
|
||||
std::string::const_iterator cStringUtil::Convert(std::string& nbs, const wc16_string& dbs)
|
||||
{
|
||||
#if IS_AROS
|
||||
nbs.resize(dbs.length());
|
||||
for (int x=0; x<dbs.length(); ++x)
|
||||
for (int x = 0; x < dbs.length(); ++x)
|
||||
nbs[x] = (unsigned char)dbs[x];
|
||||
#else
|
||||
cDebug d("cStringUtil::Convert( char, w16 )");
|
||||
|
||||
ASSERT( (void*)nbs.c_str() != (void*)dbs.c_str() );
|
||||
ASSERT((void*)nbs.c_str() != (void*)dbs.c_str());
|
||||
|
||||
if ( dbs.empty() )
|
||||
if (dbs.empty())
|
||||
nbs.erase();
|
||||
else
|
||||
{
|
||||
if( tss_find_in_hash( dbs, nbs ) )
|
||||
if (tss_find_in_hash(dbs, nbs))
|
||||
{
|
||||
d.TraceNever( _T("found string in hash table\n") );
|
||||
d.TraceNever(_T("found string in hash table\n"));
|
||||
return nbs.begin();
|
||||
}
|
||||
else
|
||||
{
|
||||
d.TraceNever( _T("didn't find string in hash table\n") );
|
||||
d.TraceNever(_T("didn't find string in hash table\n"));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -167,21 +160,19 @@ cStringUtil::Convert( std::string& nbs, const wc16_string& dbs )
|
|||
d.TraceDebug( _T("----\n") );
|
||||
*/
|
||||
|
||||
nbs.resize( dbs.size() * MB_CUR_MAX );
|
||||
nbs.resize(dbs.size() * MB_CUR_MAX);
|
||||
|
||||
int nWrote =
|
||||
iCodeConverter::GetInstance()->Convert(
|
||||
(char*)nbs.c_str(), nbs.size(),
|
||||
dbs.c_str(), dbs.size() ); // c_str() because must be null terminated
|
||||
int nWrote = iCodeConverter::GetInstance()->Convert(
|
||||
(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);
|
||||
|
||||
if ( nWrote == -1 )
|
||||
throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
if (nWrote == -1)
|
||||
throw eCharacterEncoding(TSS_GetString(cCore, core::STR_ERR_BADCHAR));
|
||||
|
||||
nbs.resize( nWrote );
|
||||
nbs.resize(nWrote);
|
||||
|
||||
tss_insert_in_hash( dbs, nbs );
|
||||
tss_insert_in_hash(dbs, nbs);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -189,12 +180,11 @@ cStringUtil::Convert( std::string& nbs, const wc16_string& dbs )
|
|||
}
|
||||
|
||||
/*static*/
|
||||
wc16_string::const_iterator
|
||||
cStringUtil::Convert( wc16_string& dbs, const std::string& nbs )
|
||||
wc16_string::const_iterator cStringUtil::Convert(wc16_string& dbs, const std::string& nbs)
|
||||
{
|
||||
#if IS_AROS
|
||||
dbs.resize(nbs.length());
|
||||
for (int x=0; x<nbs.length(); x++)
|
||||
for (int x = 0; x < nbs.length(); x++)
|
||||
dbs[x] = (unsigned short)nbs[x];
|
||||
#else
|
||||
|
||||
|
@ -202,23 +192,21 @@ cStringUtil::Convert( wc16_string& dbs, const std::string& nbs )
|
|||
|
||||
if (nbs.size() != 0)
|
||||
{
|
||||
dbs.resize( nbs.size() );
|
||||
dbs.resize(nbs.size());
|
||||
|
||||
// d.TraceDebug( "converting <%s>\n", nbs.c_str() );
|
||||
|
||||
int nWrote =
|
||||
iCodeConverter::GetInstance()->Convert(
|
||||
(WCHAR16*)dbs.c_str(), dbs.length(),
|
||||
nbs.c_str(), nbs.size() ); // c_str() because must be null terminated
|
||||
int nWrote = iCodeConverter::GetInstance()->Convert(
|
||||
(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);
|
||||
|
||||
if ( nWrote == -1 )
|
||||
if (nWrote == -1)
|
||||
{
|
||||
throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
throw eCharacterEncoding(TSS_GetString(cCore, core::STR_ERR_BADCHAR));
|
||||
}
|
||||
|
||||
dbs.resize( nWrote );
|
||||
dbs.resize(nWrote);
|
||||
|
||||
/*
|
||||
d.TraceDebug( _T("converted to: \n") );
|
||||
|
@ -237,18 +225,17 @@ cStringUtil::Convert( wc16_string& dbs, const std::string& nbs )
|
|||
#if SUPPORTS_WCHART && WCHAR_REP_IS_UCS2
|
||||
|
||||
/*static*/
|
||||
std::wstring::const_iterator
|
||||
cStringUtil::Convert( std::wstring& wcs, const wc16_string& dbs )
|
||||
std::wstring::const_iterator cStringUtil::Convert(std::wstring& wcs, const wc16_string& dbs)
|
||||
{
|
||||
if (dbs.size() != 0)
|
||||
{
|
||||
if( tss_find_in_hash( dbs, wcs ) )
|
||||
if (tss_find_in_hash(dbs, wcs))
|
||||
return wcs.begin();
|
||||
|
||||
wcs.resize( dbs.size() );
|
||||
std::copy( dbs.begin(), dbs.end(), wcs.begin() );
|
||||
wcs.resize(dbs.size());
|
||||
std::copy(dbs.begin(), dbs.end(), wcs.begin());
|
||||
|
||||
tss_insert_in_hash( dbs, wcs );
|
||||
tss_insert_in_hash(dbs, wcs);
|
||||
}
|
||||
else
|
||||
wcs.erase();
|
||||
|
@ -257,13 +244,12 @@ cStringUtil::Convert( std::wstring& wcs, const wc16_string& dbs )
|
|||
}
|
||||
|
||||
/*static*/
|
||||
wc16_string::const_iterator
|
||||
cStringUtil::Convert( wc16_string& dbs, const std::wstring& wcs )
|
||||
wc16_string::const_iterator cStringUtil::Convert(wc16_string& dbs, const std::wstring& wcs)
|
||||
{
|
||||
if (wcs.size() != 0)
|
||||
{
|
||||
dbs.resize( wcs.size() );
|
||||
std::copy( wcs.begin(), wcs.end(), dbs.begin() );
|
||||
dbs.resize(wcs.size());
|
||||
std::copy(wcs.begin(), wcs.end(), dbs.begin());
|
||||
}
|
||||
else
|
||||
dbs.resize(0);
|
||||
|
@ -272,18 +258,17 @@ cStringUtil::Convert( wc16_string& dbs, const std::wstring& wcs )
|
|||
}
|
||||
|
||||
/*static*/
|
||||
std::wstring::const_iterator
|
||||
cStringUtil::Convert( std::wstring& wcs, const std::string& nbs )
|
||||
std::wstring::const_iterator cStringUtil::Convert(std::wstring& wcs, const std::string& nbs)
|
||||
{
|
||||
if (nbs.size() != 0)
|
||||
{
|
||||
wcs.resize( nbs.size() );
|
||||
wcs.resize(nbs.size());
|
||||
|
||||
size_t nWrote = ::mbstowcs( (wchar_t*)wcs.c_str(), nbs.c_str(), wcs.size() + 1 );
|
||||
if ( nWrote == (size_t)-1 )
|
||||
throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
size_t nWrote = ::mbstowcs((wchar_t*)wcs.c_str(), nbs.c_str(), wcs.size() + 1);
|
||||
if (nWrote == (size_t)-1)
|
||||
throw eCharacterEncoding(TSS_GetString(cCore, core::STR_ERR_BADCHAR));
|
||||
|
||||
wcs.resize( nWrote );
|
||||
wcs.resize(nWrote);
|
||||
}
|
||||
else
|
||||
wcs.erase();
|
||||
|
@ -292,22 +277,21 @@ cStringUtil::Convert( std::wstring& wcs, const std::string& nbs )
|
|||
}
|
||||
|
||||
/*static*/
|
||||
std::string::const_iterator
|
||||
cStringUtil::Convert( std::string& nbs, const std::wstring& wcs )
|
||||
std::string::const_iterator cStringUtil::Convert(std::string& nbs, const std::wstring& wcs)
|
||||
{
|
||||
if (wcs.size() != 0)
|
||||
{
|
||||
if( tss_find_in_hash( wc16_string( wcs.c_str() ), nbs ) )
|
||||
if (tss_find_in_hash(wc16_string(wcs.c_str()), nbs))
|
||||
return nbs.begin();
|
||||
|
||||
nbs.resize( MB_CUR_MAX * wcs.size() );
|
||||
size_t nWrote = ::wcstombs( (char*)nbs.c_str(), wcs.c_str(), nbs.size() + 1 );
|
||||
if ( nWrote == (size_t)-1 )
|
||||
throw eCharacterEncoding( TSS_GetString( cCore, core::STR_ERR_BADCHAR ) );
|
||||
nbs.resize(MB_CUR_MAX * wcs.size());
|
||||
size_t nWrote = ::wcstombs((char*)nbs.c_str(), wcs.c_str(), nbs.size() + 1);
|
||||
if (nWrote == (size_t)-1)
|
||||
throw eCharacterEncoding(TSS_GetString(cCore, core::STR_ERR_BADCHAR));
|
||||
|
||||
nbs.resize( nWrote );
|
||||
nbs.resize(nWrote);
|
||||
|
||||
tss_insert_in_hash( wc16_string( wcs.c_str() ), nbs );
|
||||
tss_insert_in_hash(wc16_string(wcs.c_str()), nbs);
|
||||
}
|
||||
else
|
||||
nbs.erase();
|
||||
|
@ -324,40 +308,39 @@ cStringUtil::Convert( std::string& nbs, const std::wstring& wcs )
|
|||
// TstrToStr
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string
|
||||
cStringUtil::TstrToStr( const TSTRING& tstr )
|
||||
std::string cStringUtil::TstrToStr(const TSTRING& tstr)
|
||||
{
|
||||
std::string s;
|
||||
cStringUtil::Convert( s, tstr );
|
||||
cStringUtil::Convert(s, tstr);
|
||||
return s;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// StrToTstr
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
TSTRING cStringUtil::StrToTstr( const std::string& rhs )
|
||||
TSTRING cStringUtil::StrToTstr(const std::string& rhs)
|
||||
{
|
||||
TSTRING lhs;
|
||||
cStringUtil::Convert( lhs, rhs );
|
||||
cStringUtil::Convert(lhs, rhs);
|
||||
return lhs;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// WstrToTstr
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
TSTRING cStringUtil::WstrToTstr(const wc16_string& rhs )
|
||||
TSTRING cStringUtil::WstrToTstr(const wc16_string& rhs)
|
||||
{
|
||||
TSTRING lhs;
|
||||
cStringUtil::Convert( lhs, rhs );
|
||||
cStringUtil::Convert(lhs, rhs);
|
||||
return lhs;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// TstrToWstr
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
wc16_string cStringUtil::TstrToWstr( const TSTRING& rhs )
|
||||
wc16_string cStringUtil::TstrToWstr(const TSTRING& rhs)
|
||||
{
|
||||
wc16_string lhs;
|
||||
cStringUtil::Convert( lhs, rhs );
|
||||
cStringUtil::Convert(lhs, rhs);
|
||||
return lhs;
|
||||
}
|
||||
|
|
|
@ -55,76 +55,65 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
namespace cStringUtil
|
||||
{
|
||||
//--Type Dispatched Conversion (Generalization away from TCHAR)
|
||||
//--Type Dispatched Conversion (Generalization away from TCHAR)
|
||||
|
||||
/// Handle Like-Types (xstring to xstring)
|
||||
/// Handle Like-Types (xstring to xstring)
|
||||
|
||||
inline
|
||||
const char *
|
||||
Convert( std::string& lhs, const std::string& rhs )
|
||||
{
|
||||
inline const char* Convert(std::string& lhs, const std::string& rhs)
|
||||
{
|
||||
lhs = rhs;
|
||||
return lhs.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
/// Specialize Everything Else
|
||||
/// Specialize Everything Else
|
||||
|
||||
std::string::const_iterator
|
||||
Convert( std::string&, const wc16_string& );
|
||||
std::string::const_iterator Convert(std::string&, const wc16_string&);
|
||||
|
||||
wc16_string::const_iterator
|
||||
Convert( wc16_string&, const std::string& );
|
||||
wc16_string::const_iterator Convert(wc16_string&, const std::string&);
|
||||
|
||||
#if SUPPORTS_WCHART && WCHAR_REP_IS_UCS2
|
||||
|
||||
inline
|
||||
std::wstring::const_iterator
|
||||
Convert( std::wstring& lhs, const std::wstring& rhs )
|
||||
{
|
||||
inline std::wstring::const_iterator Convert(std::wstring& lhs, const std::wstring& rhs)
|
||||
{
|
||||
lhs = rhs;
|
||||
return lhs.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring::const_iterator
|
||||
Convert( std::wstring&, const wc16_string& );
|
||||
std::wstring::const_iterator Convert(std::wstring&, const wc16_string&);
|
||||
|
||||
std::wstring::const_iterator
|
||||
Convert( std::wstring&, const std::string& );
|
||||
std::wstring::const_iterator Convert(std::wstring&, const std::string&);
|
||||
|
||||
std::string::const_iterator
|
||||
Convert( std::string&, const std::wstring& );
|
||||
std::string::const_iterator Convert(std::string&, const std::wstring&);
|
||||
|
||||
wc16_string::const_iterator
|
||||
Convert( wc16_string&, const std::wstring& );
|
||||
wc16_string::const_iterator Convert(wc16_string&, const std::wstring&);
|
||||
|
||||
#endif//SUPPORTS_WCHART
|
||||
#endif //SUPPORTS_WCHART
|
||||
|
||||
|
||||
/// WARNING: These are deprecated, please use Convert()!
|
||||
/// WARNING: These are deprecated, please use Convert()!
|
||||
|
||||
std::string TstrToStr( const TSTRING& tstr );
|
||||
// converts a tstring to a narrow string; useful for passphrase input, which must always be
|
||||
// the same format, regardless of what TCHAR is defined to.
|
||||
std::string TstrToStr(const TSTRING& tstr);
|
||||
// converts a tstring to a narrow string; useful for passphrase input, which must always be
|
||||
// the same format, regardless of what TCHAR is defined to.
|
||||
|
||||
TSTRING StrToTstr( const std::string& str );
|
||||
// converts a narrow string to a TSTRING
|
||||
TSTRING StrToTstr(const std::string& str);
|
||||
// converts a narrow string to a TSTRING
|
||||
|
||||
TSTRING WstrToTstr( const wc16_string& src );
|
||||
// convert wc16_string to a TSTRING
|
||||
wc16_string TstrToWstr( const TSTRING& tstr );
|
||||
// convert a TSTRING to a wc16_string
|
||||
TSTRING WstrToTstr(const wc16_string& src);
|
||||
// convert wc16_string to a TSTRING
|
||||
wc16_string TstrToWstr(const TSTRING& tstr);
|
||||
// convert a TSTRING to a wc16_string
|
||||
|
||||
|
||||
template <class IterT>
|
||||
void splitstring(IterT& iter,
|
||||
const TSTRING& str,
|
||||
const TSTRING& delims) {
|
||||
template<class IterT> void splitstring(IterT& iter, const TSTRING& str, const TSTRING& delims)
|
||||
{
|
||||
|
||||
TSTRING::size_type where;
|
||||
TSTRING tmpStr;
|
||||
TSTRING workingString = str;
|
||||
|
||||
while (workingString.length() > 0) {
|
||||
while (workingString.length() > 0)
|
||||
{
|
||||
|
||||
where = workingString.find_first_of(delims, 0);
|
||||
|
||||
|
@ -135,17 +124,14 @@ namespace cStringUtil
|
|||
where = workingString.length();
|
||||
|
||||
tmpStr = workingString.substr(0, where);
|
||||
workingString.erase(0, where+1);
|
||||
workingString.erase(0, where + 1);
|
||||
|
||||
iter.push_back(tmpStr);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}//cStringUtil::
|
||||
} // namespace cStringUtil
|
||||
|
||||
/*
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -202,5 +188,4 @@ namespace std
|
|||
}
|
||||
*/
|
||||
|
||||
#endif//__STRINGUTIL_H
|
||||
|
||||
#endif //__STRINGUTIL_H
|
||||
|
|
|
@ -57,12 +57,14 @@ class cTaskTimer
|
|||
|
||||
|
||||
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()
|
||||
{
|
||||
// stop the timer if it is currently running
|
||||
if(IsRunning())
|
||||
if (IsRunning())
|
||||
Stop();
|
||||
|
||||
// trace out the time contents...
|
||||
|
@ -72,7 +74,7 @@ public:
|
|||
|
||||
inline void Start()
|
||||
{
|
||||
ASSERT(! IsRunning());
|
||||
ASSERT(!IsRunning());
|
||||
time_t dummy;
|
||||
mStartTime = time(&dummy);
|
||||
mNumStarts++;
|
||||
|
@ -82,24 +84,37 @@ public:
|
|||
{
|
||||
ASSERT(IsRunning());
|
||||
time_t dummy;
|
||||
mTotalTime += ( time(&dummy) - mStartTime );
|
||||
mTotalTime += (time(&dummy) - mStartTime);
|
||||
mStartTime = 0;
|
||||
}
|
||||
|
||||
bool IsRunning() { return (mStartTime != 0); }
|
||||
void Reset() { mNumStarts = mStartTime = mTotalTime = 0; }
|
||||
uint32 GetTotalTime() const { return mTotalTime; }
|
||||
uint32 GetNumTimesStarted() const { return mNumStarts; }
|
||||
const std::string& GetName() const { return mName; }
|
||||
bool IsRunning()
|
||||
{
|
||||
return (mStartTime != 0);
|
||||
}
|
||||
void Reset()
|
||||
{
|
||||
mNumStarts = mStartTime = mTotalTime = 0;
|
||||
}
|
||||
uint32 GetTotalTime() const
|
||||
{
|
||||
return mTotalTime;
|
||||
}
|
||||
uint32 GetNumTimesStarted() const
|
||||
{
|
||||
return mNumStarts;
|
||||
}
|
||||
const std::string& GetName() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
private:
|
||||
TSTRING mName;
|
||||
uint32 mTotalTime;
|
||||
uint32 mStartTime;
|
||||
uint32 mNumStarts;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
#define __TCHAR_H
|
||||
|
||||
// A little macro that's useful for finding the number of characters in a TCHAR ARRAY
|
||||
#define countof( x ) ( sizeof( x ) / sizeof( x[0] ) )
|
||||
#define countof(x) (sizeof(x) / sizeof(x[0]))
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
@ -79,51 +79,50 @@ typedef std::ofstream TOFSTREAM;
|
|||
typedef std::ifstream TIFSTREAM;
|
||||
|
||||
// iostream abstractions
|
||||
#define TCIN std::cin
|
||||
#define TCOUT std::cout
|
||||
#define TCERR std::cerr
|
||||
# define TCIN std::cin
|
||||
# define TCOUT std::cout
|
||||
# define TCERR std::cerr
|
||||
|
||||
// other functions
|
||||
#define _ftprintf fprintf
|
||||
#define _stprintf sprintf
|
||||
#define _itot itoa
|
||||
#define _ttoi atoi
|
||||
#define _istdigit isdigit
|
||||
#define _tcsftime strftime
|
||||
#define _vtprintf vprintf
|
||||
#define _vftprintf vfprintf
|
||||
#define _topen open
|
||||
#define _tfdopen fdopen
|
||||
#define _tfopen fopen
|
||||
#define _tmkdir mkdir
|
||||
#define _tcscpy strcpy
|
||||
#define _tgetenv getenv
|
||||
#define _taccess access
|
||||
#define _tcreat creat
|
||||
#define _tunlink unlink
|
||||
#define _tcscmp strcmp
|
||||
#define _tcsicmp strcasecmp
|
||||
#define _totlower tolower
|
||||
#define _totupper toupper
|
||||
#define _tcslen strlen
|
||||
#define _tcscat strcat
|
||||
#define _tcsncmp strncmp
|
||||
# define _ftprintf fprintf
|
||||
# define _stprintf sprintf
|
||||
# define _itot itoa
|
||||
# define _ttoi atoi
|
||||
# define _istdigit isdigit
|
||||
# define _tcsftime strftime
|
||||
# define _vtprintf vprintf
|
||||
# define _vftprintf vfprintf
|
||||
# define _topen open
|
||||
# define _tfdopen fdopen
|
||||
# define _tfopen fopen
|
||||
# define _tmkdir mkdir
|
||||
# define _tcscpy strcpy
|
||||
# define _tgetenv getenv
|
||||
# define _taccess access
|
||||
# define _tcreat creat
|
||||
# define _tunlink unlink
|
||||
# define _tcscmp strcmp
|
||||
# define _tcsicmp strcasecmp
|
||||
# define _totlower tolower
|
||||
# define _totupper toupper
|
||||
# define _tcslen strlen
|
||||
# define _tcscat strcat
|
||||
# define _tcsncmp strncmp
|
||||
|
||||
// other abstractions
|
||||
#define TUNLINK unlink
|
||||
# define TUNLINK unlink
|
||||
|
||||
// string representation
|
||||
#if defined(_T)
|
||||
# if defined(_T)
|
||||
// run it right over with a bulldozer, tripwire doesn't seem
|
||||
// to use ctype.h's _T -PH
|
||||
#undef _T
|
||||
#endif
|
||||
#define _T(x) x
|
||||
# undef _T
|
||||
# endif
|
||||
# define _T(x) x
|
||||
|
||||
// misc...
|
||||
#ifndef __cdecl
|
||||
#define __cdecl
|
||||
#endif
|
||||
# ifndef __cdecl
|
||||
# define __cdecl
|
||||
# endif
|
||||
|
||||
#endif // __TCHAR_H
|
||||
|
||||
|
|
|
@ -55,33 +55,31 @@
|
|||
#define TIME_MAX 2147483647L // largest signed 32 bit number
|
||||
|
||||
#if IS_AROS
|
||||
#define tzset()
|
||||
# define tzset()
|
||||
#endif
|
||||
|
||||
struct tm* cTimeUtil::TimeToDateGMT( const int64& seconds )
|
||||
struct tm* cTimeUtil::TimeToDateGMT(const int64& seconds)
|
||||
{
|
||||
ASSERT( seconds < TIME_MAX );// this assumes time_t size is 32 bit. Yikes!
|
||||
ASSERT(seconds < TIME_MAX); // this assumes time_t size is 32 bit. Yikes!
|
||||
time_t t = static_cast<time_t>(seconds);
|
||||
return gmtime( &t );
|
||||
return gmtime(&t);
|
||||
}
|
||||
|
||||
struct tm* cTimeUtil::TimeToDateLocal( const int64& seconds )
|
||||
struct tm* cTimeUtil::TimeToDateLocal(const int64& seconds)
|
||||
{
|
||||
ASSERT( seconds < TIME_MAX );// this assumes time_t size is 32 bit. Yikes!
|
||||
ASSERT(seconds < TIME_MAX); // this assumes time_t size is 32 bit. Yikes!
|
||||
time_t t = static_cast<time_t>(seconds);
|
||||
tzset();
|
||||
return localtime( &t );
|
||||
return localtime(&t);
|
||||
}
|
||||
|
||||
int64 cTimeUtil::DateToTime( struct tm* ptm )
|
||||
int64 cTimeUtil::DateToTime(struct tm* ptm)
|
||||
{
|
||||
tzset();
|
||||
return mktime( ptm );
|
||||
return mktime(ptm);
|
||||
}
|
||||
|
||||
int64 cTimeUtil::GetTime()
|
||||
{
|
||||
return time( NULL );
|
||||
return time(NULL);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -62,15 +62,14 @@
|
|||
class cTimeUtil
|
||||
{
|
||||
public:
|
||||
static int64 DateToTime( struct tm* ptm );
|
||||
static int64 DateToTime(struct tm* ptm);
|
||||
// simple conversion. ptm is considered to be in localtime.
|
||||
static struct tm* TimeToDateGMT( const int64& seconds );
|
||||
static struct tm* TimeToDateGMT(const int64& seconds);
|
||||
// simple conversion
|
||||
static struct tm* TimeToDateLocal( const int64& seconds );
|
||||
static struct tm* TimeToDateLocal(const int64& seconds);
|
||||
// conversion with timezone and daylight
|
||||
static int64 GetTime();
|
||||
// returns current time in UTC
|
||||
};
|
||||
|
||||
#endif//__TIMECONVERT_H
|
||||
|
||||
#endif //__TIMECONVERT_H
|
||||
|
|
|
@ -36,9 +36,9 @@
|
|||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void util_SignalHandler( int sig );
|
||||
static void util_SignalHandler(int sig);
|
||||
|
||||
static void tw_psignal( int sig, const TCHAR* s );
|
||||
static void tw_psignal(int sig, const TCHAR* s);
|
||||
|
||||
tw_sighandler_t tw_signal(int sig, tw_sighandler_t pFunc)
|
||||
{
|
||||
|
@ -58,33 +58,32 @@ tw_sighandler_t tw_sigign(int sig)
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
// tw_HandleSignal -- Take a given signal and install a handler for
|
||||
// it, which will then exit with the supplied exit value
|
||||
tw_sighandler_t tw_HandleSignal( int sig )
|
||||
tw_sighandler_t tw_HandleSignal(int sig)
|
||||
{
|
||||
return signal( sig, util_SignalHandler );
|
||||
return signal(sig, util_SignalHandler);
|
||||
}
|
||||
|
||||
void util_SignalHandler( int sig )
|
||||
void util_SignalHandler(int sig)
|
||||
{
|
||||
//If we're on unix, let's print out a nice error message telling
|
||||
//the user which signal we've recieved.
|
||||
tw_psignal( sig, (TSS_GetString( cCore, core::STR_SIGNAL).c_str() ) );
|
||||
exit( 8 );
|
||||
tw_psignal(sig, (TSS_GetString(cCore, core::STR_SIGNAL).c_str()));
|
||||
exit(8);
|
||||
}
|
||||
|
||||
/* For the morbidly curious, here's a thread where a POSIX standards committee
|
||||
wrings its hands about how to define NSIG: http://austingroupbugs.net/view.php?id=741#c1834 */
|
||||
#ifndef NSIG
|
||||
# ifdef SIGMAX
|
||||
# define NSIG (SIGMAX+1)
|
||||
# define NSIG (SIGMAX + 1)
|
||||
# else
|
||||
# define NSIG 32
|
||||
# endif
|
||||
#endif
|
||||
|
||||
void tw_psignal(int sig, const TCHAR *str)
|
||||
void tw_psignal(int sig, const TCHAR* str)
|
||||
{
|
||||
const TCHAR *siglist[NSIG] = {
|
||||
_T("Unknown Signal"),
|
||||
const TCHAR* siglist[NSIG] = {_T("Unknown Signal"),
|
||||
_T("Hangup"),
|
||||
_T("Interrupt"),
|
||||
_T("Quit"),
|
||||
|
@ -114,10 +113,7 @@ void tw_psignal(int sig, const TCHAR *str)
|
|||
_T("Stopped (tty input)"),
|
||||
_T("Stopped (tty output)"),
|
||||
_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]);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -45,12 +45,13 @@
|
|||
#include <bits/signum.h>
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
typedef void (*tw_sighandler_t)(int);
|
||||
extern "C"
|
||||
{
|
||||
typedef void (*tw_sighandler_t)(int);
|
||||
}
|
||||
|
||||
tw_sighandler_t tw_signal(int sig, tw_sighandler_t pFunc);
|
||||
int tw_raise (int sig);
|
||||
int tw_raise(int sig);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// tw_sigign -- wrapper around tw_signal(XXX, SIG_IGN)
|
||||
|
@ -60,8 +61,7 @@ tw_sighandler_t tw_sigign(int sig);
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// tw_HandleSignal --wrapper around signal( XXX, <our handler function> )
|
||||
//
|
||||
tw_sighandler_t tw_HandleSignal( int sig );
|
||||
tw_sighandler_t tw_HandleSignal(int sig);
|
||||
|
||||
|
||||
#endif //__TW_SIGNAL_H
|
||||
|
||||
|
|
|
@ -44,9 +44,9 @@
|
|||
// METHOD CODE
|
||||
//=========================================================================
|
||||
|
||||
bool cInterpretInt::InterpretInt( const TSTRING& str, int* pi )
|
||||
bool cInterpretInt::InterpretInt(const TSTRING& str, int* pi)
|
||||
{
|
||||
ASSERT( pi != 0);
|
||||
ASSERT(pi != 0);
|
||||
|
||||
bool fFormatOK = true;
|
||||
|
||||
|
@ -55,21 +55,21 @@ bool cInterpretInt::InterpretInt( const TSTRING& str, int* pi )
|
|||
//
|
||||
TOSTRINGSTREAM sstr;
|
||||
sstr << cInterpretInt::LIMIT_MAX;
|
||||
if( str.length() > sstr.str().length() )
|
||||
if (str.length() > sstr.str().length())
|
||||
fFormatOK = false;
|
||||
|
||||
//
|
||||
// make sure string is not too short
|
||||
//
|
||||
if( fFormatOK && str.length() <= 0 )
|
||||
if (fFormatOK && str.length() <= 0)
|
||||
fFormatOK = false;
|
||||
|
||||
//
|
||||
// make sure first character is a digit or the minus sign
|
||||
//
|
||||
if( fFormatOK )
|
||||
if (fFormatOK)
|
||||
{
|
||||
if( ! ( _T('-') == str[0] || std::isdigit<TCHAR>( str[0], std::locale() ) ) )
|
||||
if (!(_T('-') == str[0] || std::isdigit<TCHAR>(str[0], std::locale())))
|
||||
fFormatOK = false;
|
||||
}
|
||||
|
||||
|
@ -77,23 +77,22 @@ bool cInterpretInt::InterpretInt( const TSTRING& str, int* pi )
|
|||
// make sure all other characters are digits
|
||||
// NOTE:BAM -- this assumes that all digits in all locales are SB characters.
|
||||
// TODO:BAM -- check this...
|
||||
for( TSTRING::size_type j = 1; fFormatOK && j < str.length(); j++ )
|
||||
for (TSTRING::size_type j = 1; fFormatOK && j < str.length(); j++)
|
||||
{
|
||||
if( ! std::isdigit<TCHAR>( str[j], std::locale() ) )
|
||||
if (!std::isdigit<TCHAR>(str[j], std::locale()))
|
||||
fFormatOK = false;
|
||||
}
|
||||
|
||||
//
|
||||
// do _ttoi conversion and check that it is within allowable limits
|
||||
//
|
||||
if( fFormatOK )
|
||||
if (fFormatOK)
|
||||
{
|
||||
*pi = _ttoi( str.c_str() );
|
||||
*pi = _ttoi(str.c_str());
|
||||
|
||||
if( *pi < GetMin() || *pi > GetMax() )
|
||||
if (*pi < GetMin() || *pi > GetMax())
|
||||
fFormatOK = false;
|
||||
}
|
||||
|
||||
return fFormatOK;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ public:
|
|||
//
|
||||
// basic functionality
|
||||
//
|
||||
bool InterpretInt( const TSTRING& str, int* pi );
|
||||
bool InterpretInt(const TSTRING& str, int* pi);
|
||||
// converts the string into an int value, returned in *pi.
|
||||
// returns true if successfully converted value.
|
||||
// *pi is undefined if function returns false.
|
||||
|
@ -86,11 +86,19 @@ private:
|
|||
//
|
||||
// private functionality
|
||||
//
|
||||
virtual int GetMax() { return LIMIT_MAX; };
|
||||
virtual int GetMin() { return LIMIT_MIN; };
|
||||
virtual int GetMax()
|
||||
{
|
||||
return LIMIT_MAX;
|
||||
};
|
||||
virtual int GetMin()
|
||||
{
|
||||
return LIMIT_MIN;
|
||||
};
|
||||
|
||||
public:
|
||||
virtual ~cInterpretInt() {}
|
||||
virtual ~cInterpretInt()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////
|
||||
|
@ -105,11 +113,19 @@ private:
|
|||
LIMIT_MAX = 1000000
|
||||
};
|
||||
|
||||
virtual int GetMax() { return LIMIT_MAX; };
|
||||
virtual int GetMin() { return LIMIT_MIN; };
|
||||
virtual int GetMax()
|
||||
{
|
||||
return LIMIT_MAX;
|
||||
};
|
||||
virtual int GetMin()
|
||||
{
|
||||
return LIMIT_MIN;
|
||||
};
|
||||
|
||||
public:
|
||||
virtual ~cSeverityLimits() {}
|
||||
virtual ~cSeverityLimits()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////
|
||||
|
@ -124,12 +140,19 @@ private:
|
|||
LIMIT_MAX = 1000000
|
||||
};
|
||||
|
||||
virtual int GetMax() { return LIMIT_MAX; };
|
||||
virtual int GetMin() { return LIMIT_MIN; };
|
||||
virtual int GetMax()
|
||||
{
|
||||
return LIMIT_MAX;
|
||||
};
|
||||
virtual int GetMin()
|
||||
{
|
||||
return LIMIT_MIN;
|
||||
};
|
||||
|
||||
public:
|
||||
virtual ~cRecurseDepthLimits() {}
|
||||
virtual ~cRecurseDepthLimits()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif //__TWLIMITS_H
|
||||
|
||||
|
|
|
@ -57,11 +57,11 @@
|
|||
//=========================================================================
|
||||
// UTIL FUNCTION PROTOTYPES
|
||||
//=========================================================================
|
||||
static TSTRING& util_FormatTimeC( struct tm* ptm, TSTRING& strBuf );
|
||||
static TSTRING& util_FormatTime( struct tm* ptm, TSTRING& strBuf );
|
||||
static TSTRING& util_FormatTimeC(struct tm* ptm, TSTRING& strBuf);
|
||||
static TSTRING& util_FormatTime(struct tm* ptm, TSTRING& strBuf);
|
||||
|
||||
#if !USES_CLIB_DATE_FUNCTION
|
||||
static TSTRING& util_FormatTimeCPlusPlus( struct tm* ptm, TSTRING& strBuf );
|
||||
static TSTRING& util_FormatTimeCPlusPlus(struct tm* ptm, TSTRING& strBuf);
|
||||
#endif
|
||||
|
||||
//=========================================================================
|
||||
|
@ -69,39 +69,38 @@ static TSTRING& util_FormatTimeCPlusPlus( struct tm* ptm, TSTRING& strBuf );
|
|||
//=========================================================================
|
||||
|
||||
#if IS_AROS
|
||||
#define tzset()
|
||||
# define tzset()
|
||||
#endif
|
||||
|
||||
void cTWLocale::InitGlobalLocale()
|
||||
{
|
||||
cDebug d("cTWLocale::InitGlobalLocale");
|
||||
|
||||
d.TraceDetail( "Attempting to set the program locale from the"
|
||||
"default \"C\" locale to the system-default locale." );
|
||||
d.TraceDetail("Attempting to set the program locale from the"
|
||||
"default \"C\" locale to the system-default locale.");
|
||||
|
||||
#if USE_CLIB_LOCALE
|
||||
char* pchLocale = setlocale( LC_ALL, "" );
|
||||
char* pchLocale = setlocale(LC_ALL, "");
|
||||
|
||||
d.TraceDetail( "C++ locale is incomplete or unavailable with this compiler, so"
|
||||
d.TraceDetail("C++ locale is incomplete or unavailable with this compiler, so"
|
||||
"only changing the C-language locale. Some C++ locale-specific functionality"
|
||||
"may not function properly." );
|
||||
"may not function properly.");
|
||||
|
||||
if( pchLocale )
|
||||
if (pchLocale)
|
||||
{
|
||||
d.TraceDebug( "locale changed to the system-default locale (non-C++): <%s>\n", pchLocale );
|
||||
d.TraceDebug("locale changed to the system-default locale (non-C++): <%s>\n", pchLocale);
|
||||
}
|
||||
else
|
||||
{
|
||||
d.TraceDebug( "Error: unable to change locale to the system-default.\n"
|
||||
d.TraceDebug("Error: unable to change locale to the system-default.\n"
|
||||
"It is possible that there is no other locale than\n"
|
||||
"the \"C\" locale on this platform.\n" );
|
||||
"the \"C\" locale on this platform.\n");
|
||||
}
|
||||
#else
|
||||
std::locale l("");
|
||||
std::locale::global( l );
|
||||
d.TraceDebug( "locale changed to the system default std::locale (C++): <%s>\n", l.name().c_str() );
|
||||
std::locale::global(l);
|
||||
d.TraceDebug("locale changed to the system default std::locale (C++): <%s>\n", l.name().c_str());
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -128,11 +127,9 @@ TSTRING cTWLocale::FormatNumberAsHex( int32 i )
|
|||
}
|
||||
*/
|
||||
|
||||
template< class numT, class CharT >
|
||||
class cFormatNumberUtil
|
||||
template<class numT, class CharT> class cFormatNumberUtil
|
||||
{
|
||||
public:
|
||||
|
||||
// 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
|
||||
//. the FormatNumberAsHex function as well
|
||||
|
@ -143,30 +140,23 @@ public:
|
|||
// cFormatNumberUtil::FormatNumber( const std::basic_string< CharT >& s, bool fCStyleFormatting = false )
|
||||
//-----------------------------------------------------------------------------
|
||||
// EFFECTS: Does all actual formatting for FormatNumber methods
|
||||
static
|
||||
numT
|
||||
Format( const std::basic_string< CharT >& s, bool fCStyleFormatting )
|
||||
static numT Format(const std::basic_string<CharT>& s, bool fCStyleFormatting)
|
||||
{
|
||||
static const std::num_get< CharT >* png;
|
||||
std::basic_istringstream< CharT > ss( s );
|
||||
static const std::num_get<CharT>* png;
|
||||
std::basic_istringstream<CharT> ss(s);
|
||||
std::ios_base::iostate state;
|
||||
numT n;
|
||||
|
||||
if( fCStyleFormatting )
|
||||
ss.imbue( std::locale::classic() );
|
||||
if (fCStyleFormatting)
|
||||
ss.imbue(std::locale::classic());
|
||||
|
||||
tss::GetFacet( ss.getloc(), png ).get(
|
||||
ss,
|
||||
std::istreambuf_iterator< CharT >(),
|
||||
ss,
|
||||
state,
|
||||
n );
|
||||
tss::GetFacet(ss.getloc(), png).get(ss, std::istreambuf_iterator<CharT>(), ss, state, n);
|
||||
|
||||
|
||||
if( ( state & std::ios_base::failbit ) != 0 )
|
||||
if ((state & std::ios_base::failbit) != 0)
|
||||
throw eTWLocaleBadNumFormat();
|
||||
|
||||
return( n );
|
||||
return (n);
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
@ -175,20 +165,18 @@ public:
|
|||
//-----------------------------------------------------------------------------
|
||||
// EFFECTS: Does all actual formatting for FormatNumber methods
|
||||
//
|
||||
static
|
||||
std::basic_string< CharT >&
|
||||
Format( numT n, std::basic_string< CharT >& sBuf, bool fCStyleFormatting = false )
|
||||
static std::basic_string<CharT>& Format(numT n, std::basic_string<CharT>& sBuf, bool fCStyleFormatting = false)
|
||||
{
|
||||
static const std::num_put< CharT >* pnp;
|
||||
std::basic_ostringstream< CharT > ss;
|
||||
static const std::num_put<CharT>* pnp;
|
||||
std::basic_ostringstream<CharT> ss;
|
||||
|
||||
if( fCStyleFormatting )
|
||||
ss.imbue( std::locale::classic() );
|
||||
if (fCStyleFormatting)
|
||||
ss.imbue(std::locale::classic());
|
||||
|
||||
tss::GetFacet( ss.getloc(), pnp ).put( ss, ss, ss.fill(), n );
|
||||
tss::GetFacet(ss.getloc(), pnp).put(ss, ss, ss.fill(), n);
|
||||
|
||||
sBuf = ss.str();
|
||||
return( sBuf );
|
||||
return (sBuf);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -205,102 +193,102 @@ int32 cTWLocale::FormatNumberClassic( const TSTRING& s )
|
|||
}
|
||||
*/
|
||||
|
||||
TSTRING& cTWLocale::FormatNumber( uint64 ui, TSTRING& strBuf )
|
||||
TSTRING& cTWLocale::FormatNumber(uint64 ui, TSTRING& strBuf)
|
||||
{
|
||||
// try to use the int64 version
|
||||
if( ui <= (uint64)TSS_INT64_MAX )
|
||||
return( FormatNumber( (int64)ui, strBuf ) );
|
||||
if (ui <= (uint64)TSS_INT64_MAX)
|
||||
return (FormatNumber((int64)ui, strBuf));
|
||||
else
|
||||
{
|
||||
#if IS_MSVC
|
||||
#if IS_MSVC
|
||||
// MSVC can't convert from uint64 to a double for some reason
|
||||
strBuf = TSS_GetString( cCore, core::STR_NUMBER_TOO_BIG );
|
||||
return( strBuf );
|
||||
#else
|
||||
ASSERT( std::numeric_limits<double>::max() >= TSS_UINT64_MAX );
|
||||
return( cFormatNumberUtil< double, TCHAR >::Format( (double)ui, strBuf ) );
|
||||
#endif
|
||||
strBuf = TSS_GetString(cCore, core::STR_NUMBER_TOO_BIG);
|
||||
return (strBuf);
|
||||
#else
|
||||
ASSERT(std::numeric_limits<double>::max() >= TSS_UINT64_MAX);
|
||||
return (cFormatNumberUtil<double, TCHAR>::Format((double)ui, strBuf));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
TSTRING& cTWLocale::FormatNumber( int64 i, TSTRING& strBuf )
|
||||
TSTRING& cTWLocale::FormatNumber(int64 i, TSTRING& strBuf)
|
||||
{
|
||||
// try to use the int32 version
|
||||
if( i <= (int64)TSS_INT32_MAX )
|
||||
return( FormatNumber( (int32)i, strBuf ) );
|
||||
if (i <= (int64)TSS_INT32_MAX)
|
||||
return (FormatNumber((int32)i, strBuf));
|
||||
else
|
||||
{
|
||||
ASSERT( std::numeric_limits<double>::max() >= TSS_INT64_MAX );
|
||||
return( cFormatNumberUtil< double, TCHAR >::Format( (double)i, strBuf ) );
|
||||
ASSERT(std::numeric_limits<double>::max() >= TSS_INT64_MAX);
|
||||
return (cFormatNumberUtil<double, TCHAR>::Format((double)i, strBuf));
|
||||
}
|
||||
}
|
||||
|
||||
TSTRING& cTWLocale::FormatNumber( uint32 ui, TSTRING& strBuf )
|
||||
TSTRING& cTWLocale::FormatNumber(uint32 ui, TSTRING& strBuf)
|
||||
{
|
||||
ASSERT( sizeof(unsigned long) >= sizeof(uint32) ); // must be able to cast to 'ulong'
|
||||
return( cFormatNumberUtil< unsigned long, TCHAR >::Format( (unsigned long)ui, strBuf ) );
|
||||
ASSERT(sizeof(unsigned long) >= sizeof(uint32)); // must be able to cast to 'ulong'
|
||||
return (cFormatNumberUtil<unsigned long, TCHAR>::Format((unsigned long)ui, strBuf));
|
||||
}
|
||||
|
||||
TSTRING& cTWLocale::FormatNumber( int32 i, TSTRING& strBuf )
|
||||
TSTRING& cTWLocale::FormatNumber(int32 i, TSTRING& strBuf)
|
||||
{
|
||||
ASSERT( sizeof(long) >= sizeof(int32) ); // must be able to cast to 'long'
|
||||
return( cFormatNumberUtil< long, TCHAR >::Format( (long)i, strBuf ) );
|
||||
ASSERT(sizeof(long) >= sizeof(int32)); // must be able to cast to 'long'
|
||||
return (cFormatNumberUtil<long, TCHAR>::Format((long)i, strBuf));
|
||||
}
|
||||
|
||||
TSTRING& cTWLocale::FormatTime( int64 t, TSTRING& strBuf )
|
||||
TSTRING& cTWLocale::FormatTime(int64 t, TSTRING& strBuf)
|
||||
{
|
||||
// clear return string
|
||||
strBuf.erase();
|
||||
tzset();
|
||||
time_t tmpTime = t;
|
||||
struct tm * ptm = localtime( &tmpTime );
|
||||
if( ptm )
|
||||
struct tm* ptm = localtime(&tmpTime);
|
||||
if (ptm)
|
||||
{
|
||||
util_FormatTime( ptm, strBuf );
|
||||
util_FormatTime(ptm, strBuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
strBuf = TSS_GetString( cCore, core::STR_UNKNOWN_TIME );
|
||||
strBuf = TSS_GetString(cCore, core::STR_UNKNOWN_TIME);
|
||||
}
|
||||
|
||||
return( strBuf );
|
||||
return (strBuf);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// UTIL FUNCTION IMPLEMENTATION
|
||||
//=========================================================================
|
||||
|
||||
TSTRING& util_FormatTime( struct tm* ptm, TSTRING& strBuf )
|
||||
TSTRING& util_FormatTime(struct tm* ptm, TSTRING& strBuf)
|
||||
{
|
||||
ASSERT( ptm );
|
||||
ASSERT(ptm);
|
||||
|
||||
#if USES_CLIB_DATE_FUNCTION
|
||||
#if USES_CLIB_DATE_FUNCTION
|
||||
|
||||
return util_FormatTimeC( ptm, strBuf );
|
||||
return util_FormatTimeC(ptm, strBuf);
|
||||
|
||||
#else
|
||||
#else
|
||||
|
||||
return util_FormatTimeCPlusPlus( ptm, strBuf );
|
||||
return util_FormatTimeCPlusPlus(ptm, strBuf);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if !USES_CLIB_DATE_FUNCTION
|
||||
TSTRING& util_FormatTimeCPlusPlus( struct tm* ptm, TSTRING& strBuf )
|
||||
TSTRING& util_FormatTimeCPlusPlus(struct tm* ptm, TSTRING& strBuf)
|
||||
{
|
||||
ASSERT( ptm );
|
||||
ASSERT(ptm);
|
||||
TOSTRINGSTREAM sstr;
|
||||
static const std::time_put<TCHAR>* ptp;
|
||||
|
||||
//
|
||||
// format date
|
||||
//
|
||||
#if IS_MSVC // MSVC uses old put() signature which didn't have the fill character, (and uses proprietary '#')
|
||||
tss::GetFacet( sstr.getloc(), ptp ).put( sstr, sstr, ptm, 'c', '#' );
|
||||
#else
|
||||
tss::GetFacet( sstr.getloc(), ptp ).put( sstr, sstr, sstr.fill(), ptm, 'c' );
|
||||
#endif
|
||||
# if IS_MSVC // MSVC uses old put() signature which didn't have the fill character, (and uses proprietary '#')
|
||||
tss::GetFacet(sstr.getloc(), ptp).put(sstr, sstr, ptm, 'c', '#');
|
||||
# else
|
||||
tss::GetFacet(sstr.getloc(), ptp).put(sstr, sstr, sstr.fill(), ptm, 'c');
|
||||
# endif
|
||||
|
||||
strBuf = sstr.str();
|
||||
return strBuf;
|
||||
|
@ -308,27 +296,27 @@ TSTRING& util_FormatTimeCPlusPlus( struct tm* ptm, TSTRING& strBuf )
|
|||
#endif
|
||||
|
||||
|
||||
TSTRING& util_FormatTimeC( struct tm* ptm, TSTRING& strBuf )
|
||||
TSTRING& util_FormatTimeC(struct tm* ptm, TSTRING& strBuf)
|
||||
{
|
||||
ASSERT( ptm );
|
||||
ASSERT(ptm);
|
||||
|
||||
TCHAR achTimeBuf[256];
|
||||
|
||||
/* 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"),
|
||||
#else
|
||||
#else
|
||||
_T("%c"),
|
||||
#endif
|
||||
ptm );
|
||||
#endif
|
||||
ptm);
|
||||
|
||||
if( nbWritten )
|
||||
if (nbWritten)
|
||||
strBuf = achTimeBuf;
|
||||
else
|
||||
strBuf = TSS_GetString( cCore, core::STR_UNKNOWN_TIME );
|
||||
strBuf = TSS_GetString(cCore, core::STR_UNKNOWN_TIME);
|
||||
|
||||
return strBuf;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,8 +52,8 @@
|
|||
// DECLARATION OF CLASSES
|
||||
//=========================================================================
|
||||
|
||||
TSS_EXCEPTION( eTWLocale, eError );
|
||||
TSS_EXCEPTION( eTWLocaleBadNumFormat, eError );
|
||||
TSS_EXCEPTION(eTWLocale, eError);
|
||||
TSS_EXCEPTION(eTWLocaleBadNumFormat, eError);
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// cTWLocale
|
||||
|
@ -73,22 +73,22 @@ public:
|
|||
//
|
||||
// basic functionality
|
||||
//
|
||||
static TSTRING& FormatNumber( int32 i, TSTRING& strBuf );
|
||||
static TSTRING& FormatNumber( int64 i, TSTRING& strBuf );
|
||||
static TSTRING& FormatNumber( uint32 ui, TSTRING& strBuf );
|
||||
static TSTRING& FormatNumber( uint64 ui, TSTRING& strBuf );
|
||||
static TSTRING& FormatNumber( double d, TSTRING& strBuf );
|
||||
static TSTRING& FormatNumber(int32 i, TSTRING& strBuf);
|
||||
static TSTRING& FormatNumber(int64 i, TSTRING& strBuf);
|
||||
static TSTRING& FormatNumber(uint32 ui, TSTRING& strBuf);
|
||||
static TSTRING& FormatNumber(uint64 ui, TSTRING& strBuf);
|
||||
static TSTRING& FormatNumber(double d, TSTRING& strBuf);
|
||||
// returns the locale-specific representation of the given cardinal number
|
||||
/*
|
||||
/*
|
||||
static TSTRING FormatNumberClassic( int32 i );
|
||||
static int32 FormatNumberClassic( const TSTRING& s );
|
||||
// returns the C-locale representation of the given cardinal number
|
||||
*/
|
||||
// disabled this since nobody's using it
|
||||
// static TSTRING FormatNumberAsHex( int32 x );
|
||||
// disabled this since nobody's using it
|
||||
// static TSTRING FormatNumberAsHex( int32 x );
|
||||
// locale-independant
|
||||
|
||||
static TSTRING& FormatTime( int64 t, TSTRING& strBuf );
|
||||
static TSTRING& FormatTime(int64 t, TSTRING& strBuf);
|
||||
// returns the local time and date formatted according to the current locale.
|
||||
// t is the number of seconds elapsed since midnight (00:00:00),
|
||||
// January 1, 1970, coordinated universal time
|
||||
|
@ -100,22 +100,21 @@ public:
|
|||
|
||||
namespace tss
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// GetFacet
|
||||
//
|
||||
// Abstracts std::use_facet since Win32 and KAI
|
||||
// each implement it in a non-standard way.
|
||||
////////////////////////////////////////////////
|
||||
template< class FacetT > inline const FacetT& GetFacet( const std::locale& l, const FacetT* pf )
|
||||
{
|
||||
////////////////////////////////////////////////
|
||||
// GetFacet
|
||||
//
|
||||
// Abstracts std::use_facet since Win32 and KAI
|
||||
// each implement it in a non-standard way.
|
||||
////////////////////////////////////////////////
|
||||
template<class FacetT> inline const FacetT& GetFacet(const std::locale& l, const FacetT* pf)
|
||||
{
|
||||
#if USE_STD_CPP_LOCALE_WORKAROUND
|
||||
return std::use_facet( l, pf );
|
||||
return std::use_facet(l, pf);
|
||||
#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
|
||||
}
|
||||
}
|
||||
} // namespace tss
|
||||
|
||||
#endif //__TWLOCALE_H
|
||||
|
||||
|
||||
|
|
|
@ -42,4 +42,3 @@ enum Languages
|
|||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ public:
|
|||
const TCHAR* AsString() const;
|
||||
bool operator==(const cType& rhs) const;
|
||||
bool operator!=(const cType& rhs) const;
|
||||
|
||||
private:
|
||||
TSTRING mString;
|
||||
};
|
||||
|
@ -62,28 +63,30 @@ public:
|
|||
// (b) returning that object in their implementation of GetType()
|
||||
// You can use the macros below to simplify the process
|
||||
|
||||
virtual ~iTyped() {}
|
||||
virtual ~iTyped()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// convenience macros for implementing iTyped
|
||||
//////////////////////////////////////////////
|
||||
#define DECLARE_TYPED()\
|
||||
public:\
|
||||
static const cType mType;\
|
||||
virtual const cType& GetType() const;
|
||||
// put DECLARE_TYPED in the class definition
|
||||
#define DECLARE_TYPED() \
|
||||
public: \
|
||||
static const cType mType; \
|
||||
virtual const cType& GetType() const;
|
||||
// put DECLARE_TYPED in the class definition
|
||||
|
||||
#define IMPLEMENT_TYPED(CLASS, STRING)\
|
||||
const cType CLASS::mType(STRING);\
|
||||
const cType& CLASS::GetType() const\
|
||||
{\
|
||||
return mType;\
|
||||
}
|
||||
// put IMPLEMENT_TYPED in the .cpp file where the class is implemented
|
||||
#define IMPLEMENT_TYPED(CLASS, STRING) \
|
||||
const cType CLASS::mType(STRING); \
|
||||
const cType& CLASS::GetType() const \
|
||||
{ \
|
||||
return mType; \
|
||||
}
|
||||
// put IMPLEMENT_TYPED in the .cpp file where the class is implemented
|
||||
|
||||
#define CLASS_TYPE(CLASS) CLASS::mType
|
||||
// a convienent way to specify a class's type
|
||||
// a convienent way to specify a class's type
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// iTyped Example
|
||||
|
@ -116,8 +119,7 @@ const cType& CLASS::GetType() const\
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// inline implementation
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
inline cType::cType(const TCHAR* name) :
|
||||
mString(name)
|
||||
inline cType::cType(const TCHAR* name) : mString(name)
|
||||
{
|
||||
ASSERT(!mString.empty());
|
||||
}
|
||||
|
@ -140,4 +142,3 @@ inline bool cType::operator!=(const cType& rhs) const
|
|||
|
||||
|
||||
#endif //__TYPED_H
|
||||
|
||||
|
|
|
@ -41,44 +41,43 @@
|
|||
#endif
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// standard TSS types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef unsigned char byte ; // platform-independent
|
||||
typedef unsigned char byte; // platform-independent
|
||||
|
||||
typedef signed char int8 ;
|
||||
typedef short int16 ;
|
||||
typedef float float32 ;
|
||||
typedef double float64 ;
|
||||
typedef unsigned char uint8 ;
|
||||
typedef unsigned short uint16 ;
|
||||
typedef signed char int8;
|
||||
typedef short int16;
|
||||
typedef float float32;
|
||||
typedef double float64;
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned short uint16;
|
||||
|
||||
#if HAVE_STDINT_H
|
||||
typedef int32_t int32 ;
|
||||
typedef uint32_t uint32 ;
|
||||
typedef int32_t int32;
|
||||
typedef uint32_t uint32;
|
||||
|
||||
#elif SIZEOF_INT == 4
|
||||
typedef int int32 ;
|
||||
typedef unsigned int uint32 ;
|
||||
typedef int int32;
|
||||
typedef unsigned int uint32;
|
||||
|
||||
#elif SIZEOF_LONG == 4
|
||||
typedef long int32 ;
|
||||
typedef unsigned long uint32 ;
|
||||
typedef long int32;
|
||||
typedef unsigned long uint32;
|
||||
#else
|
||||
# error "I don't seem to have a 32-bit integer type on this system."
|
||||
#endif
|
||||
|
||||
#if HAVE_STDINT_H
|
||||
typedef int64_t int64 ;
|
||||
typedef uint64_t uint64 ;
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
#elif SIZEOF_LONG == 8
|
||||
typedef long int64 ;
|
||||
typedef unsigned long uint64 ;
|
||||
typedef long int64;
|
||||
typedef unsigned long uint64;
|
||||
#elif SIZEOF_LONG_LONG == 8
|
||||
typedef long long int64 ;
|
||||
typedef unsigned long long uint64 ;
|
||||
typedef long long int64;
|
||||
typedef unsigned long long uint64;
|
||||
#else
|
||||
# error "I don't seem to have a 64-bit integer type on this system."
|
||||
#endif
|
||||
|
@ -93,7 +92,7 @@ typedef unsigned long long uint64 ;
|
|||
|
||||
|
||||
#if (!(USES_2S_COMPLEMENT))
|
||||
#error limits.h depends on 2s complement integers. Check core/types.h
|
||||
# error limits.h depends on 2s complement integers. Check core/types.h
|
||||
#endif
|
||||
|
||||
#include <limits.h> // defines limits for built-in types
|
||||
|
@ -157,60 +156,49 @@ inline int16 SWAPBYTES16(int16 i)
|
|||
{
|
||||
|
||||
return ((uint16)i >> 8) | ((uint16)i << 8);
|
||||
|
||||
}
|
||||
|
||||
inline int32 SWAPBYTES32(int32 i)
|
||||
{
|
||||
return ((uint32)i >> 24) |
|
||||
(((uint32)i & 0x00ff0000) >> 8) |
|
||||
(((uint32)i & 0x0000ff00) << 8) |
|
||||
((uint32)i << 24);
|
||||
return ((uint32)i >> 24) | (((uint32)i & 0x00ff0000) >> 8) | (((uint32)i & 0x0000ff00) << 8) | ((uint32)i << 24);
|
||||
}
|
||||
|
||||
inline int64 SWAPBYTES64(int64 i)
|
||||
{
|
||||
return ((uint64)i >> 56) |
|
||||
(((uint64)i & 0x00ff000000000000ULL) >> 40) |
|
||||
(((uint64)i & 0x0000ff0000000000ULL) >> 24) |
|
||||
(((uint64)i & 0x000000ff00000000ULL) >> 8) |
|
||||
(((uint64)i & 0x00000000ff000000ULL) << 8) |
|
||||
(((uint64)i & 0x0000000000ff0000ULL) << 24) |
|
||||
(((uint64)i & 0x000000000000ff00ULL) << 40) |
|
||||
((uint64)i << 56);
|
||||
return ((uint64)i >> 56) | (((uint64)i & 0x00ff000000000000ULL) >> 40) |
|
||||
(((uint64)i & 0x0000ff0000000000ULL) >> 24) | (((uint64)i & 0x000000ff00000000ULL) >> 8) |
|
||||
(((uint64)i & 0x00000000ff000000ULL) << 8) | (((uint64)i & 0x0000000000ff0000ULL) << 24) |
|
||||
(((uint64)i & 0x000000000000ff00ULL) << 40) | ((uint64)i << 56);
|
||||
}
|
||||
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
# ifdef WORDS_BIGENDIAN
|
||||
|
||||
#define tw_htonl(x) (x)
|
||||
#define tw_ntohl(x) (x)
|
||||
#define tw_htons(x) (x)
|
||||
#define tw_ntohs(x) (x)
|
||||
#define tw_htonll(x) (x) // int64 versions
|
||||
#define tw_ntohll(x) (x)
|
||||
# define tw_htonl(x) (x)
|
||||
# define tw_ntohl(x) (x)
|
||||
# define tw_htons(x) (x)
|
||||
# define tw_ntohs(x) (x)
|
||||
# define tw_htonll(x) (x) // int64 versions
|
||||
# define tw_ntohll(x) (x)
|
||||
|
||||
#else //!WORDS_BIGENDIAN
|
||||
# else //!WORDS_BIGENDIAN
|
||||
|
||||
#define tw_htonl(x) SWAPBYTES32((x))
|
||||
#define tw_ntohl(x) SWAPBYTES32((x))
|
||||
#define tw_htons(x) SWAPBYTES16((x))
|
||||
#define tw_ntohs(x) SWAPBYTES16((x))
|
||||
#define tw_htonll(x) SWAPBYTES64((x)) // int64 versions
|
||||
#define tw_ntohll(x) SWAPBYTES64((x))
|
||||
# define tw_htonl(x) SWAPBYTES32((x))
|
||||
# define tw_ntohl(x) SWAPBYTES32((x))
|
||||
# define tw_htons(x) SWAPBYTES16((x))
|
||||
# define tw_ntohs(x) SWAPBYTES16((x))
|
||||
# define tw_htonll(x) SWAPBYTES64((x)) // int64 versions
|
||||
# define tw_ntohll(x) SWAPBYTES64((x))
|
||||
|
||||
#endif //WORDS_BIGENDIAN
|
||||
# endif //WORDS_BIGENDIAN
|
||||
|
||||
////////////////////////////////////////////
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
# if __cplusplus >= 201103L
|
||||
# define TW_UNIQUE_PTR std::unique_ptr
|
||||
#else
|
||||
# else
|
||||
# define TW_UNIQUE_PTR std::auto_ptr
|
||||
#endif
|
||||
|
||||
|
||||
# endif
|
||||
|
||||
|
||||
#endif // __TYPES_H
|
||||
|
||||
|
|
|
@ -38,27 +38,26 @@
|
|||
#include <errno.h>
|
||||
|
||||
// TODO: JEB: make this look like eFileError
|
||||
eUnix::eUnix( const TCHAR* szFunctionName, const TCHAR* szObjectName, bool fCallGetLastError)
|
||||
: eError( _T(""))
|
||||
eUnix::eUnix(const TCHAR* szFunctionName, const TCHAR* szObjectName, bool fCallGetLastError) : eError(_T(""))
|
||||
{
|
||||
ASSERT( szFunctionName || szObjectName || fCallGetLastError );
|
||||
ASSERT(szFunctionName || szObjectName || fCallGetLastError);
|
||||
//
|
||||
// construct the error message:
|
||||
//
|
||||
// it will be of the form: FuncName() failed for Object: <FormatMessage output>
|
||||
//
|
||||
if( szFunctionName )
|
||||
if (szFunctionName)
|
||||
{
|
||||
mMsg = szFunctionName;
|
||||
mMsg += _T(" failed");
|
||||
|
||||
if( szObjectName )
|
||||
if (szObjectName)
|
||||
{
|
||||
mMsg += _T(" for ");
|
||||
mMsg += szObjectName;
|
||||
}
|
||||
}
|
||||
else if( szObjectName )
|
||||
else if (szObjectName)
|
||||
{
|
||||
mMsg = szObjectName;
|
||||
}
|
||||
|
@ -67,11 +66,11 @@ eUnix::eUnix( const TCHAR* szFunctionName, const TCHAR* szObjectName, bool fCall
|
|||
mMsg = _T("Error");
|
||||
}
|
||||
|
||||
if( fCallGetLastError )
|
||||
if (fCallGetLastError)
|
||||
{
|
||||
TSTRING strErr = strerror(errno);
|
||||
|
||||
if( ! strErr.empty() )
|
||||
if (!strErr.empty())
|
||||
{
|
||||
mMsg += _T(": ");
|
||||
mMsg += strErr;
|
||||
|
|
|
@ -41,18 +41,16 @@
|
|||
#include "error.h"
|
||||
#endif
|
||||
|
||||
TSS_BEGIN_EXCEPTION( eUnix, eError )
|
||||
TSS_BEGIN_EXCEPTION(eUnix, eError)
|
||||
|
||||
eUnix( const TCHAR* functionName, const TCHAR* objectName, bool displayErrorNumber = true );
|
||||
// construct one of these to indicate a unix api failure. both functionName and
|
||||
// objectName can be NULL. This method will construct a string to pass to eError
|
||||
// that contains all of the above information plus whatever errno returns if the dusplayErrorNumber
|
||||
// parameter is true.
|
||||
eUnix(const TCHAR* functionName, const TCHAR* objectName, bool displayErrorNumber = true);
|
||||
// construct one of these to indicate a unix api failure. both functionName and
|
||||
// objectName can be NULL. This method will construct a string to pass to eError
|
||||
// that contains all of the above information plus whatever errno returns if the dusplayErrorNumber
|
||||
// parameter is true.
|
||||
|
||||
|
||||
TSS_END_EXCEPTION()
|
||||
|
||||
|
||||
|
||||
#endif //__unixexcept_H
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -59,7 +59,7 @@ class cUnixFSServices : public iFSServices
|
|||
///////////////////////////////////////////////////////////////
|
||||
// MEMBER FUNCTIONS
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
public:
|
||||
cUnixFSServices();
|
||||
virtual ~cUnixFSServices();
|
||||
|
||||
|
@ -77,22 +77,22 @@ class cUnixFSServices : public iFSServices
|
|||
////////////////////////////////////////
|
||||
// process functions
|
||||
////////////////////////////////////////
|
||||
virtual void Sleep( int nSeconds ) const;
|
||||
virtual void Sleep(int nSeconds) const;
|
||||
// makes the current process sleep for the specified number of seconds
|
||||
|
||||
////////////////////////////////////////
|
||||
// major filesystem functions
|
||||
////////////////////////////////////////
|
||||
virtual void Stat( const TSTRING& strFileName, cFSStatArgs& pStat ) const ;
|
||||
virtual void Stat(const TSTRING& strFileName, cFSStatArgs& pStat) const;
|
||||
// fills out the cFSStatArgs structure with the stat info for the named file
|
||||
|
||||
virtual void GetTempDirName( TSTRING& strName ) const ;
|
||||
virtual void GetTempDirName(TSTRING& strName) const;
|
||||
// makes directory if it doesn't exist already. Dirname will end with a delimiter ( '/' )
|
||||
|
||||
virtual void SetTempDirName(TSTRING& tmpName);
|
||||
// set the default dir name which GetTempDirName will use...
|
||||
|
||||
virtual TSTRING& MakeTempFilename( TSTRING& strName ) const ;
|
||||
virtual TSTRING& MakeTempFilename(TSTRING& strName) const;
|
||||
// create temporary file
|
||||
// strName must have the form ("baseXXXXXX"), where the X's are replaced with
|
||||
// characters to make it a unique file. There must be at least 6 Xs.
|
||||
|
@ -101,39 +101,39 @@ class cUnixFSServices : public iFSServices
|
|||
////////////////////////////////////////
|
||||
// minor filesystem functions
|
||||
////////////////////////////////////////
|
||||
virtual void GetHostID( TSTRING& name ) const;
|
||||
virtual void GetHostID(TSTRING& name) const;
|
||||
|
||||
virtual void GetMachineName( TSTRING& name) const;
|
||||
virtual void GetMachineName(TSTRING& name) const;
|
||||
|
||||
virtual void GetMachineNameFullyQualified( TSTRING& name ) const;
|
||||
virtual void GetMachineNameFullyQualified(TSTRING& name) const;
|
||||
|
||||
virtual bool GetCurrentUserName( TSTRING& tstrName ) const;
|
||||
virtual bool GetCurrentUserName(TSTRING& tstrName) const;
|
||||
|
||||
virtual bool GetIPAddress( uint32& uiIPAddress );
|
||||
virtual bool GetIPAddress(uint32& uiIPAddress);
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// directory specific functions
|
||||
////////////////////////////////////////
|
||||
virtual void ReadDir( const TSTRING& strName, std::vector<TSTRING> &vDirContents, bool bFullPaths = true ) const;
|
||||
virtual void ReadDir(const TSTRING& strName, std::vector<TSTRING>& vDirContents, bool bFullPaths = true) const;
|
||||
// puts the contents of the specified directory, except for . and .., into the supplied vector.
|
||||
virtual void GetCurrentDir( TSTRING& strCurDir ) const;
|
||||
virtual void GetCurrentDir(TSTRING& strCurDir) const;
|
||||
// returns the current working directory
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// file specific functions
|
||||
////////////////////////////////////////
|
||||
virtual bool FileDelete( const TSTRING& name ) const;
|
||||
virtual bool FileDelete(const TSTRING& name) const;
|
||||
|
||||
////////////////////////////////////////
|
||||
// directory and file functions
|
||||
////////////////////////////////////////
|
||||
virtual bool Rename( const TSTRING& strOldName, const TSTRING& strNewName, bool fOverWrite = true ) const;
|
||||
virtual bool Rename(const TSTRING& strOldName, const TSTRING& strNewName, bool fOverWrite = true) const;
|
||||
// rename a file
|
||||
|
||||
virtual bool GetUserName( uid_t user_id, TSTRING& tstrUser ) const;
|
||||
virtual bool GetGroupName( gid_t group_id, TSTRING& tstrGroup ) const;
|
||||
virtual bool GetUserName(uid_t user_id, TSTRING& tstrUser) const;
|
||||
virtual bool GetGroupName(gid_t group_id, TSTRING& tstrGroup) const;
|
||||
|
||||
//Set whether we try to resolve uid/gid to a name, since Linux static binaries can
|
||||
//have trouble (read: segfaulting) with name resolution given the right nsswitch.conf setup.
|
||||
|
@ -143,14 +143,14 @@ class cUnixFSServices : public iFSServices
|
|||
////////////////////////////////////////
|
||||
// miscellaneous utility functions
|
||||
////////////////////////////////////////
|
||||
virtual void ConvertModeToString( uint64 perm, TSTRING& tstrPerm ) const;
|
||||
virtual void ConvertModeToString(uint64 perm, TSTRING& tstrPerm) const;
|
||||
// takes a int64 permission (from stat) and changes it to look like UNIX's 'ls -l' (e.g. drwxrwxrwx)
|
||||
virtual bool FullPath( TSTRING& fullPath, const TSTRING& relPath, const TSTRING& pathRelFrom = _T("") ) const;
|
||||
virtual bool FullPath(TSTRING& fullPath, const TSTRING& relPath, const TSTRING& pathRelFrom = _T("")) const;
|
||||
// converts relPath into a fully qualified path, storing it in FullPath. If this
|
||||
// fails, false is returned. if the path to which relPath is relative is not CWD, put it in pathRelFrom.
|
||||
virtual bool GetExecutableFilename( TSTRING& strFullPath, const TSTRING& strFilename ) const;
|
||||
virtual bool GetExecutableFilename(TSTRING& strFullPath, const TSTRING& strFilename) const;
|
||||
// get the path to the current executable file
|
||||
virtual bool IsRoot( const TSTRING& strPath ) const;
|
||||
virtual bool IsRoot(const TSTRING& strPath) const;
|
||||
// returns true if strPath is all '/'s
|
||||
|
||||
////////////////////////////////////////
|
||||
|
@ -158,11 +158,9 @@ class cUnixFSServices : public iFSServices
|
|||
////////////////////////////////////////
|
||||
virtual TSTRING GetErrString() const;
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
TSTRING mTempPath;
|
||||
bool mResolveNames;
|
||||
};
|
||||
|
||||
#endif //__UNIXFSSERVICES_H
|
||||
|
||||
|
|
|
@ -54,25 +54,26 @@
|
|||
// Argument : CmpFuncT less : Comparison function. Must return as 'std::less'.
|
||||
// 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
|
||||
int nElemsInSet = 0;
|
||||
FwdIterT iCur = first;
|
||||
for (; iCur != last; ++iCur )
|
||||
for (; iCur != last; ++iCur)
|
||||
++nElemsInSet;
|
||||
|
||||
iCur = first;
|
||||
|
||||
while( 0 < nElemsInSet )
|
||||
while (0 < nElemsInSet)
|
||||
{
|
||||
// go to halfway point
|
||||
int iHalfWay = nElemsInSet/2;
|
||||
int iHalfWay = nElemsInSet / 2;
|
||||
FwdIterT iTemp = iCur;
|
||||
for( int j = 0; j < iHalfWay; j++ )
|
||||
for (int j = 0; j < iHalfWay; j++)
|
||||
iTemp++;
|
||||
|
||||
if( less( *iTemp, obj ) )
|
||||
if (less(*iTemp, obj))
|
||||
{
|
||||
// start next search set at next elem with half of the last search set's elements
|
||||
iCur = ++iTemp;
|
||||
|
@ -89,4 +90,3 @@ template< class FwdIterT, class CmpObjT, class CmpFuncT > FwdIterT UpperBound( F
|
|||
}
|
||||
|
||||
#endif // __UPPERBOUND_H
|
||||
|
||||
|
|
|
@ -38,18 +38,15 @@
|
|||
#ifdef TW_OLD_OPENBSD_VARARGS
|
||||
# undef va_start
|
||||
# ifdef __GNUC__
|
||||
# define va_start(ap, last) \
|
||||
((ap) = (va_list)__builtin_next_arg(last))
|
||||
# define va_start(ap, last) ((ap) = (va_list)__builtin_next_arg(last))
|
||||
# else
|
||||
# define va_start(ap, last) \
|
||||
((ap) = (va_list)&(last) + __va_size(last))
|
||||
# define va_start(ap, last) ((ap) = (va_list) & (last) + __va_size(last))
|
||||
# endif
|
||||
#endif // TW_OLD_OPENBSD_VARARGS
|
||||
|
||||
iUserNotify* iUserNotify::mpInstance = 0;
|
||||
|
||||
iUserNotify::iUserNotify(int verboseLevel) :
|
||||
mVerboseLevel(verboseLevel)
|
||||
iUserNotify::iUserNotify(int verboseLevel) : mVerboseLevel(verboseLevel)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -70,33 +67,33 @@ int iUserNotify::GetVerboseLevel() const
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// NotifySilent
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void iUserNotify::NotifySilent( const TCHAR* format, ... )
|
||||
void iUserNotify::NotifySilent(const TCHAR* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
HandleNotify( V_SILENT, format, args );
|
||||
HandleNotify(V_SILENT, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// NotifyNormal
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void iUserNotify::NotifyNormal( const TCHAR* format, ... )
|
||||
void iUserNotify::NotifyNormal(const TCHAR* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
HandleNotify( V_NORMAL, format, args );
|
||||
HandleNotify(V_NORMAL, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// NotifyVerbose
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void iUserNotify::NotifyVerbose( const TCHAR* format, ... )
|
||||
void iUserNotify::NotifyVerbose(const TCHAR* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
HandleNotify( V_VERBOSE, format, args );
|
||||
HandleNotify(V_VERBOSE, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
@ -107,8 +104,6 @@ void iUserNotify::Notify(int verboseLevel, const TCHAR* format, ...)
|
|||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
HandleNotify( verboseLevel, format, args );
|
||||
HandleNotify(verboseLevel, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
static iUserNotify* GetInstance();
|
||||
static void SetInstance(iUserNotify* pInst);
|
||||
|
||||
virtual void Notify(int verboseLevel, const TCHAR* format, ...) ;
|
||||
virtual void Notify(int verboseLevel, const TCHAR* format, ...);
|
||||
// notify the user that an event has occured. The outcome of this operation is
|
||||
// dependant on the type of object that is implementing this interface (for example,
|
||||
// a console application would want an iUserNotify that prints things to stdout)
|
||||
|
@ -73,19 +73,21 @@ public:
|
|||
//
|
||||
// convenience methods for notifying at these three levels...
|
||||
//
|
||||
void NotifySilent ( const TCHAR* format, ... );
|
||||
void NotifyNormal ( const TCHAR* format, ... );
|
||||
void NotifyVerbose ( const TCHAR* format, ... );
|
||||
void NotifySilent(const TCHAR* format, ...);
|
||||
void NotifyNormal(const TCHAR* format, ...);
|
||||
void NotifyVerbose(const TCHAR* format, ...);
|
||||
|
||||
|
||||
iUserNotify(int verboseLevel = 0);
|
||||
virtual ~iUserNotify();
|
||||
|
||||
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
|
||||
// notification desired
|
||||
|
||||
int mVerboseLevel;
|
||||
|
||||
private:
|
||||
static iUserNotify* mpInstance;
|
||||
};
|
||||
|
@ -101,16 +103,16 @@ private:
|
|||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define TW_NOTIFY_SILENT\
|
||||
if( iUserNotify::GetInstance()->GetVerboseLevel() >= iUserNotify::V_SILENT )\
|
||||
#define TW_NOTIFY_SILENT \
|
||||
if (iUserNotify::GetInstance()->GetVerboseLevel() >= iUserNotify::V_SILENT) \
|
||||
iUserNotify::GetInstance()->NotifySilent
|
||||
|
||||
#define TW_NOTIFY_NORMAL\
|
||||
if( iUserNotify::GetInstance()->GetVerboseLevel() >= iUserNotify::V_NORMAL )\
|
||||
#define TW_NOTIFY_NORMAL \
|
||||
if (iUserNotify::GetInstance()->GetVerboseLevel() >= iUserNotify::V_NORMAL) \
|
||||
iUserNotify::GetInstance()->NotifyNormal
|
||||
|
||||
#define TW_NOTIFY_VERBOSE\
|
||||
if( iUserNotify::GetInstance()->GetVerboseLevel() >= iUserNotify::V_VERBOSE )\
|
||||
#define TW_NOTIFY_VERBOSE \
|
||||
if (iUserNotify::GetInstance()->GetVerboseLevel() >= iUserNotify::V_VERBOSE) \
|
||||
iUserNotify::GetInstance()->NotifyVerbose
|
||||
|
||||
//#############################################################################
|
||||
|
@ -129,4 +131,3 @@ inline void iUserNotify::SetInstance(iUserNotify* pInst)
|
|||
|
||||
|
||||
#endif //__USERNOTIFY_H
|
||||
|
||||
|
|
|
@ -36,21 +36,20 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// HandleNotify
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void cUserNotifyStdout::HandleNotify( int level, const TCHAR* format, va_list& args )
|
||||
void cUserNotifyStdout::HandleNotify(int level, const TCHAR* format, va_list& args)
|
||||
{
|
||||
if(GetVerboseLevel() < level)
|
||||
if (GetVerboseLevel() < level)
|
||||
return;
|
||||
|
||||
// all verbose output now goes to stderr
|
||||
if(level < iUserNotify::V_VERBOSE)
|
||||
if (level < iUserNotify::V_VERBOSE)
|
||||
{
|
||||
_vtprintf(format, args);
|
||||
fflush( stdout );
|
||||
fflush(stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
_vftprintf(stderr, format, args);
|
||||
fflush( stderr );
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,11 +43,10 @@
|
|||
class cUserNotifyStdout : public iUserNotify
|
||||
{
|
||||
public:
|
||||
virtual void HandleNotify( int level, const TCHAR* format, va_list& args ) ;
|
||||
virtual void HandleNotify(int level, const TCHAR* format, va_list& args);
|
||||
// formats the string and sends it to stdout
|
||||
// NOTE -- a little tripwire specific hack has been applied that makes all output
|
||||
// at or above iUserNotify::V_VERBOSE go to stderr instead of stdout
|
||||
};
|
||||
|
||||
#endif /* __USERNOTIFYSTDOUT_H */
|
||||
|
||||
|
|
|
@ -167,4 +167,3 @@ void cUserStringMemBased::AddString(int setID, int stringID, TCHAR* string)
|
|||
|
||||
setItr->second->insert(std::pair<int, TCHAR*>(stringID, string));
|
||||
}
|
||||
|
||||
|
|
|
@ -40,16 +40,16 @@
|
|||
#endif
|
||||
|
||||
#ifndef __USERSTRINGMEM_H
|
||||
#define __USERSTRINGMEM_H
|
||||
# define __USERSTRINGMEM_H
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4786) /* disable unwanted C++ /W4 warning */
|
||||
# ifdef _MSC_VER
|
||||
# pragma warning(disable : 4786) /* disable unwanted C++ /W4 warning */
|
||||
/* #pragma warning(default:4786) */ /* use this to reenable, if necessary */
|
||||
#endif /* _MSC_VER */
|
||||
# endif /* _MSC_VER */
|
||||
|
||||
#ifndef __USERSTRING_H
|
||||
#include "userstring.h"
|
||||
#endif
|
||||
# ifndef __USERSTRING_H
|
||||
# include "userstring.h"
|
||||
# endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// class cUserStringMemBased -- A implementation where the various string
|
||||
|
@ -69,11 +69,11 @@ public:
|
|||
~cUserStringMemBased();
|
||||
|
||||
// the abstract interface
|
||||
virtual bool SelectStringSet (int setID);
|
||||
virtual const TCHAR* GetString (int stringID) const;
|
||||
virtual void ClearStringSet (int id);
|
||||
virtual void AddStringSet (int setID, const iUserString::tStringPair* pPairArray);
|
||||
virtual void AddString (int setID, int stringID, TCHAR* string);
|
||||
virtual bool SelectStringSet(int setID);
|
||||
virtual const TCHAR* GetString(int stringID) const;
|
||||
virtual void ClearStringSet(int id);
|
||||
virtual void AddStringSet(int setID, const iUserString::tStringPair* pPairArray);
|
||||
virtual void AddString(int setID, int stringID, TCHAR* string);
|
||||
|
||||
private:
|
||||
typedef std::map<int, TCHAR*> StringSet;
|
||||
|
@ -83,9 +83,8 @@ private:
|
|||
};
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# ifdef _MSC_VER
|
||||
//#pragma warning(default:4786)
|
||||
#endif /* _MSC_VER */
|
||||
# endif /* _MSC_VER */
|
||||
|
||||
#endif // __USERSTRINGMEM_H
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
#include "debug.h"
|
||||
#include <stdexcept> // for stl::out_of_range
|
||||
#ifdef HAVE_MEMORY_H
|
||||
# include <memory.h>
|
||||
#include <memory.h>
|
||||
#endif
|
||||
|
||||
int wchar16len(const WCHAR16* s)
|
||||
|
@ -80,13 +80,15 @@ public:
|
|||
|
||||
~wc16_string_impl(); // call Release() to delete
|
||||
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;
|
||||
|
||||
wc16_string::wc16_string()
|
||||
: mpData(0)
|
||||
wc16_string::wc16_string() : mpData(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -112,42 +114,39 @@ wc16_string::~wc16_string()
|
|||
mpData->Release();
|
||||
}
|
||||
|
||||
void wc16_string::operator = (const wc16_string& rhs)
|
||||
void wc16_string::operator=(const wc16_string& rhs)
|
||||
{
|
||||
if (mpData)
|
||||
mpData->Release();
|
||||
|
||||
mpData = rhs.mpData;
|
||||
|
||||
if( mpData )
|
||||
if (mpData)
|
||||
mpData->AddRef();
|
||||
}
|
||||
|
||||
|
||||
int wc16_string::compare(const wc16_string& rhs) const
|
||||
{
|
||||
if( length() > rhs.length() )
|
||||
if (length() > rhs.length())
|
||||
return 1;
|
||||
else if ( length() < rhs.length() )
|
||||
else if (length() < rhs.length())
|
||||
return -1;
|
||||
else
|
||||
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::length() const
|
||||
wc16_string::size_type wc16_string::length() const
|
||||
{
|
||||
return mpData ? mpData->length : 0;
|
||||
}
|
||||
|
||||
wc16_string::size_type
|
||||
wc16_string::size() const
|
||||
wc16_string::size_type wc16_string::size() const
|
||||
{
|
||||
return mpData ? mpData->length : 0;
|
||||
}
|
||||
|
||||
wc16_string::const_iterator
|
||||
wc16_string::c_str() const
|
||||
wc16_string::const_iterator wc16_string::c_str() const
|
||||
{
|
||||
if (mpData == 0)
|
||||
return &NULL_WCHAR16;
|
||||
|
@ -157,35 +156,24 @@ wc16_string::c_str() const
|
|||
return mpData->pString;
|
||||
}
|
||||
|
||||
wc16_string::const_iterator
|
||||
wc16_string::begin() const
|
||||
wc16_string::const_iterator wc16_string::begin() const
|
||||
{
|
||||
return (const_cast<wc16_string*>(this))->begin();
|
||||
}
|
||||
|
||||
wc16_string::iterator
|
||||
wc16_string::begin()
|
||||
wc16_string::iterator wc16_string::begin()
|
||||
{
|
||||
return mpData ? mpData->pString : &NULL_WCHAR16;
|
||||
}
|
||||
|
||||
wc16_string::const_iterator
|
||||
wc16_string::end() const
|
||||
wc16_string::const_iterator wc16_string::end() const
|
||||
{
|
||||
return
|
||||
const_cast< iterator >(
|
||||
mpData
|
||||
? mpData->pString + mpData->length
|
||||
: &NULL_WCHAR16 );
|
||||
return const_cast<iterator>(mpData ? mpData->pString + mpData->length : &NULL_WCHAR16);
|
||||
}
|
||||
|
||||
wc16_string::iterator
|
||||
wc16_string::end()
|
||||
wc16_string::iterator wc16_string::end()
|
||||
{
|
||||
return
|
||||
mpData
|
||||
? mpData->pString + mpData->length
|
||||
: &NULL_WCHAR16;
|
||||
return mpData ? mpData->pString + mpData->length : &NULL_WCHAR16;
|
||||
}
|
||||
|
||||
wc16_string::const_iterator wc16_string::data() const
|
||||
|
@ -193,7 +181,7 @@ wc16_string::const_iterator wc16_string::data() const
|
|||
return begin();
|
||||
}
|
||||
|
||||
const wc16_string::value_type& wc16_string::operator [] (int i) const
|
||||
const wc16_string::value_type& wc16_string::operator[](int i) const
|
||||
{
|
||||
ASSERT(i >= 0);
|
||||
|
||||
|
@ -206,7 +194,7 @@ const wc16_string::value_type& wc16_string::operator [] (int i) const
|
|||
return mpData->pString[i];
|
||||
}
|
||||
|
||||
wc16_string::value_type& wc16_string::operator [] (int i)
|
||||
wc16_string::value_type& wc16_string::operator[](int i)
|
||||
{
|
||||
ASSERT(i >= 0);
|
||||
|
||||
|
@ -226,20 +214,20 @@ wc16_string::value_type& wc16_string::operator [] (int i)
|
|||
return mpData->pString[i];
|
||||
}
|
||||
|
||||
void wc16_string::resize( size_type nCount )
|
||||
void wc16_string::resize(size_type nCount)
|
||||
{
|
||||
if ( mpData == 0 )
|
||||
if (mpData == 0)
|
||||
{
|
||||
mpData = new wc16_string_impl;
|
||||
}
|
||||
else if ( mpData->refCount > 1 )
|
||||
else if (mpData->refCount > 1)
|
||||
{
|
||||
wc16_string_impl* newImpl = new wc16_string_impl( *mpData );
|
||||
wc16_string_impl* newImpl = new wc16_string_impl(*mpData);
|
||||
mpData->Release();
|
||||
mpData = newImpl;
|
||||
}
|
||||
|
||||
mpData->Resize( nCount );
|
||||
mpData->Resize(nCount);
|
||||
}
|
||||
|
||||
// useful to convert to network byte order
|
||||
|
@ -339,4 +327,3 @@ void wc16_string_impl::CopyString(const wc16_string_impl& rhs)
|
|||
|
||||
memcpy(this->pString, rhs.pString, newlen * sizeof(WCHAR16));
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,6 @@ class wc16_string_impl;
|
|||
class wc16_string
|
||||
{
|
||||
public:
|
||||
|
||||
typedef WCHAR16 value_type;
|
||||
typedef value_type* iterator;
|
||||
typedef const value_type* const_iterator;
|
||||
|
@ -78,13 +77,13 @@ public:
|
|||
|
||||
|
||||
wc16_string();
|
||||
wc16_string( const wc16_string& rhs);
|
||||
wc16_string( const_iterator pStr);
|
||||
wc16_string(const wc16_string& rhs);
|
||||
wc16_string(const_iterator pStr);
|
||||
|
||||
~wc16_string();
|
||||
|
||||
void operator=( const wc16_string& rhs );
|
||||
int compare( const wc16_string& rhs ) const;
|
||||
void operator=(const wc16_string& rhs);
|
||||
int compare(const wc16_string& rhs) const;
|
||||
|
||||
size_type length() const;
|
||||
size_type size() const;
|
||||
|
@ -103,16 +102,14 @@ public:
|
|||
return length() == 0;
|
||||
}
|
||||
|
||||
const value_type& operator[]( int i ) const; // throw std::out_of_range
|
||||
value_type& operator[]( int i ); // throw std::out_of_range
|
||||
const value_type& operator[](int i) const; // throw std::out_of_range
|
||||
value_type& operator[](int i); // throw std::out_of_range
|
||||
|
||||
void resize( size_type );
|
||||
void resize(size_type);
|
||||
void swapbytes(); // useful to convert to network byte order
|
||||
|
||||
private:
|
||||
|
||||
wc16_string_impl* mpData;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
127
src/db/block.h
127
src/db/block.h
|
@ -45,26 +45,43 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// cBlock
|
||||
//-----------------------------------------------------------------------------
|
||||
template <int SIZE>
|
||||
class cBlock
|
||||
template<int SIZE> class cBlock
|
||||
{
|
||||
public:
|
||||
enum { INVALID_NUM = -1 };
|
||||
enum
|
||||
{
|
||||
INVALID_NUM = -1
|
||||
};
|
||||
|
||||
cBlock();
|
||||
|
||||
void SetDirty () { mbDirty = true; }
|
||||
bool IsDirty () const { return mbDirty; }
|
||||
int GetBlockNum () const { return mBlockNum; }
|
||||
int8* GetData() { return mpData; }
|
||||
void SetDirty()
|
||||
{
|
||||
mbDirty = true;
|
||||
}
|
||||
bool IsDirty() const
|
||||
{
|
||||
return mbDirty;
|
||||
}
|
||||
int GetBlockNum() const
|
||||
{
|
||||
return mBlockNum;
|
||||
}
|
||||
int8* GetData()
|
||||
{
|
||||
return mpData;
|
||||
}
|
||||
|
||||
bool AssertValid() const;
|
||||
// this asserts and returns false if the guard bytes have been corrupted
|
||||
bool IsValidAddr(int8* pAddr) const;
|
||||
// returns true if pAddr falls within mpData
|
||||
protected:
|
||||
enum { NUM_GUARD_BLOCKS = 8, // associated with BYTE_ALIGN: see ctor for info
|
||||
GUARD_BLOCK_VAL = 0xAB }; // odd, non-zero value for debugging
|
||||
enum
|
||||
{
|
||||
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
|
||||
uint8 mGuardMin[NUM_GUARD_BLOCKS];
|
||||
|
@ -77,46 +94,38 @@ protected:
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ctor
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <int SIZE>
|
||||
inline cBlock<SIZE>::cBlock()
|
||||
: mbDirty (false),
|
||||
mBlockNum (cBlock::INVALID_NUM)
|
||||
template<int SIZE> inline cBlock<SIZE>::cBlock() : mbDirty(false), mBlockNum(cBlock::INVALID_NUM)
|
||||
{
|
||||
// To prevent misaligned memory access, the size of the data and the
|
||||
// number of guard blocks must be a multiple of the byte alignment
|
||||
// and they both must be at least as large as the byte alignment
|
||||
ASSERT( 0 == ( SIZE % BYTE_ALIGN ) );
|
||||
ASSERT( 0 == ( NUM_GUARD_BLOCKS % BYTE_ALIGN ) );
|
||||
ASSERT( SIZE >= BYTE_ALIGN );
|
||||
ASSERT( NUM_GUARD_BLOCKS >= BYTE_ALIGN );
|
||||
ASSERT(0 == (SIZE % BYTE_ALIGN));
|
||||
ASSERT(0 == (NUM_GUARD_BLOCKS % BYTE_ALIGN));
|
||||
ASSERT(SIZE >= BYTE_ALIGN);
|
||||
ASSERT(NUM_GUARD_BLOCKS >= BYTE_ALIGN);
|
||||
|
||||
// init guard blocks to dummy value
|
||||
for( int i = 0; i < NUM_GUARD_BLOCKS; i++ )
|
||||
for (int i = 0; i < NUM_GUARD_BLOCKS; i++)
|
||||
{
|
||||
mGuardMin[i] = (uint8)GUARD_BLOCK_VAL;
|
||||
mGuardMax[i] = (uint8)GUARD_BLOCK_VAL;
|
||||
}
|
||||
|
||||
// zero out memory
|
||||
memset( mpData, 0, SIZE );
|
||||
memset(mpData, 0, SIZE);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ctor
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <int SIZE>
|
||||
inline bool cBlock<SIZE>::AssertValid() const
|
||||
template<int SIZE> inline bool cBlock<SIZE>::AssertValid() const
|
||||
{
|
||||
// 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(
|
||||
( mGuardMin[i] != (uint8) GUARD_BLOCK_VAL )
|
||||
||
|
||||
( mGuardMax[i] != (uint8) GUARD_BLOCK_VAL )
|
||||
)
|
||||
if ((mGuardMin[i] != (uint8)GUARD_BLOCK_VAL) || (mGuardMax[i] != (uint8)GUARD_BLOCK_VAL))
|
||||
{
|
||||
ASSERT( false );
|
||||
ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -124,30 +133,40 @@ inline bool cBlock<SIZE>::AssertValid() const
|
|||
return true;
|
||||
}
|
||||
|
||||
template <int SIZE>
|
||||
inline bool cBlock<SIZE>::IsValidAddr(int8* pAddr) const
|
||||
template<int SIZE> inline bool cBlock<SIZE>::IsValidAddr(int8* pAddr) const
|
||||
{
|
||||
return ( (pAddr >= &mpData[0]) && (pAddr <= &mpData[SIZE-1]) );
|
||||
return ((pAddr >= &mpData[0]) && (pAddr <= &mpData[SIZE - 1]));
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// cBlockImpl
|
||||
//-----------------------------------------------------------------------------
|
||||
template <int SIZE>
|
||||
class cBlockImpl : public cBlock<SIZE>
|
||||
template<int SIZE> class cBlockImpl : public cBlock<SIZE>
|
||||
{
|
||||
public:
|
||||
enum { INVALID_NUM = -1 };
|
||||
enum
|
||||
{
|
||||
INVALID_NUM = -1
|
||||
};
|
||||
|
||||
cBlockImpl();
|
||||
|
||||
void SetBlockNum ( int blockNum ) { cBlock<SIZE>::mBlockNum = blockNum; }
|
||||
void SetTimestamp( uint32 timestamp ) { mTimestamp = timestamp; }
|
||||
uint32 GetTimestamp() const { return mTimestamp; }
|
||||
void SetBlockNum(int blockNum)
|
||||
{
|
||||
cBlock<SIZE>::mBlockNum = blockNum;
|
||||
}
|
||||
void SetTimestamp(uint32 timestamp)
|
||||
{
|
||||
mTimestamp = timestamp;
|
||||
}
|
||||
uint32 GetTimestamp() const
|
||||
{
|
||||
return mTimestamp;
|
||||
}
|
||||
|
||||
void Write ( cBidirArchive& arch ); //throw( eArchive )
|
||||
void Read ( cBidirArchive& arch, int blockNum = INVALID_NUM ); //throw( eArchive )
|
||||
void Write(cBidirArchive& arch); //throw( eArchive )
|
||||
void Read(cBidirArchive& arch, int blockNum = INVALID_NUM); //throw( eArchive )
|
||||
// if blockNum is INVALID_NUM, then it reads in the current block number
|
||||
protected:
|
||||
uint32 mTimestamp;
|
||||
|
@ -156,24 +175,20 @@ protected:
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ctor
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <int SIZE>
|
||||
inline cBlockImpl<SIZE>::cBlockImpl()
|
||||
: cBlock<SIZE> ( ),
|
||||
mTimestamp (0)
|
||||
template<int SIZE> inline cBlockImpl<SIZE>::cBlockImpl() : cBlock<SIZE>(), mTimestamp(0)
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Write
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <int SIZE>
|
||||
inline void cBlockImpl<SIZE>::Write( cBidirArchive& arch ) //throw( eArchive )
|
||||
template<int SIZE> inline void cBlockImpl<SIZE>::Write(cBidirArchive& arch) //throw( eArchive )
|
||||
{
|
||||
ASSERT( mbDirty );
|
||||
ASSERT( (mBlockNum >= 0) && (((mBlockNum + 1) * SIZE) <= arch.Length()) );
|
||||
ASSERT(mbDirty);
|
||||
ASSERT((mBlockNum >= 0) && (((mBlockNum + 1) * SIZE) <= arch.Length()));
|
||||
|
||||
arch.Seek ( (cBlock<SIZE>::mBlockNum * SIZE), cBidirArchive::BEGINNING );
|
||||
arch.WriteBlob ( cBlock<SIZE>::mpData, SIZE );
|
||||
arch.Seek((cBlock<SIZE>::mBlockNum * SIZE), cBidirArchive::BEGINNING);
|
||||
arch.WriteBlob(cBlock<SIZE>::mpData, SIZE);
|
||||
|
||||
cBlock<SIZE>::mbDirty = false;
|
||||
}
|
||||
|
@ -181,21 +196,19 @@ inline void cBlockImpl<SIZE>::Write( cBidirArchive& arch ) //throw( eArchive )
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Read
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <int SIZE>
|
||||
inline void cBlockImpl<SIZE>::Read( cBidirArchive& arch, int blockNum ) //throw( eArchive )
|
||||
template<int SIZE> inline void cBlockImpl<SIZE>::Read(cBidirArchive& arch, int blockNum) //throw( eArchive )
|
||||
{
|
||||
if( blockNum != INVALID_NUM )
|
||||
if (blockNum != INVALID_NUM)
|
||||
cBlock<SIZE>::mBlockNum = blockNum;
|
||||
|
||||
ASSERT( (mBlockNum >= 0) && (((mBlockNum + 1) * SIZE) <= arch.Length()) );
|
||||
ASSERT((mBlockNum >= 0) && (((mBlockNum + 1) * SIZE) <= arch.Length()));
|
||||
|
||||
// std::cout << "cBlockImpl<SIZE>::Read() mBlockNum = " << mBlockNum << " arch.Length() = " << arch.Length() << std::endl;
|
||||
// std::cout << "cBlockImpl<SIZE>::Read() mBlockNum = " << mBlockNum << " arch.Length() = " << arch.Length() << std::endl;
|
||||
|
||||
arch.Seek ( (cBlock<SIZE>::mBlockNum * SIZE), cBidirArchive::BEGINNING );
|
||||
arch.ReadBlob ( cBlock<SIZE>::mpData, SIZE );
|
||||
arch.Seek((cBlock<SIZE>::mBlockNum * SIZE), cBidirArchive::BEGINNING);
|
||||
arch.ReadBlob(cBlock<SIZE>::mpData, SIZE);
|
||||
|
||||
cBlock<SIZE>::mbDirty = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue