📄 mstring.hpp
字号:
referenceCount++;
}
inline void
MStringRepresentation::DecrementReferenceCount()
{
Check_Object(this);
Verify(referenceCount > 0);
if (--referenceCount == 0)
{
Unregister_Object(this);
delete this;
}
}
inline IteratorPosition
MStringRepresentation::GetHashValue()
{
//
// Verify that the IteratorPosition is 32 bits wide
// Hash value is first 16 bits of fileID and first 16 bits of recordID
//
Verify(sizeof(IteratorPosition) == sizeof(DWORD));
static int andAway[3] = {0x000000ff, 0x0000ffff, 0x00ffffff };
IteratorPosition ret = 0;
register i, r, len = stringLength >> 2;
for(i=0;i<len;i++)
{
r = ((int *)stringText)[i];
_asm mov ecx, i
_asm ror r, cl
ret += r;
}
ret += stringLength&0x3 ? ((int *)stringText)[i] & andAway[stringLength&0x3-1] : 0;
return (ret & 0x7fffffff);
}
//##########################################################################
//############################ MString ###############################
//##########################################################################
class MString
#if defined(_ARMOR)
: public Stuff::Signature
#endif
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Construction, Destruction
//
public:
MString();
MString(const MString &str);
MString(const char *cstr);
~MString();
void
TestInstance() const;
static bool
TestClass();
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Length, Size
//
public:
//
// Length returns strlen of string
//
size_t
GetLength() const;
void
SetLength(size_t length);
void
AllocateLength(size_t length);
//
// Size returns memory allocation size
//
size_t
GetSize() const;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Accesors & Manipulation
//
public:
//
// create a c-string from MString method
// HACK - ECH 11/1/95 - Remove const to support 3rd party libs
//
operator char*() const;
//
// assignment method
//
MString&
operator = (const MString &str);
MString&
operator = (const char *cstr);
//
// concatenation methods
//
friend MString
operator + (
const MString &str1,
const MString &str2
);
friend MString
operator + (
const MString & str1,
char ch
);
friend bool
Close_Enough(
const char *str1,
const char *str2,
Scalar e = SMALL
);
void
operator += (const MString &str);
void
operator += (char ch);
//
// comparison methods
//
int
Compare(const MString &str) const;
bool
operator < (const MString &str) const;
bool
operator > (const MString &str) const;
bool
operator <= (const MString &str) const;
bool
operator >= (const MString &str) const;
bool
operator == (const MString &str) const;
bool
operator != (const MString &str) const;
bool
operator == (const char *cstr) const;
//
// character retrieval method
//
char
operator [] (size_t pos) const;
MString
GetNthToken(
size_t nth_token,
char *delimiters=NULL
) const;
//
// case-modification methods
//
void
ToUpper();
void
ToLower();
//
// stream input/output methods
//
#if !defined(Spew)
friend void
::Spew(
const char* group,
const MString &string
);
#endif
friend MemoryStream&
MemoryStreamIO::Read(
MemoryStream* stream,
MString* str
);
friend MemoryStream&
MemoryStreamIO::Write(
MemoryStream* stream,
const MString* str
);
friend void
Convert_From_Ascii(
const char *str,
MString *value
);
IteratorPosition
GetHashValue() const
{ return representation->GetHashValue(); }
friend IteratorPosition
GetHashFunctions::GetHashValue(const MString &value);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Private Data
//
private:
MStringRepresentation
*representation;
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~ MString inlines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// construction, destruction, testing
inline
MString::MString()
{
representation = new MStringRepresentation;
Register_Object(representation);
representation->IncrementReferenceCount();
Verify(representation->referenceCount == 1);
}
inline
MString::MString(const MString &str)
{
Check_Object(&str);
representation = str.representation;
Check_Object(representation);
representation->IncrementReferenceCount();
}
inline
MString::MString(const char *cstr)
{
representation = new MStringRepresentation(cstr);
Register_Object(representation);
representation->IncrementReferenceCount();
Verify(representation->referenceCount == 1);
}
inline
MString::~MString()
{
Check_Object(representation);
representation->DecrementReferenceCount();
}
inline void
MString::TestInstance() const
{
Check_Object(representation);
}
// length, size
inline size_t
MString::GetLength() const
{
Check_Object(representation);
return representation->GetLength();
}
inline void
MString::SetLength(size_t length)
{
Check_Object(representation);
representation->SetLength(length);
}
inline void
MString::AllocateLength(size_t length)
{
Check_Object(representation);
representation->AllocateLength(length);
}
inline size_t
MString::GetSize() const
{
Check_Object(representation);
return representation->GetSize();
}
// create a c-string from MString method
// HACK - ECH 11/1/95 - Remove const to support 3rd party libs
inline
MString::operator char*() const
{
Check_Object(representation);
// Verify(representation->stringText != NULL);
return representation->stringText;
}
// concatenation methods
inline MString
operator + (
const MString &str1,
const MString &str2
)
{
Check_Object(&str1);
Check_Object(&str2);
MStringRepresentation temp = *str1.representation + *str2.representation;
return MString(temp.stringText);
}
inline MString
operator + (
const MString &str1,
char ch
)
{
Check_Object(&str1);
MStringRepresentation temp = *str1.representation + ch;
return MString(temp.stringText);
}
inline void
MString::operator += (const MString &str)
{
Check_Object(this);
Check_Object(&str);
*this = *this + str;
}
inline void
MString::operator += (char ch)
{
Check_Object(this);
*this = *this + ch;
}
// comparison methods
inline int
MString::Compare(const MString &str) const
{
Check_Object(&str);
Check_Object(representation);
return representation->Compare(*str.representation);
}
inline bool
MString::operator < (const MString &str) const
{
return (Compare(str) < 0);
}
inline bool
MString::operator > (const MString &str) const
{
return (Compare(str) > 0);
}
inline bool
MString::operator <= (const MString &str) const
{
return !(Compare(str) > 0);
}
inline bool
MString::operator >= (const MString &str) const
{
return !(Compare(str) < 0);
}
inline bool
MString::operator == (const MString &str) const
{
return (Compare(str) == 0);
}
inline bool
MString::operator != (const MString &str) const
{
return (Compare(str) != 0);
}
inline bool
MString::operator == (const char *cstr) const
{
return (Compare(cstr) == 0);
}
// character retrieval method
inline char
MString::operator[](size_t pos) const
{
Check_Object(representation);
return (*representation)[pos];
}
inline MString
MString::GetNthToken(
size_t nth_token,
char *delimiters
) const
{
Check_Object(representation);
MStringRepresentation temp =
representation->GetNthToken(nth_token, delimiters);
return MString(temp.stringText);
}
}
// stream input/output methods
#if !defined(Spew)
inline void
Spew(
const char* group,
const Stuff::MStringRepresentation &string
)
{
Check_Object(&string);
SPEW((group, string.stringText));
}
inline void
Spew(
const char* group,
const Stuff::MString &string
)
{
Check_Object(&string);
Spew(group, *string.representation);
}
#endif
namespace MemoryStreamIO {
inline Stuff::MemoryStream&
Write(
Stuff::MemoryStream* stream,
const Stuff::MString* str
)
{
return Write(stream, *str->representation);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -