00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #ifndef MFCSTL_INCL_H_MFCSTL
00070 # include "mfcstl.h"
00071 #endif
00072
00073 #if defined(__STLSOFT_COMPILER_IS_MSVC) && \
00074 _MSC_VER < 1200
00075 # error mfcstl_cstring_veneer.h is not compatible with Visual C++ 5.0 or earlier
00076 #endif
00077
00078 #ifndef STLSOFT_INCL_H_STLSOFT_ITERATOR
00079 # include "stlsoft_iterator.h"
00080 #endif
00081 #ifndef STLSOFT_INCL_H_STLSOFT_CONSTRAINTS
00082 # include "stlsoft_constraints.h"
00083 #endif
00084 #if defined(__STLSOFT_COMPILER_IS_DMC)
00085 # include "stlsoft_sap_cast.h"
00086 # ifndef STLSOFT_INCL_H_STLSOFT_SAP_CAST
00087 # endif
00088 #endif
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 #ifndef _MFCSTL_NO_NAMESPACE
00108 # if defined(_STLSOFT_NO_NAMESPACE) || \
00109 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00110
00111 namespace mfcstl
00112 {
00113 # else
00114
00115
00116 namespace stlsoft
00117 {
00118
00119 namespace mfcstl_project
00120 {
00121
00122 # endif
00123 #endif
00124
00125
00126
00129
00133
00138
00139
00140
00141
00142
00146 class cstring_veneer
00147 #ifdef _MFCSTL_CSTRING_VENEER_INHERIT_AS_PUBLIC
00148 : public CString
00149 #else
00150 : private CString
00151 #endif
00152 {
00153 private:
00154 typedef CString parent_class_type;
00155 typedef cstring_veneer class_type;
00156 public:
00158 typedef TCHAR value_type;
00160 typedef LPTSTR iterator;
00162 typedef LPCTSTR const_iterator;
00164 typedef LPTSTR pointer;
00166 typedef LPCTSTR const_pointer;
00168 typedef TCHAR &reference;
00170 typedef TCHAR const &const_reference;
00172 typedef ms_size_t size_type;
00173
00174
00175 public:
00177 cstring_veneer();
00179 cstring_veneer(class_type const &rhs);
00181 ss_explicit_k cstring_veneer(CString const &rhs);
00183 ss_explicit_k cstring_veneer(LPCSTR s);
00185 ss_explicit_k cstring_veneer(LPCWSTR s);
00187 ss_explicit_k cstring_veneer(unsigned char const *s);
00189 cstring_veneer(LPCTSTR from, LPCTSTR to);
00191 cstring_veneer(LPCTSTR from, size_type length);
00193 cstring_veneer(ms_size_t cch, TCHAR ch);
00194
00196 class_type const &operator =(class_type const &rhs);
00198 class_type const &operator =(CString const &rhs);
00200 class_type const &operator =(LPCSTR s);
00202 class_type const &operator =(LPCWSTR s);
00204 class_type const &operator =(unsigned char const *s);
00205
00206
00207 public:
00211 const_iterator begin() const;
00215 const_iterator end() const;
00216
00217
00218 public:
00219 reference operator [](size_type index);
00220 const_reference operator [](size_type index) const;
00221
00222
00223 public:
00225 CString &get_base_type();
00227 CString const &get_base_type() const;
00229 size_type length() const;
00231 size_type size() const;
00233 ms_bool_t empty() const;
00235 const_pointer c_str() const;
00237 const_pointer data() const;
00238 };
00239
00240
00241
00242
00243
00244 #ifndef _MFCSTL_CSTRING_VENEER_INHERIT_AS_PUBLIC
00245 inline ms_bool_t operator ==(cstring_veneer const &lhs, cstring_veneer const &rhs)
00246 {
00247 CString const &lhs_ = lhs.get_base_type();
00248 CString const &rhs_ = rhs.get_base_type();
00249
00250 return lhs_ == rhs_;
00251 }
00252 inline ms_bool_t operator ==(LPCSTR lhs, cstring_veneer const &rhs)
00253 {
00254 CString const &rhs_ = rhs.get_base_type();
00255
00256 return rhs_ == lhs;
00257 }
00258 inline ms_bool_t operator ==(cstring_veneer const &lhs, LPCSTR rhs)
00259 {
00260 CString const &lhs_ = lhs.get_base_type();
00261
00262 return lhs_ == rhs;
00263 }
00264 inline ms_bool_t operator ==(LPCWSTR lhs, cstring_veneer const &rhs)
00265 {
00266 CString const &rhs_ = rhs.get_base_type();
00267
00268 #if defined(__STLSOFT_COMPILER_IS_BORLAND) || \
00269 ( defined(__STLSOFT_COMPILER_IS_DMC) && \
00270 __DMC__ < 0x0835)
00271 return CString(lhs) == rhs_;
00272 #else
00273 return lhs == rhs_;
00274 #endif
00275 }
00276 inline ms_bool_t operator ==(cstring_veneer const &lhs, LPCWSTR rhs)
00277 {
00278 CString const &lhs_ = lhs.get_base_type();
00279
00280 #if defined(__STLSOFT_COMPILER_IS_BORLAND) || \
00281 ( defined(__STLSOFT_COMPILER_IS_DMC) && \
00282 __DMC__ < 0x0835)
00283 return lhs_ == CString(rhs);
00284 #else
00285 return lhs_ == rhs;
00286 #endif
00287 }
00288 inline ms_bool_t operator !=(cstring_veneer const &lhs, cstring_veneer const &rhs)
00289 {
00290 return !operator ==(lhs, rhs);
00291 }
00292 inline ms_bool_t operator !=(LPCSTR lhs, cstring_veneer const &rhs)
00293 {
00294 return !operator ==(lhs, rhs);
00295 }
00296 inline ms_bool_t operator !=(cstring_veneer const &lhs, LPCSTR rhs)
00297 {
00298 return !operator ==(lhs, rhs);
00299 }
00300 inline ms_bool_t operator !=(LPCWSTR lhs, cstring_veneer const &rhs)
00301 {
00302 return !operator ==(lhs, rhs);
00303 }
00304 inline ms_bool_t operator !=(cstring_veneer const &lhs, LPCWSTR rhs)
00305 {
00306 return !operator ==(lhs, rhs);
00307 }
00308 #endif
00309
00310
00311
00312
00313
00314 inline LPCTSTR c_str_ptr_null(cstring_veneer const &s)
00315 {
00316 return s.empty() ? NULL : s.c_str();
00317 }
00318
00319 inline LPCTSTR c_str_ptr(cstring_veneer const &s)
00320 {
00321 return s.c_str();
00322 }
00323
00324 inline ms_size_t c_str_len(cstring_veneer const &s)
00325 {
00326 return s.length();
00327 }
00328
00329 inline ms_size_t c_str_size(cstring_veneer const &s)
00330 {
00331 return c_str_len(s) * sizeof(TCHAR);
00332 }
00333
00334 template<ss_typename_param_k S>
00335 inline S &operator <<(S &s, cstring_veneer const &str)
00336 {
00337 s << str.c_str();
00338
00339 return s;
00340 }
00341
00342
00343
00344
00345
00346 #ifdef STLSOFT_UNITTEST
00347
00348 namespace unittest
00349 {
00350 ss_bool_t test_mfcstl_cstring_veneer(unittest_reporter *r)
00351 {
00352 using stlsoft::unittest::unittest_initialiser;
00353
00354 ss_bool_t bSuccess = true;
00355
00356 unittest_initialiser init(r, "MFCSTL", "cstring_veneer", __FILE__);
00357
00358 cstring_veneer cs1("Hello");
00359 cstring_veneer cs2(cs1);
00360
00361 if(cs1 != cs2)
00362 {
00363 r->report("Copy construction failed ", __LINE__);
00364 bSuccess = false;
00365 }
00366
00367 cstring_veneer cs3;
00368
00369 cs3 = cs1;
00370
00371 if(cs1 != cs3)
00372 {
00373 r->report("Copy assignment failed ", __LINE__);
00374 bSuccess = false;
00375 }
00376
00377 if(cs1 != "Hello")
00378 {
00379 r->report("Comparison to LPCSTR failed ", __LINE__);
00380 bSuccess = false;
00381 }
00382
00383 if(cs1 != L"Hello")
00384 {
00385 r->report("Comparison to LPCWSTR failed ", __LINE__);
00386 bSuccess = false;
00387 }
00388
00389 return bSuccess;
00390 }
00391
00392 unittest_registrar unittest_mfcstl_cstring_veneer(test_mfcstl_cstring_veneer);
00393
00394 }
00395
00396 #endif
00397
00398
00399
00400
00401
00402 inline cstring_veneer::cstring_veneer()
00403 : parent_class_type()
00404 {
00405 stlsoft_constraint_must_be_same_size(CString, class_type);
00406 }
00407
00408 inline cstring_veneer::cstring_veneer(class_type const &rhs)
00409 : parent_class_type(rhs.get_base_type())
00410 {
00411 stlsoft_constraint_must_be_same_size(CString, class_type);
00412 }
00413
00414 inline cstring_veneer::cstring_veneer(CString const &rhs)
00415 : parent_class_type(rhs)
00416 {
00417 stlsoft_constraint_must_be_same_size(CString, class_type);
00418 }
00419
00420 inline cstring_veneer::cstring_veneer(LPCSTR s)
00421 : parent_class_type(s)
00422 {
00423 stlsoft_constraint_must_be_same_size(CString, class_type);
00424 }
00425
00426 inline cstring_veneer::cstring_veneer(LPCWSTR s)
00427 : parent_class_type(s)
00428 {
00429 stlsoft_constraint_must_be_same_size(CString, class_type);
00430 }
00431
00432 inline cstring_veneer::cstring_veneer(unsigned char const *s)
00433 : parent_class_type(s)
00434 {
00435 stlsoft_constraint_must_be_same_size(CString, class_type);
00436 }
00437
00438 inline cstring_veneer::cstring_veneer(LPCTSTR from, LPCTSTR to)
00439 : parent_class_type(from, static_cast<int>(to - from))
00440 {
00441 stlsoft_constraint_must_be_same_size(CString, class_type);
00442 }
00443
00444 inline cstring_veneer::cstring_veneer(LPCTSTR from, cstring_veneer::size_type length)
00445 : parent_class_type(from, static_cast<int>(length))
00446 {
00447 stlsoft_constraint_must_be_same_size(CString, class_type);
00448 }
00449
00450 inline cstring_veneer::cstring_veneer(ms_size_t cch, TCHAR ch)
00451 : parent_class_type(ch, static_cast<int>(cch))
00452 {
00453 stlsoft_constraint_must_be_same_size(CString, class_type);
00454 }
00455
00456 inline cstring_veneer::class_type const &cstring_veneer::operator =(cstring_veneer::class_type const &rhs)
00457 {
00458 parent_class_type::operator =(rhs.get_base_type());
00459
00460 return *this;
00461 }
00462
00463 inline cstring_veneer::class_type const &cstring_veneer::operator =(CString const &rhs)
00464 {
00465 parent_class_type::operator =(rhs);
00466
00467 return *this;
00468 }
00469
00470 inline cstring_veneer::class_type const &cstring_veneer::operator =(LPCSTR s)
00471 {
00472 parent_class_type::operator =(s);
00473
00474 return *this;
00475 }
00476
00477 inline cstring_veneer::class_type const &cstring_veneer::operator =(LPCWSTR s)
00478 {
00479 parent_class_type::operator =(s);
00480
00481 return *this;
00482 }
00483
00484 inline cstring_veneer::class_type const &cstring_veneer::operator =(unsigned char const *s)
00485 {
00486 parent_class_type::operator =(s);
00487
00488 return *this;
00489 }
00490
00491 inline cstring_veneer::const_iterator cstring_veneer::begin() const
00492 {
00493 return *this;
00494 }
00495
00496 inline cstring_veneer::const_iterator cstring_veneer::end() const
00497 {
00498 return begin() + GetLength();
00499 }
00500
00501 inline cstring_veneer::reference cstring_veneer::operator [](cstring_veneer::size_type index)
00502 {
00503 mfcstl_message_assert("Index out of range", index < length());
00504
00505 return const_cast<reference>(data()[index]);
00506 }
00507
00508 inline cstring_veneer::const_reference cstring_veneer::operator [](cstring_veneer::size_type index) const
00509 {
00510 mfcstl_message_assert("Index out of range", index < length());
00511
00512 return data()[index];
00513 }
00514
00515 inline CString &cstring_veneer::get_base_type()
00516 {
00517 #if defined(__STLSOFT_COMPILER_IS_DMC)
00518 CString *this_ = stlsoft_ns_qual(sap_cast)<CString*>(this);
00519 #else
00520 CString *this_ = this;
00521 #endif
00522
00523 return *this_;
00524 }
00525
00526 inline CString const &cstring_veneer::get_base_type() const
00527 {
00528 #if defined(__STLSOFT_COMPILER_IS_DMC)
00529 CString const *this_ = stlsoft_ns_qual(sap_cast)<CString const*>(this);
00530 #else
00531 CString const *this_ = this;
00532 #endif
00533
00534 return *this_;
00535 }
00536
00537 inline cstring_veneer::size_type cstring_veneer::length() const
00538 {
00539 return GetLength();
00540 }
00541
00542 inline cstring_veneer::size_type cstring_veneer::size() const
00543 {
00544 return length();
00545 }
00546
00547 inline ms_bool_t cstring_veneer::empty() const
00548 {
00549 return length() == 0;
00550 }
00551
00552 inline cstring_veneer::const_pointer cstring_veneer::c_str() const
00553 {
00554 return *this;
00555 }
00556
00557 inline cstring_veneer::const_pointer cstring_veneer::data() const
00558 {
00559 return *this;
00560 }
00561
00562
00563
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576 #endif
00577
00578
00579
00580
00581
00582