| 259 | |
| 260 | template <class tchar, class tchar_traits> |
| 261 | class TStringT |
| 262 | { |
| 263 | public: |
| 264 | typedef tchar _tchar; |
| 265 | typedef const _tchar * pctstr; |
| 266 | typedef tchar_traits _tchar_traits; |
| 267 | |
| 268 | // Constructors |
| 269 | TStringT() |
| 270 | { |
| 271 | Init(); |
| 272 | } |
| 273 | TStringT(const TStringT& stringSrc) |
| 274 | { |
| 275 | SASSERT(stringSrc.GetData()->nRefs != 0); |
| 276 | if (stringSrc.GetData()->nRefs >= 0) |
| 277 | { |
| 278 | SASSERT(stringSrc.GetData() != _tstr_initDataNil); |
| 279 | m_pszData = stringSrc.m_pszData; |
| 280 | GetData()->AddRef(); |
| 281 | } |
| 282 | else |
| 283 | { |
| 284 | Init(); |
| 285 | *this = stringSrc.m_pszData; |
| 286 | } |
| 287 | } |
| 288 | TStringT(tchar ch, int nLength = 1) |
| 289 | { |
| 290 | Init(); |
| 291 | if (nLength >= 1) |
| 292 | { |
| 293 | if (AllocBuffer(nLength)) |
| 294 | { |
| 295 | for (int i = 0; i < nLength; i++) |
| 296 | m_pszData[i] = ch; |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | TStringT(const tchar* psz, int nLength) |
| 301 | { |
| 302 | Init(); |
| 303 | if (nLength < 0) nLength = SafeStrlen(psz); |
| 304 | if (nLength != 0) |
| 305 | { |
| 306 | if (AllocBuffer(nLength)) |
| 307 | memcpy(m_pszData, psz, nLength * sizeof(tchar)); |
| 308 | } |
| 309 | } |
| 310 | TStringT(const tchar* psz) |
| 311 | { |
| 312 | Init(); |
| 313 | int nLength = SafeStrlen(psz); |
| 314 | if (nLength != 0) |
| 315 | { |
| 316 | if (AllocBuffer(nLength)) |
| 317 | memcpy(m_pszData, psz, nLength * sizeof(tchar)); |
| 318 | } |