Merge pull request #73 from Douwanna/release/2.4

Update notes
This commit is contained in:
FrankLee 2020-05-17 23:30:53 +08:00 committed by GitHub
commit 903efb4785
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 235 additions and 45 deletions

View File

@ -26,6 +26,7 @@ namespace tars
{
/**
* @brief Null Pointer Exception
* @brief
*/
struct TC_AutoPtrNull_Exception : public TC_Exception
@ -35,9 +36,11 @@ struct TC_AutoPtrNull_Exception : public TC_Exception
};
/**
* @brief .
*
*
* @brief Smart Pointer Base Class
* @brief
*
* All classes that require smart pointer support need to inherit from this object.
*
*
*/
class UTIL_DLL_API TC_HandleBase
@ -45,7 +48,8 @@ class UTIL_DLL_API TC_HandleBase
public:
/**
* @brief .
* @brief Copy
* @brief
*
* @return TC_HandleBase&
*/
@ -55,12 +59,17 @@ public:
}
/**
* @brief Increase Count
* @brief
*/
void incRef() { ++_atomic; }
/**
* @brief , ==0, ,
* @brief Decrease Count/
*
* ==0, ,
* When 'count==0' and you need to delete data, you can use this to release object.
*
*/
void decRef()
{
@ -72,15 +81,19 @@ public:
}
/**
* @brief Get Count
* @brief .
*
* @return int value of count
* @return int
*/
int getRef() const { return _atomic; }
/**
* @brief .
* @brief Set Automatically-Release Off
* @brief .
*
* @param b Determine whether to be deleted automatically or not, true or false.
* @param b ,true or false
*/
void setNoDelete(bool b) { _bNoDelete = b; }
@ -88,13 +101,15 @@ public:
protected:
/**
* @brief
* @brief Constructor
* @brief
*/
TC_HandleBase() : _atomic(0), _bNoDelete(false)
{
}
/**
* @brief Copy Constructor
* @brief
*/
TC_HandleBase(const TC_HandleBase&) : _atomic(0), _bNoDelete(false)
@ -102,7 +117,8 @@ protected:
}
/**
* @brief
* @brief Destructor
* @brief
*/
virtual ~TC_HandleBase()
{
@ -111,25 +127,32 @@ protected:
protected:
/**
* Count
*
*/
std::atomic<int> _atomic;
/**
* Determine whether to be deleted automatically or not
*
*/
bool _bNoDelete;
};
/**
* @brief Smart Pointer Template Class
* @brief .
*
* This template class an product thread-safe smart pointer which can be placed in a container.
* The smart pointer which is defined by this class can be implemented by reference counting.
* The pointer can be passed in a container.
*
* template<typename T> T MUST BE inherited from TC_HandleBase
*
* ,线.
*
*
*
* .
*
* .
*
* template<typename T> T必须继承于TC_HandleBase
*/
template<typename T>
@ -138,11 +161,13 @@ class TC_AutoPtr
public:
/**
* Element Type
*
*/
typedef T element_type;
/**
* @brief Initialize with native pointer, count +1
* @brief , +1.
*
* @param p
@ -158,6 +183,7 @@ public:
}
/**
* @brief Initialize with the native pointer of other smart pointer r, count +1.
* @brief r的原生指针初始化, +1.
*
* @param Y
@ -175,6 +201,7 @@ public:
}
/**
* @brief Copy constructor, count +1
* @brief , +1.
*
* @param r
@ -190,6 +217,7 @@ public:
}
/**
* @brief Destructor
* @brief
*/
~TC_AutoPtr()
@ -201,6 +229,7 @@ public:
}
/**
* @brief Assignment, normal pointer
* @brief , .
*
* @param p
@ -227,6 +256,7 @@ public:
}
/**
* @brief Assignment, other type of smart pointer
* @brief , .
*
* @param Y
@ -255,6 +285,7 @@ public:
}
/**
* @brief Assignment, other ruling pointer of this type.
* @brief , .
*
* @param r
@ -281,6 +312,7 @@ public:
}
/**
* @brief Replace other types of smart pointers with current types of smart pointers
* @brief .
*
* @param Y
@ -294,6 +326,7 @@ public:
}
/**
* @brief Convert pointers of other native types into smart pointers of the current type
* @brief .
*
* @param Y
@ -307,6 +340,7 @@ public:
}
/**
* @brief Get Native Pointer
* @brief .
*
* @return T*
@ -317,6 +351,7 @@ public:
}
/**
* @brief Transfer
* @brief .
*
* @return T*
@ -332,6 +367,7 @@ public:
}
/**
* @brief Reference
* @brief .
*
* @return T&
@ -347,6 +383,7 @@ public:
}
/**
* @brief To define whether it is effective or not.
* @brief .
*
* @return bool
@ -357,7 +394,8 @@ public:
}
/**
* @brief .
* @brief Swap pointer
* @brief .
*
* @param other
*/
@ -369,6 +407,7 @@ public:
protected:
/**
* @brief Throw Exception
* @brief
*/
void throwNullHandleException() const;
@ -379,6 +418,7 @@ public:
};
/**
* @brief Throw Exception
* @brief .
*
* @param T
@ -392,6 +432,7 @@ TC_AutoPtr<T>::throwNullHandleException() const
}
/**
* @brief Determine '=='.
* @brief ==.
*
* @param T
@ -407,11 +448,13 @@ inline bool operator==(const TC_AutoPtr<T>& lhs, const TC_AutoPtr<U>& rhs)
T* l = lhs.get();
U* r = rhs.get();
// 改为直接比较指针,而不是比较值
// Compare pointers directly instead of comparing values of the two pointers.
// 改为直接比较指针,而不是比较值
return (l == r);
}
/**
* @brief Determine '!='.
* @brief .
*
* @param T
@ -427,11 +470,13 @@ inline bool operator!=(const TC_AutoPtr<T>& lhs, const TC_AutoPtr<U>& rhs)
T* l = lhs.get();
U* r = rhs.get();
// 改为直接比较指针,而不是比较值
// Compare pointers directly instead of comparing values of the two pointers.
// 改为直接比较指针,而不是比较值
return (l != r);
}
/**
* @brief Determine '<', can be used in map and other conrainers.
* @brief , map等容器中.
*
* @param T
@ -448,7 +493,8 @@ inline bool operator<(const TC_AutoPtr<T>& lhs, const TC_AutoPtr<U>& rhs)
U* r = rhs.get();
if(l && r)
{
//return *l < *r;
// return *l < *r;
// Compare pointers directly instead of comparing values of the two pointers.
// 改为直接比较指针,而不是比较值
return (l < r);
}

View File

@ -25,21 +25,30 @@ namespace tars
{
/////////////////////////////////////////////////
/**
* @file tc_base64.h
* @brief base64编解码类.
* @file tc_base64.h
* @brief base64 Codec Class
* @brief base64编解码类.
*/
/////////////////////////////////////////////////
/**
* @brief Base64的编码解码
* @brief This class provides standard base64 encoding and decoding methods.
* @brief base64的编码解码
*/
class TC_Base64
{
public:
/**
* @brief base64编码.
*
* @brief Encode the string by base64
* @brief base64编码.
*
* @param data Data to be encoded
* @param bChangeLine Add line breaks in the final encoded data if necessary,
* (In the RFC, it is recommended to add an 'Enter' after every 76 characters.
* No newline is added by default.)
* @return string the encoded data
*
* @param data
* @param bChangeLine
* (RFC中建议每76个字符后加入回车换行
@ -48,16 +57,28 @@ public:
static string encode(const string &data, bool bChangeLine = false);
/**
* @brief base64解码.
*
* @brief Decode the string by base64
* @brief base64解码.
*
* @param data Data to be decoded
* @return string the decoded data
*
* @param data
* @return string
*/
static string decode(const string &data);
/**
* @brief base64编码.
*
* @brief Encode the string by base64
* @brief base64编码.
*
* @param buffer buffer pointer
* @param length length
* @param bChangeLine Add line breaks in the final encoded data if necessary,
* (In the RFC, it is recommended to add an 'Enter' after every 76 characters.
* No newline is added by default.)
* @return string the encoded data
*
* @param buffer buffer指针
* @param length
* @param bChangeLine
@ -67,7 +88,16 @@ public:
static string encode(const char *buffer, size_t length, bool bChangeLine = false);
/**
* @brief Encode the string by base64
* @brief base64编码 .
*
* @param pSrc the data to be encoded
* @param nSrcLen the length of the data to be encoded
* @param pDst the encoded data
* @param bChangeLine Add line breaks in the final encoded data if necessary,
* (In the RFC, it is recommended to add an 'Enter' after every 76 characters.
* No newline is added by default.)
* @return the length of the encoded string
*
* @param pSrc
* @param nSrcLen
@ -79,8 +109,14 @@ public:
static int encode(const unsigned char* pSrc, size_t nSrcLen, char* pDst, bool bChangeLine = false);
/**
* @brief base64解码.
*
* @brief Decode the string by base64
* @brief base64解码
*
* @param pSrc the data to be decoded
* @param nSrcLe the length of the data to be decoded
* @param pDst the decoded data
* @return the length of the decoded string
*
* @param pSrc
* @param nSrcLe
* @param pDst
@ -91,11 +127,13 @@ public:
protected:
/**
* base64编码表
* base64 Code Table
* base64编码表
*/
static const char EnBase64Tab[];
/**
* base64解码表
* base64 Decode Table
* base64解码表
*/
static const char DeBase64Tab[];
};

View File

@ -29,10 +29,12 @@ namespace tars
/////////////////////////////////////////////////
/**
* @file tc_bitmap.h
* @brief Multi-bit Bitmap Class
* @brief bitmap类.
*/
/////////////////////////////////////////////////
/**
* @brief Exception
* @brief
*/
struct TC_BitMap_Exception : public TC_Exception
@ -43,18 +45,25 @@ struct TC_BitMap_Exception : public TC_Exception
/**
* @brief bitmap1.
* @brief Memory bitmap, 1 bit for each integer, can support multiple bits,
* that is, several bits for several integers.
* @brief bitmap1.
*
* .
* The process of the operation will not be locked.
* If it needs to be locked when called outside, the group lock strategy is usually adopted.
* .
*
* /8
* Attention that according to the group lock strategy,
* memory block address should be divided by 8,
* and then lock the blocks group by the tail number.
* /8
*/
class TC_BitMap
{
public:
/**
* @brief the bitmap of memories, each integer holds 1 bit
* @brief bitmap1
*
*/
class BitMap
{
@ -66,55 +75,85 @@ public:
#define _clear_bit(n,m) (n&(~_magic_bits[m]))
#define _get_bit(n,m) (n&_magic_bits[m])
/**the Version of Shared Memories*/
/**共享内存版本*/
#define BM_VERSION 1
/**
* @brief Calculate the size of the required memory based on the number of elements.
* @brief
* @param iElementCount, (0)
*
* @param iElementCount The number of elements to be saved (marked start from 0)
* @param iElementCount (0)
*
* @return size_t
*/
static size_t calcMemSize(size_t iElementCount);
/**
* @brief Initialize
* @brief
*
* @param pAddr Absolute address
* @param pAddr
*
* @param iSize size, calculated by (calcMemSize)
* @param iSize , (calcMemSize)
* @return 0: , -1:
*
* @return 0: success, -1: lack of memories
* @return 0: , -1:
*/
void create(void *pAddr, size_t iSize);
/**
* @brief Link to a memory block
* @brief
*
* @param pAddr Address, calculated by (calcMemSize)
* @param pAddr , (calcMemSize)
* @return 0, , -1,, -2:
*
* @return 0:success, -1:wrong version, -2:wrong size
* @return 0:, -1:, -2:
*
*/
int connect(void *pAddr, size_t iSize);
/**
* @brief Whether it have mark or not
* @brief
* @param i
*
* @param i
*
* @return int, >0:marked, =0:no mark, <0:out of range
* @return int, >0:, =0:, <0:
*
*/
int get(size_t i);
/**
* @brief Mark
* @brief
*
* @param i
*
* @return int, >0:marked, =0:no mark, <0:out of range
* @return int, >0:, =0:, <0:
*/
int set(size_t i);
/**
* @brief Clear Marks
* @brief
*
* @param i
*
* @return int, >0:marked, =0:no mark, <0:out of range
* @return int, >0:, =0:, <0:
*/
int clear(size_t i);
/**
* @brief Clear all data
* @brief
*
* @return int
@ -122,6 +161,7 @@ public:
int clear4all();
/**
* @brief Dump to File
* @brief dump到文件
* @param sFile
*
@ -130,104 +170,168 @@ public:
int dump2file(const string &sFile);
/**
* @brief Load from File
* @brief load
*
* @param sFile
*
* @return int
*/
int load5file(const string &sFile);
/**the Head of Shared Memories*/
/**共享内存头部*/
#pragma pack(1)
struct tagBitMapHead
{
char _cVersion; /**版本, 当前版本为1*/
size_t _iMemSize; /**共享内存大小*/
char _cVersion; /**version, the current version is 1*/
/**版本, 当前版本为1*/
size_t _iMemSize; /**the size of the shared memory*/
/**共享内存大小*/
};
#pragma pack()
/**
* @brief
* @brief get the address of the head
* @brief
*
* @return tagBitMapHead* the head of the shared memory
* @return tagBitMapHead*
*/
BitMap::tagBitMapHead *getAddr() const { return _pHead; }
/**
* @brief
* @brief get the size of the memory
* @brief
*
* @return the size of the memory
* @return
*
*/
size_t getMemSize() const { return _pHead->_iMemSize; }
protected:
/**
* the Head of the Shared Memory
*
*/
tagBitMapHead *_pHead;
/**
* pointer of a data block
*
*/
unsigned char * _pData;
};
/**
* @brief Calculate the memory size according to count the number of the elements.
* @brief
*
* @param iElementCount the number of the elements which needs to be saved(marked started from 0)
* @param iElementCount (0)
* @param iBitCount (1) (>=1)
*
* @param iBitCount the max bit value of each element(defualt for 1 bit)(each bit>=1)
* @param iBitCount (1) (>=1)
*
* @return the required size of the memory
* @return
*
*/
static size_t calcMemSize(size_t iElementCount, unsigned iBitCount = 1);
/**
* @brief Initialize
* @brief
*
* @param pAddr Absolute Address
* @param pAddr
*
* @param iSize Size, Calculate by (calcMemSize)
* @param iSize , (calcMemSize)
*
* @return 0: success, -1:lack of memories
* @return 0: , -1:
*
*/
void create(void *pAddr, size_t iSize, unsigned iBitCount = 1);
/**
* @brief Link to Memory Blocks
* @brief
*
* @param pAddr Address, Calculate by (calcMemSize)
* @param pAddr (calcMemSize)
*
* @return 0success, -1wrong version, -2:wrong size
* @return 0, -1, -2:
*
*/
int connect(void *pAddr, size_t iSize, unsigned iBitCount = 1);
/**
* @brief
* @brief Whether it is Marked or not
* @brief
*
* @param i the value of the element
* @param i
* @param iBit
*
* @param iBit bit number
* @param iBit
*
* @return int, >0:maked, =0:no mark, <0:out of range
* @return int, >0:, =0:, <0:
*
*/
int get(size_t i, unsigned iBit = 1);
/**
* @brief Mark
* @brief
*
* @param i the value of the element
* @param i
* @param iBit
*
* @param iBit bit number
* @param iBit
*
* @return int, >0:marked, =0:no mark, <0:outof range
* @return int, >0:, =0:, <0:
*
*/
int set(size_t i, unsigned iBit = 1);
/**
* @brief Clear a mark
* @brief
*
* @param i the value of the element
* @param i
*
* @param iBit bit number
* @param iBit
*
* @return int, >0:marked, =0:no mark, <0:out of range
* @return int, >0:, =0:, <0:
*/
int clear(size_t i, unsigned iBit = 1);
/**
* @brief Clear all marks
* @brief
*
* @param iBit bit number
* @param iBit
*
* @return int
*/
int clear4all(unsigned iBit = (unsigned)(-1));
/**
* @brief Dump to File
* @brief dump到文件
*
* @param sFile
*
* @return int
@ -235,7 +339,9 @@ public:
int dump2file(const string &sFile);
/**
* @brief Load from File
* @brief load
*
* @param sFile
*
* @return int