init
This commit is contained in:
218
Gateway/srvlib/include/ref_string.hpp
Normal file
218
Gateway/srvlib/include/ref_string.hpp
Normal file
@@ -0,0 +1,218 @@
|
||||
#ifndef _REF_STRING_HPP_
|
||||
#define _REF_STRING_HPP_
|
||||
|
||||
#include "string_ex.h"
|
||||
#include "ref_class.hpp"
|
||||
|
||||
namespace string
|
||||
{
|
||||
template <class TS, typename TC>
|
||||
class CTRefString
|
||||
: public misc::RefObject<TS>
|
||||
{
|
||||
typedef misc::RefObject<TS> Inherited;
|
||||
typedef misc::RefObjectImpl<TS> CRefTS;
|
||||
public:
|
||||
/* <20><><EFBFBD>캯<EFBFBD><ECBAAF><EFBFBD>б<EFBFBD> */
|
||||
CTRefString()
|
||||
: Inherited()
|
||||
{
|
||||
}
|
||||
CTRefString(const size_t len)
|
||||
{
|
||||
this->m_ptr = new CRefTS(len);
|
||||
}
|
||||
CTRefString(const TC* str)
|
||||
{
|
||||
operator = (str);
|
||||
}
|
||||
CTRefString(const TS& str)
|
||||
{
|
||||
this->m_ptr = new CRefTS(str);
|
||||
}
|
||||
CTRefString(const CTRefString<TS, TC>& rStr)
|
||||
{
|
||||
operator = (rStr);
|
||||
}
|
||||
public:
|
||||
/* <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ(const TC*)<29><>
|
||||
ע<>⣺ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ΪNULL<4C><4C><EFBFBD><EFBFBD><EFBFBD>᷵<EFBFBD><E1B7B5>""<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>NULL<4C><4C>
|
||||
*/
|
||||
inline operator const TC* () const
|
||||
{
|
||||
return this->m_ptr ? this->m_ptr->rawStr() : NULL;
|
||||
}
|
||||
/* <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ(const TC*)<29><>
|
||||
ע<>⣺ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ΪNULL<4C><4C><EFBFBD><EFBFBD><EFBFBD>᷵<EFBFBD><E1B7B5>""<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>NULL<4C><4C>
|
||||
*/
|
||||
inline operator TC* ()
|
||||
{
|
||||
return this->m_ptr ? this->m_ptr->rawStr() : NULL;
|
||||
}
|
||||
/* <09><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(const TC*)<29><><EFBFBD>͵<EFBFBD>ֵ */
|
||||
inline void operator = (const TC* data)
|
||||
{
|
||||
CRefTS* newPtr = new CRefTS();
|
||||
*((TS*)newPtr) = data;
|
||||
|
||||
if (this->m_ptr) this->m_ptr->release();
|
||||
|
||||
this->m_ptr = newPtr;
|
||||
}
|
||||
/* <09><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TS<54><53><EFBFBD>͵<EFBFBD>ֵ */
|
||||
inline void operator = (const TS& str)
|
||||
{
|
||||
CRefTS* newPtr = new CRefTS();
|
||||
*((TS*)newPtr) = str;
|
||||
|
||||
if (this->m_ptr) this->m_ptr->release();
|
||||
|
||||
this->m_ptr = newPtr;
|
||||
}
|
||||
/* <09><>(const TC*)<29><><EFBFBD>͵<EFBFBD><CDB5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
inline void operator += (const TC* data)
|
||||
{
|
||||
CRefTS* newPtr = new CRefTS();
|
||||
|
||||
if (this->m_ptr) *((TS*)newPtr) = *this->m_ptr;
|
||||
|
||||
*newPtr += data;
|
||||
|
||||
if (this->m_ptr) this->m_ptr->release();
|
||||
|
||||
this->m_ptr = newPtr;
|
||||
}
|
||||
/* <09><><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
inline void operator += (const TS& str)
|
||||
{
|
||||
CRefTS* newPtr = new CRefTS();
|
||||
|
||||
if (this->m_ptr) *((TS*)newPtr) = *this->m_ptr;
|
||||
|
||||
*newPtr += str;
|
||||
|
||||
if (this->m_ptr) this->m_ptr->release();
|
||||
|
||||
this->m_ptr = newPtr;
|
||||
}
|
||||
/* <20>ж<EFBFBD><D0B6><EFBFBD>(const TC*)<29><><EFBFBD>͵<EFBFBD><CDB5>ַ<EFBFBD><D6B7><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>е<EFBFBD><D0B5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>ССд<D0A1><D0B4> */
|
||||
inline bool operator == (const TC* data) const
|
||||
{
|
||||
return compare(data) == 0;
|
||||
}
|
||||
/* <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>ССд<D0A1><D0B4> */
|
||||
inline bool operator == (const TS& str) const
|
||||
{
|
||||
return compare(str) == 0;
|
||||
}
|
||||
/* <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>ССд<D0A1><D0B4> */
|
||||
inline bool operator == (const CTRefString<TS, TC>& str) const
|
||||
{
|
||||
return compare(str) == 0;
|
||||
}
|
||||
/* <20>ж<EFBFBD><D0B6><EFBFBD>(const TC*)<29><><EFBFBD>͵<EFBFBD><CDB5>ַ<EFBFBD><D6B7><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>е<EFBFBD><D0B5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>ССд<D0A1><D0B4> */
|
||||
inline bool operator != (const TC* data) const
|
||||
{
|
||||
return compare(data) != 0;
|
||||
}
|
||||
/* <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>ССд<D0A1><D0B4> */
|
||||
inline bool operator != (const TS& str) const
|
||||
{
|
||||
return compare(str.m_sStr) != 0;
|
||||
}
|
||||
/* <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>ССд<D0A1><D0B4> */
|
||||
inline bool operator != (const CTRefString<TS, TC>& str) const
|
||||
{
|
||||
return compare(str) != 0;
|
||||
}
|
||||
|
||||
public:
|
||||
/* ȡ<><C8A1><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ָ<EFBFBD><D6B8> */
|
||||
inline const TC* rawStr() const
|
||||
{
|
||||
return this->m_ptr ? this->m_ptr->rawStr() : NULL;
|
||||
}
|
||||
/* ȡ<><C8A1><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ָ<EFBFBD><D6B8> */
|
||||
inline TC* rawStr()
|
||||
{
|
||||
return this->m_ptr ? this->m_ptr->rawStr() : NULL;
|
||||
}
|
||||
/* ȡ<><C8A1><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
inline size_t length() const
|
||||
{
|
||||
return this->m_ptr ? this->m_ptr->length() : 0;
|
||||
}
|
||||
/* <09><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>) */
|
||||
inline void setLength(const size_t len)
|
||||
{
|
||||
misc::RefObjectImpl<TS>* newPtr = new misc::RefObjectImpl<TS>(len);
|
||||
|
||||
if (this->m_ptr) this->m_ptr->release();
|
||||
|
||||
this->m_ptr = newPtr;
|
||||
}
|
||||
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>Ա<EFBFBD> */
|
||||
inline int compare(const TC* data) const
|
||||
{
|
||||
if (!this->m_ptr)
|
||||
return !data ? 0 : -1;
|
||||
|
||||
if (data == this->m_ptr->rawStr())
|
||||
return 0;
|
||||
|
||||
return this->m_ptr->compare(data);
|
||||
}
|
||||
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жԱ<D0B6> */
|
||||
inline int compare(const TS& str) const
|
||||
{
|
||||
if (!this->m_ptr)
|
||||
return str.isEmpty() ? 0 : -1;
|
||||
|
||||
if (this->m_ptr == &str)
|
||||
return 0;
|
||||
|
||||
return this->m_ptr->compare(str);
|
||||
}
|
||||
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жԱ<D0B6> */
|
||||
inline int compare(const CTRefString<TS, TC>& str) const
|
||||
{
|
||||
if (this->m_ptr == str.m_ptr)
|
||||
return 0;
|
||||
|
||||
if (!this->m_ptr) return -1;
|
||||
|
||||
return this->m_ptr->compare(str->raw_ptr());
|
||||
}
|
||||
/* <20><>ʽ<EFBFBD><CABD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD> */
|
||||
inline size_t format(const TC* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
size_t Result = 0;
|
||||
|
||||
va_start(args, fmt);
|
||||
Result = format_args(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return Result;
|
||||
}
|
||||
inline size_t format_args(const TC* fmt, va_list _Args)
|
||||
{
|
||||
size_t Result = 0;
|
||||
|
||||
misc::RefObjectImpl<TS>* newPtr = new misc::RefObjectImpl<TS>();
|
||||
Result = newPtr->format_args(fmt, _Args);
|
||||
|
||||
if (this->m_ptr) this->m_ptr->release();
|
||||
|
||||
this->m_ptr = newPtr;
|
||||
|
||||
return Result;
|
||||
}
|
||||
};
|
||||
|
||||
typedef CTRefString<AnsiString, char> CRefAnsiString;
|
||||
};
|
||||
|
||||
typedef string::CRefAnsiString RefString;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user