summaryrefslogtreecommitdiff
path: root/open-vm-tools/services/plugins/dndcp/stringxx/ubstr_t.hh
blob: b0498f930c7d61e284df241c524feed80b0efefb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
/*********************************************************
 * Copyright (C) 2008-2015 VMware, Inc. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation version 2.1 and no later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 *
 *********************************************************/

/*
 * ubstr_t.hh --
 *
 *     A string wrapper for _bstr_t.  _bstr_t assumes all char* strings use
 *     the local MBCS encoding, but we want to require that char* strings be
 *     interpreted as UTF-8.
 */

#ifndef _WIN32
#error This file should be built on Windows only.
#endif

#pragma once

#include <algorithm>
#include <comutil.h>
#include <glibmm/refptr.h>

extern "C" {
#include "unicode.h"
#include "util.h"
}


#ifdef I_LOVE_BSTR_T_CLASSIC

typedef _bstr_t ubstr_t;
typedef _variant_t uvariant_t;

#else

class ubstr_t
{
public:
   ubstr_t();
   ubstr_t(const char *s);
   ubstr_t(const wchar_t *s);
   ubstr_t(const _variant_t& var);
   explicit ubstr_t(const _bstr_t& bstr);
   ubstr_t(BSTR bstr, bool copy);
   ubstr_t(const ubstr_t& s);

   ubstr_t& operator=(ubstr_t copy);
   ubstr_t& operator=(const char *s);
   ubstr_t& operator=(const wchar_t *s);
   ubstr_t& operator=(const _variant_t& var);

   // Wrappers around standard _bstr_t methods.
   void Assign(BSTR s);
   BSTR copy(bool copy = true) const;

   void Attach(BSTR s);
   BSTR Detach();

   BSTR *GetAddress();
   BSTR& GetBSTR();

   unsigned int length() const;

   ubstr_t& operator+=(const ubstr_t& s);
   ubstr_t operator+(const ubstr_t& s) const;
   ubstr_t operator+(const char *s) const;
   ubstr_t operator+(const wchar_t *s) const;

   bool operator!() const;
   bool operator==(const ubstr_t& s) const;
   bool operator!=(const ubstr_t& s) const;
   bool operator<(const ubstr_t& s) const;
   bool operator>(const ubstr_t& s) const;
   bool operator<=(const ubstr_t& s) const;
   bool operator>=(const ubstr_t& s) const;

   operator const wchar_t*() const;
   operator wchar_t*() const; // XXX: Get rid of this.
   operator const char*() const;
#ifndef I_HATE_NON_CONST_BSTR_T_CASTS
   operator char*() const; // XXX: Get rid of this.
#endif

   /*
    * _variant_t is implicitly constructible from a _bstr_t.  Since we can't
    * add a constructor to _variant_t, instead provide an implicit conversion
    * from ubstr_t to _variant_t.
    */
   operator _variant_t() const;

   void swap(ubstr_t& s);

private:
   class UTF8Data
   {
   public:
      // Takes ownership of the input string.
      UTF8Data(char *utf8String = NULL) // IN/OUT: May be NULL
         : mUTF8String(utf8String),
           mRefCount(1)
      {
      }

      // For Glib::RefPtr.
      void reference()
      {
         ++mRefCount;
      }

      // For Glib::RefPtr.
      void unreference()
      {
         --mRefCount;
         if (mRefCount == 0) {
            delete this;
         }
      }

      // Takes ownership of the input string.
      void Set(char *utf8String) // IN/OUT: May be NULL.
      {
         Unicode_Free(mUTF8String);
         mUTF8String = utf8String;
      }

      char *Get()
      {
         return mUTF8String;
      }

   private:
      // Only destructible via unreference().
      ~UTF8Data()
      {
         Unicode_Free(mUTF8String);
      }

      char *mUTF8String;
      unsigned int mRefCount;

   private:
      // Intentionally unimplemented.
      UTF8Data(const UTF8Data&);
      UTF8Data& operator=(const UTF8Data&);
   };

   char *GetUTF8Cache() const;
   void InvalidateCache();

   /*
    * Anything that mutates mBstr (all non-const methods) must call
    * InvalidateCache().
    */
   _bstr_t mBstr;

   // mUTF8 is allocated and initialized lazily.
   mutable Glib::RefPtr<UTF8Data> mUTF8;
};


/*
 * _variant_t does string conversions too, so we also need to wrap that.
 * Since _variant_t doesn't keep a cached version of the locally-encoded
 * MBCS string and since we don't use _variant_t nearly as much as _bstr_t,
 * substitutability isn't as much of a concern, so we can use inheritance.
 */
class uvariant_t
   : public _variant_t
{
public:
   /*
    * Wrappers around standard _variant_t constructors.  Unfortunately we
    * have to wrap all the constructors since they aren't inherited.
    */
   uvariant_t() : _variant_t() { }
   uvariant_t(const VARIANT& var) : _variant_t(var) { }
   uvariant_t(const VARIANT *var) : _variant_t(var) { }
   uvariant_t(const _variant_t& var) : _variant_t(var) { }
   uvariant_t(VARIANT& var, bool copy) : _variant_t(var, copy) { }
   uvariant_t(short i, VARTYPE vt = VT_I2) : _variant_t(i, vt) { }
   uvariant_t(long i, VARTYPE vt = VT_I4) : _variant_t(i, vt) { }
   uvariant_t(float f) : _variant_t(f) { }
   uvariant_t(double d, VARTYPE vt = VT_R8) : _variant_t(d, vt) { }
   uvariant_t(const CY& cy) : _variant_t(cy) { }
   uvariant_t(const _bstr_t& s) : _variant_t(s) { }
   uvariant_t(const wchar_t *s) : _variant_t(s) { }
   uvariant_t(IDispatch *dispatch, bool addRef = true) : _variant_t(dispatch, addRef) { }
   uvariant_t(bool b) : _variant_t(b) { }
   uvariant_t(IUnknown *unknown, bool addRef = true) : _variant_t(unknown, addRef) { }
   uvariant_t(const DECIMAL& dec) : _variant_t(dec) { }
   uvariant_t(BYTE i) : _variant_t(i) { }
   uvariant_t(char c) : _variant_t(c) { }
   uvariant_t(unsigned short i) : _variant_t(i) { }
   uvariant_t(unsigned long i) : _variant_t(i) { }
   uvariant_t(int i) : _variant_t(i) { }
   uvariant_t(unsigned int i) : _variant_t(i) { }
#if _WIN32_WINNT >= 0x0501
   uvariant_t(__int64 i) : _variant_t(i) { }
   uvariant_t(unsigned __int64 i) : _variant_t(i) { }
#endif

   // Override the _variant_t constructor that assumes locally-encoded strings.
   uvariant_t(const char *s) : _variant_t(ubstr_t(s)) { }

   // Provide conversion from our ubstr_t wrapper.
   uvariant_t(const ubstr_t& s) : _variant_t(s) { }
};


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::ubstr_t --
 *
 *      ubstr_t constructors.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

inline
ubstr_t::ubstr_t()
   : mBstr(),
     mUTF8()
{
}


inline
ubstr_t::ubstr_t(const char *s) // IN: A UTF-8-encoded string.
   : mBstr(),
     mUTF8()
{
   if (s != NULL) {
      // Since we already have the UTF-8 version of the string, cache it now.
      mUTF8 = Glib::RefPtr<UTF8Data>(new UTF8Data(Util_SafeStrdup(s)));
      utf16_t *utf16Str = Unicode_GetAllocUTF16(s);
      try {
         mBstr = utf16Str;
         Unicode_Free(utf16Str);
      } catch (...) {
         Unicode_Free(utf16Str);
         throw;
      }
   }
}


inline
ubstr_t::ubstr_t(const wchar_t *s) // IN
   : mBstr(s),
     mUTF8()
{
}


inline
ubstr_t::ubstr_t(const _variant_t& var) // IN
   : mBstr(var),
     mUTF8()
{
}


inline
ubstr_t::ubstr_t(const _bstr_t& bstr) // IN
   : mBstr(bstr),
     mUTF8()
{
}


inline
ubstr_t::ubstr_t(BSTR bstr, // IN
                 bool copy) // IN
   : mBstr(bstr, copy),
     mUTF8()
{
}


inline
ubstr_t::ubstr_t(const ubstr_t& s) // IN
   : mBstr(s.mBstr),
     mUTF8(s.mUTF8)
{
   if (static_cast<wchar_t *>(mBstr) != NULL && !mUTF8) {
      mUTF8 = s.mUTF8 = Glib::RefPtr<UTF8Data>(new UTF8Data());
   }
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::operator= --
 *
 *      ubstr_t assignment operators.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

inline ubstr_t&
ubstr_t::operator=(ubstr_t copy) // IN
{
   swap(copy);
   return *this;
}


inline ubstr_t&
ubstr_t::operator=(const char *s) // IN: A UTF-8-encoded string.
{
   return operator=(ubstr_t(s));
}


inline ubstr_t&
ubstr_t::operator=(const wchar_t *s) // IN
{
   return operator=(ubstr_t(s));
}


inline ubstr_t&
ubstr_t::operator=(const _variant_t& var) // IN
{
   return operator=(ubstr_t(var));
}



/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::Assign --
 *
 *      Wrapper around _bstr_t::Assign.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

inline void
ubstr_t::Assign(BSTR s) // IN
{
   InvalidateCache();
   mBstr.Assign(s);
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::copy --
 *
 *      Wrapper around _bstr_t::copy.
 *
 * Results:
 *      A copy of the underlying BSTR.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

inline BSTR
ubstr_t::copy(bool copy) // IN/OPT
   const
{
   return mBstr.copy(copy);
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::Attach --
 *
 *      Wrapper around _bstr_t::Attach.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      Invalidates the UTF-8 cache.
 *
 *-----------------------------------------------------------------------------
 */

inline void
ubstr_t::Attach(BSTR s) // IN
{
   InvalidateCache();
   mBstr.Attach(s);
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::Detach --
 *
 *      Wrapper around _bstr_t::Detach.
 *
 * Results:
 *      The underlying BSTR, which is no longer managed.
 *
 * Side effects:
 *      Invalidates the UTF-8 cache.
 *
 *-----------------------------------------------------------------------------
 */

inline BSTR
ubstr_t::Detach()
{
   InvalidateCache();
   return mBstr.Detach();
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::GetAddress --
 *
 *      Wrapper around _bstr_t::GetAddress.
 *
 * Results:
 *      A pointer to the underlying BSTR.
 *
 * Side effects:
 *      Invalidates the UTF-8 cache.
 *
 *-----------------------------------------------------------------------------
 */

inline BSTR *
ubstr_t::GetAddress()
{
   /*
    * We don't know if the underlying BSTR will be modified via the returned
    * pointer.  We can only assume it will.
    */
   InvalidateCache();
   return mBstr.GetAddress();
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::GetBSTR --
 *
 *      Wrapper around _bstr_t::GetBSTR.
 *
 * Results:
 *      A reference to the underlying BSTR.
 *
 * Side effects:
 *      Invalidates the UTF-8 cache.
 *
 *-----------------------------------------------------------------------------
 */

inline BSTR&
ubstr_t::GetBSTR()
{
   /*
    * We don't know if the underlying BSTR will be modified via the returned
    * reference.  We can only assume it will.
    */
   InvalidateCache();
   return mBstr.GetBSTR();
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::length --
 *
 *      Wrapper around _bstr_t::length.
 *
 * Results:
 *      The length of the string, in TCHARs.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

inline unsigned int
ubstr_t::length()
   const
{
   return mBstr.length();
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::operator+= --
 *
 *      Mutating concatenation operator.
 *
 * Results:
 *      A reference to this ubstr_t object.
 *
 * Side effects:
 *      Invalidates the UTF-8 cache.
 *
 *-----------------------------------------------------------------------------
 */

inline ubstr_t&
ubstr_t::operator+=(const ubstr_t& s) // IN
{
   InvalidateCache();
   mBstr += s.mBstr;
   return *this;
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::operator+ --
 *
 *      Concatenation operators.
 *
 * Results:
 *      A copy of the concatenated string.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

inline ubstr_t
ubstr_t::operator+(const ubstr_t& s) // IN
   const
{
   ubstr_t copy(*this);
   copy += s;
   return copy;
}


inline ubstr_t
ubstr_t::operator+(const char *s) // IN
   const
{
   return operator+(ubstr_t(s));
}


inline ubstr_t
ubstr_t::operator+(const wchar_t *s) // IN
   const
{
   return operator+(ubstr_t(s));
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::operator! --
 *
 *      Wrapper around _bstr_t::operator!.
 *
 * Results:
 *      true if the underlying _bstr_t is NULL, false otherwise.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

inline bool
ubstr_t::operator!()
   const
{
   return !mBstr;
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::operator== --
 * ubstr_t::operator!= --
 * ubstr_t::operator< --
 * ubstr_t::operator> --
 * ubstr_t::operator<= --
 * ubstr_t::operator>= --
 *
 *      Wrappers around _bstr_t's comparison operators.
 *
 * Results:
 *      true if the comparisons are hold, false otherwise.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

inline bool
ubstr_t::operator==(const ubstr_t& s) // IN
   const
{
   return mBstr == s.mBstr;
}


inline bool
ubstr_t::operator!=(const ubstr_t& s) // IN
   const
{
   return mBstr != s.mBstr;
}


inline bool
ubstr_t::operator<(const ubstr_t& s) // IN
   const
{
   return mBstr < s.mBstr;
}


inline bool
ubstr_t::operator>(const ubstr_t& s) // IN
   const
{
   return mBstr > s.mBstr;
}


inline bool
ubstr_t::operator<=(const ubstr_t& s) // IN
   const
{
   return mBstr <= s.mBstr;
}


inline bool
ubstr_t::operator>=(const ubstr_t& s) // IN
   const
{
   return mBstr >= s.mBstr;
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::operator const wchar_t* --
 * ubstr_t::operator wchar_t* --
 *
 *      Wrappers around _bstr_t's cast operators.
 *
 * Results:
 *      A pointer to the underlying UTF-16 string.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

inline
ubstr_t::operator const wchar_t*()
   const
{
   return static_cast<const wchar_t *>(mBstr);
}


inline
ubstr_t::operator wchar_t*()
   const
{
   return static_cast<wchar_t *>(mBstr);
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::operator const char_t* --
 * ubstr_t::operator char_t* --
 *
 *      Cast operators to UTF-8 strings.
 *
 * Results:
 *      A pointer to a UTF-8 string.
 *
 * Side effects:
 *      Might initializes the UTF-8 cache.
 *
 *-----------------------------------------------------------------------------
 */

inline
ubstr_t::operator const char*()
   const
{
   return GetUTF8Cache();
}


#ifndef I_HATE_NON_CONST_BSTR_T_CASTS
inline
ubstr_t::operator char*()
   const
{
   return GetUTF8Cache();
}
#endif


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::operator _variant_t --
 *
 *      Cast operator to _variant_t.
 *
 * Results:
 *      A _variant_t equivalent to this ubstr_t object.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

inline
ubstr_t::operator _variant_t()
   const
{
   return static_cast<const wchar_t *>(mBstr);
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::swap --
 *
 *      Swaps this ubstr_t object with another.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

inline void
ubstr_t::swap(ubstr_t& s) // IN/OUT
{
   std::swap(mBstr, s.mBstr);
   mUTF8.swap(s.mUTF8);
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::GetUTF8Cache --
 *
 *      Retrieves the UTF-8 cache, initializing it if necessary.
 *
 * Results:
 *      The cached UTF-8 string.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

inline char *
ubstr_t::GetUTF8Cache()
   const
{
   if (static_cast<wchar_t *>(mBstr) == NULL) {
      // Nothing to do.
      return NULL;
   }

   char *utf8Str = NULL;
   try {
      if (!mUTF8) {
         mUTF8 = Glib::RefPtr<UTF8Data>(new UTF8Data());
      }

      if (mUTF8->Get() == NULL) {
         utf8Str = Unicode_AllocWithUTF16(static_cast<wchar_t *>(mBstr));
         mUTF8->Set(utf8Str);
      }
   } catch (...) {
      Unicode_Free(utf8Str);
      throw;
   }

   return mUTF8->Get();
}


/*
 *-----------------------------------------------------------------------------
 *
 * ubstr_t::InvalidateCache --
 *
 *      Clears the UTF-8 cache.
 *
 * Results:
 *      None.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

inline void
ubstr_t::InvalidateCache()
{
   mUTF8.clear();
}


/*
 *-----------------------------------------------------------------------------
 *
 * operator+ --
 *
 *      Non-member concatenation operators.
 *
 * Results:
 *      A copy of the concatenated string.
 *
 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */

inline ubstr_t
operator+(const char *s1,    // IN: A UTF-8-encoded sting.
          const ubstr_t& s2) // IN
{
   return ubstr_t(s1) + s2;
}


inline ubstr_t
operator+(const wchar_t *s1, // IN
          const ubstr_t& s2) // IN
{
   return ubstr_t(s1) + s2;
}


/*
 * These are not part of the _bstr_t interface but are provided to catch
 * misuse.  They are intentionally unimplemented to avoid a maintenance
 * burden, and they intentionally return nothing so that accidental usage
 * normally results in compile-time errors instead of link-time ones.
 */

void operator==(const char *s1, const ubstr_t& s2);
void operator!=(const char *s1, const ubstr_t& s2);
void operator<(const char *s1, const ubstr_t& s2);
void operator>(const char *s1, const ubstr_t& s2);
void operator<=(const char *s1, const ubstr_t& s2);
void operator>=(const char *s1, const ubstr_t& s2);

void operator==(const WCHAR *s1, const ubstr_t& s2);
void operator!=(const WCHAR *s1, const ubstr_t& s2);
void operator<(const WCHAR *s1, const ubstr_t& s2);
void operator>(const WCHAR *s1, const ubstr_t& s2);
void operator<=(const WCHAR *s1, const ubstr_t& s2);
void operator>=(const WCHAR *s1, const ubstr_t& s2);


#endif // I_LOVE_BSTR_T_CLASSIC