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 #ifndef ATLSTL_INCL_H_ATLSTL
00060 # include "atlstl.h"
00061 #endif
00062 #ifndef STLSOFT_INCL_H_STLSOFT_ITERATOR
00063 # include "stlsoft_iterator.h"
00064 #endif
00065 #ifndef STLSOFT_INCL_H_STLSOFT_CONSTRAINTS
00066 # include "stlsoft_constraints.h"
00067 #endif
00068 #ifndef STLSOFT_INCL_H_STLSOFT_AUTO_BUFFER
00069 # include "stlsoft_auto_buffer.h"
00070 #endif
00071 #ifndef STLSOFT_INCL_H_STLSOFT_NEW_ALLOCATOR
00072 # include "stlsoft_new_allocator.h"
00073 #endif
00074 #if defined(__STLSOFT_COMPILER_IS_DMC)
00075 # include "stlsoft_sap_cast.h"
00076 # ifndef STLSOFT_INCL_H_STLSOFT_SAP_CAST
00077 # endif
00078 #endif
00079 #include <wchar.h>
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 #ifndef _ATLSTL_NO_NAMESPACE
00099 # if defined(_STLSOFT_NO_NAMESPACE) || \
00100 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00101
00102 namespace atlstl
00103 {
00104 # else
00105
00106
00107 namespace stlsoft
00108 {
00109
00110 namespace atlstl_project
00111 {
00112
00113 # endif
00114 #endif
00115
00116
00117
00120
00124
00129
00130
00131
00132
00133
00137 class ccombstr_veneer
00138 #ifdef _ATLSTL_CCOMBSTR_VENEER_INHERIT_AS_PUBLIC
00139 : public CComBSTR
00140 #else
00141 : private CComBSTR
00142 #endif
00143 {
00144 private:
00145 typedef CComBSTR parent_class_type;
00146 typedef ccombstr_veneer class_type;
00147 public:
00149 typedef OLECHAR value_type;
00151 typedef LPOLESTR iterator;
00153 typedef LPCOLESTR const_iterator;
00155 typedef LPOLESTR pointer;
00157 typedef LPCOLESTR const_pointer;
00159 typedef OLECHAR &reference;
00161 typedef OLECHAR const &const_reference;
00163 typedef as_size_t size_type;
00164
00165
00166 public:
00168 ccombstr_veneer();
00170 ccombstr_veneer(class_type const &rhs);
00172 ss_explicit_k ccombstr_veneer(CComBSTR const &rhs);
00174 ss_explicit_k ccombstr_veneer(LPCSTR s);
00176 ss_explicit_k ccombstr_veneer(LPCWSTR s);
00178 ccombstr_veneer(LPCOLESTR from, LPCOLESTR to);
00180 ccombstr_veneer(size_type length, LPCOLESTR from);
00182 ccombstr_veneer(as_size_t cch, OLECHAR ch);
00183
00185 class_type const &operator =(class_type const &rhs);
00187 class_type const &operator =(CComBSTR const &rhs);
00189 class_type const &operator =(LPCSTR s);
00191 class_type const &operator =(LPCWSTR s);
00192
00193
00194 public:
00198 const_iterator begin() const;
00202 const_iterator end() const;
00203
00204
00205 public:
00206 reference operator [](size_type index);
00207 const_reference operator [](size_type index) const;
00208
00209
00210 public:
00211 void swap(class_type &rhs);
00212
00213
00214 public:
00216 CComBSTR &get_base_type();
00218 CComBSTR const &get_base_type() const;
00220 size_type length() const;
00222 size_type size() const;
00224 as_bool_t empty() const;
00226 const_pointer c_str() const;
00228 const_pointer data() const;
00229 };
00230
00231
00232
00233
00234
00235 #ifndef _ATLSTL_CCOMBSTR_VENEER_INHERIT_AS_PUBLIC
00236 inline as_bool_t operator ==(ccombstr_veneer const &lhs, ccombstr_veneer const &rhs)
00237 {
00238 CComBSTR const &lhs_ = lhs.get_base_type();
00239 CComBSTR const &rhs_ = rhs.get_base_type();
00240
00241 #if (_ATL_VER < 0x0300)
00242 return operator == (ccombstr_veneer(lhs), rhs);
00243 #else
00244 return rhs_ == lhs_;
00245 #endif
00246 }
00247 inline as_bool_t operator ==(LPCSTR lhs, ccombstr_veneer const &rhs)
00248 {
00249 CComBSTR const &rhs_ = rhs.get_base_type();
00250
00251 #if (_ATL_VER < 0x0300)
00252 return operator == (ccombstr_veneer(lhs), rhs);
00253 #else
00254 return rhs_ == lhs;
00255 #endif
00256 }
00257 inline as_bool_t operator ==(ccombstr_veneer const &lhs, LPCSTR rhs)
00258 {
00259 CComBSTR const &lhs_ = lhs.get_base_type();
00260
00261 #if (_ATL_VER < 0x0300)
00262 return operator == (lhs, ccombstr_veneer(rhs));
00263 #else
00264 return lhs_ == rhs;
00265 #endif
00266 }
00267 inline as_bool_t operator ==(LPCWSTR lhs, ccombstr_veneer const &rhs)
00268 {
00269 CComBSTR const &rhs_ = rhs.get_base_type();
00270
00271 return lhs == rhs_;
00272 }
00273 inline as_bool_t operator ==(ccombstr_veneer const &lhs, LPCWSTR rhs)
00274 {
00275 CComBSTR const &lhs_ = lhs.get_base_type();
00276 #if _ATL_VER >= 0x0700
00277
00278 return lhs_ == rhs;
00279 #else
00280
00281 if(NULL == lhs_.m_str)
00282 {
00283 return (NULL == rhs);
00284 }
00285 else if(NULL == rhs)
00286 {
00287 return (NULL == lhs_.m_str);
00288 }
00289 else
00290 {
00291 return 0 == wcscmp(lhs_.m_str, rhs);
00292 }
00293 #endif
00294 }
00295
00296 inline as_bool_t operator !=(ccombstr_veneer const &lhs, ccombstr_veneer const &rhs)
00297 {
00298 return !operator ==(lhs, rhs);
00299 }
00300 inline as_bool_t operator !=(LPCSTR lhs, ccombstr_veneer const &rhs)
00301 {
00302 return !operator ==(lhs, rhs);
00303 }
00304 inline as_bool_t operator !=(ccombstr_veneer const &lhs, LPCSTR rhs)
00305 {
00306 return !operator ==(lhs, rhs);
00307 }
00308 inline as_bool_t operator !=(LPCWSTR lhs, ccombstr_veneer const &rhs)
00309 {
00310 return !operator ==(lhs, rhs);
00311 }
00312 inline as_bool_t operator !=(ccombstr_veneer const &lhs, LPCWSTR rhs)
00313 {
00314 return !operator ==(lhs, rhs);
00315 }
00316 #endif
00317
00318
00319
00320
00321
00322 inline LPCOLESTR c_str_ptr_null(ccombstr_veneer const &str)
00323 {
00324 return str.empty() ? NULL : str.c_str();
00325 }
00326
00327 inline LPCOLESTR c_str_ptr(ccombstr_veneer const &str)
00328 {
00329 return str.c_str();
00330 }
00331
00332 inline as_size_t c_str_len(ccombstr_veneer const &str)
00333 {
00334 return str.length();
00335 }
00336
00337 inline as_size_t c_str_size(ccombstr_veneer const &str)
00338 {
00339 return c_str_len(str) * sizeof(OLECHAR);
00340 }
00341
00342 template<ss_typename_param_k S>
00343 inline S &operator <<(S &s, ccombstr_veneer const &str)
00344 {
00345 s << str.c_str();
00346
00347 return s;
00348 }
00349
00350
00351
00352
00353
00354 #ifdef STLSOFT_UNITTEST
00355
00356 namespace unittest
00357 {
00358 ss_bool_t test_atlstl_ccombstr_veneer(unittest_reporter *r)
00359 {
00360 using stlsoft::unittest::unittest_initialiser;
00361
00362 ss_bool_t bSuccess = true;
00363
00364 unittest_initialiser init(r, "ATLSTL", "ccombstr_veneer", __FILE__);
00365
00366 ccombstr_veneer bs1( "Hello");
00367 ccombstr_veneer bs2(L"Hello");
00368
00369 if(bs1 != L"Hello")
00370 {
00371 r->report("Construction (from ANSI) failed ", __LINE__);
00372 bSuccess = false;
00373 }
00374
00375 if(bs2 != L"Hello")
00376 {
00377
00378
00379 r->report("Construction (from Unicode) failed ", __LINE__);
00380 bSuccess = false;
00381 }
00382
00383
00384
00385 if(bs1 != bs2)
00386 {
00387
00388
00389 r->report("Copy construction failed ", __LINE__);
00390 bSuccess = false;
00391 }
00392
00393 ccombstr_veneer bs3(bs1);
00394
00395 if(bs1 != bs3)
00396 {
00397 r->report("Copy assignment failed ", __LINE__);
00398 bSuccess = false;
00399 }
00400
00401 bs3 = bs1;
00402
00403 if(bs3 != "Hello")
00404 {
00405 r->report("Comparison to LPCSTR failed ", __LINE__);
00406 bSuccess = false;
00407 }
00408
00409 if(bs1 != L"Hello")
00410 {
00411 r->report("Comparison to LPCWSTR failed ", __LINE__);
00412 bSuccess = false;
00413 }
00414
00415 bs3 = "Hello";
00416
00417 if(bs3 != L"Hello")
00418 {
00419 r->report("Assigment to LPCSTR failed ", __LINE__);
00420 bSuccess = false;
00421 }
00422
00423 return bSuccess;
00424 }
00425
00426 unittest_registrar unittest_atlstl_ccombstr_veneer(test_atlstl_ccombstr_veneer);
00427
00428 }
00429
00430 #endif
00431
00432
00433
00434
00435
00436 inline ccombstr_veneer::ccombstr_veneer()
00437 : parent_class_type()
00438 {
00439 stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
00440 }
00441
00442 inline ccombstr_veneer::ccombstr_veneer(class_type const &rhs)
00443 : parent_class_type(rhs)
00444 {
00445 stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
00446 }
00447
00448 inline ccombstr_veneer::ccombstr_veneer(CComBSTR const &rhs)
00449 : parent_class_type(rhs)
00450 {
00451 stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
00452 }
00453
00454 inline ccombstr_veneer::ccombstr_veneer(LPCSTR s)
00455
00456
00457
00458 #if _ATL_VER >= 0x0700
00459 : parent_class_type(s)
00460 #endif
00461 {
00462 #if _ATL_VER < 0x0700
00463 USES_CONVERSION;
00464 *this = A2COLE(s);
00465 #endif
00466
00467 atlstl_assert(s == NULL || length() == strlen(s));
00468
00469 stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
00470 }
00471
00472 inline ccombstr_veneer::ccombstr_veneer(LPCWSTR s)
00473 #if _ATL_VER >= 0x0300
00474 : parent_class_type(s)
00475 #endif
00476 {
00477 #if _ATL_VER < 0x0300
00478 USES_CONVERSION;
00479 *this = s;
00480 #endif
00481
00482 atlstl_assert(s == NULL || length() == wcslen(s));
00483
00484 stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
00485 }
00486
00487 inline ccombstr_veneer::ccombstr_veneer(LPCOLESTR from, LPCOLESTR to)
00488 : parent_class_type(static_cast<int>(to - from), from)
00489 {
00490 stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
00491 }
00492
00493 inline void ccombstr_veneer::swap(ccombstr_veneer::class_type &rhs)
00494 {
00495 BSTR str = rhs.m_str;
00496 rhs.m_str = m_str;
00497 m_str = str;
00498 }
00499
00500 inline ccombstr_veneer::ccombstr_veneer(ccombstr_veneer::size_type length, LPCOLESTR from)
00501 : parent_class_type(static_cast<int>(length), from)
00502 {
00503 stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
00504 }
00505
00506 inline ccombstr_veneer::ccombstr_veneer(as_size_t cch, OLECHAR ch)
00507 {
00508 stlsoft_constraint_must_be_same_size(CComBSTR, class_type);
00509
00510 typedef stlsoft_ns_qual(auto_buffer)<OLECHAR, stlsoft_ns_qual(new_allocator)<OLECHAR> > buffer_t;
00511
00512 buffer_t buffer(cch);
00513
00514 _wcsnset(buffer, ch, cch);
00515
00516 class_type(cch, buffer).swap(*this);
00517 }
00518
00519 inline ccombstr_veneer::class_type const &ccombstr_veneer::operator =(ccombstr_veneer::class_type const &rhs)
00520 {
00521 parent_class_type::operator =(rhs);
00522
00523 return *this;
00524 }
00525
00526 inline ccombstr_veneer::class_type const &ccombstr_veneer::operator =(CComBSTR const &rhs)
00527 {
00528 parent_class_type::operator =(rhs);
00529
00530 return *this;
00531 }
00532
00533 inline ccombstr_veneer::class_type const &ccombstr_veneer::operator =(LPCSTR s)
00534 {
00535
00536
00537
00538 #if _ATL_VER >= 0x0700
00539 parent_class_type::operator =(s);
00540 #else
00541 USES_CONVERSION;
00542 *this = A2COLE(s);
00543 #endif
00544
00545 return *this;
00546 }
00547
00548 inline ccombstr_veneer::class_type const &ccombstr_veneer::operator =(LPCWSTR s)
00549 {
00550 parent_class_type::operator =(s);
00551
00552 return *this;
00553 }
00554
00555 inline ccombstr_veneer::const_iterator ccombstr_veneer::begin() const
00556 {
00557 return *this;
00558 }
00559
00560 inline ccombstr_veneer::const_iterator ccombstr_veneer::end() const
00561 {
00562 return begin() + Length();
00563 }
00564
00565 inline ccombstr_veneer::reference ccombstr_veneer::operator [](ccombstr_veneer::size_type index)
00566 {
00567 atlstl_message_assert("Index out of range", index < length());
00568
00569 return const_cast<reference>(data()[index]);
00570 }
00571
00572 inline ccombstr_veneer::const_reference ccombstr_veneer::operator [](ccombstr_veneer::size_type index) const
00573 {
00574 atlstl_message_assert("Index out of range", index < length());
00575
00576 return data()[index];
00577 }
00578
00579 inline CComBSTR &ccombstr_veneer::get_base_type()
00580 {
00581 #if defined(__STLSOFT_COMPILER_IS_DMC)
00582 CComBSTR *this_ = stlsoft_ns_qual(sap_cast)<CComBSTR*>(this);
00583 #else
00584 CComBSTR *this_ = this;
00585 #endif
00586
00587 return *this_;
00588 }
00589
00590 inline CComBSTR const &ccombstr_veneer::get_base_type() const
00591 {
00592 #if defined(__STLSOFT_COMPILER_IS_DMC)
00593 CComBSTR const *this_ = stlsoft_ns_qual(sap_cast)<CComBSTR const*>(this);
00594 #else
00595 CComBSTR const *this_ = this;
00596 #endif
00597
00598 return *this_;
00599 }
00600
00601 inline ccombstr_veneer::size_type ccombstr_veneer::length() const
00602 {
00603 return Length();
00604 }
00605
00606 inline ccombstr_veneer::size_type ccombstr_veneer::size() const
00607 {
00608 return length();
00609 }
00610
00611 inline as_bool_t ccombstr_veneer::empty() const
00612 {
00613 return length() == 0;
00614 }
00615
00616 inline ccombstr_veneer::const_pointer ccombstr_veneer::c_str() const
00617 {
00618 return *this;
00619 }
00620
00621 inline ccombstr_veneer::const_pointer ccombstr_veneer::data() const
00622 {
00623 return *this;
00624 }
00625
00626
00627
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640 #endif
00641
00642
00643
00644
00645
00646