~ubuntu-branches/ubuntu/trusty/virtualbox/trusty-proposed

« back to all changes in this revision

Viewing changes to include/VBox/com/string.h

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2013-03-07 16:38:36 UTC
  • mfrom: (1.1.13) (3.1.20 experimental)
  • Revision ID: package-import@ubuntu.com-20130307163836-p93jpbgx39tp3gb4
Tags: 4.2.8-dfsg-0ubuntu1
* New upstream release. (Closes: #691148)
  - Fixes compatibility with kernel 3.8. (Closes: #700823; LP: #1101867)
* Switch to my @debian.org email address.
* Move package to contrib as virtualbox 4.2 needs a non-free compiler to
  build the BIOS.
* Build-depend on libdevmapper-dev.
* Refresh patches.
  - Drop 36-fix-ftbfs-xserver-112.patch, cve-2012-3221.patch,
    CVE-2013-0420.patch 37-kcompat-3.6.patch and 38-kcompat-3.7.patch.
* Drop all virtualbox-ose transitional packages.
* Drop the virtualbox-fuse package as vdfuse fails to build with
  virtualbox 4.2.
* Update install files and VBox.sh.
* Bump required kbuild version to 0.1.9998svn2577.
* Fix path to VBoxCreateUSBNode.sh in virtualbox.postinst. (Closes: #700479)
* Add an init script to virtuabox-guest-x11 which loads the vboxvideo
  kernel module. The X Server 1.13 doesn't load it anymore. (Closes: #686994)
* Update man pages. (Closes: #680053)
* Add 36-python-multiarch.patch from Rico Tzschichholz to fix detection of
  python in multiarch paths using pkg-config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 */
5
5
 
6
6
/*
7
 
 * Copyright (C) 2006-2011 Oracle Corporation
 
7
 * Copyright (C) 2006-2012 Oracle Corporation
8
8
 *
9
9
 * This file is part of VirtualBox Open Source Edition (OSE), as
10
10
 * available from http://www.virtualbox.org. This file is free software;
165
165
        return *this;
166
166
    }
167
167
 
168
 
    RTMEMEF_NEW_AND_DELETE_OPERATORS();
 
168
#ifdef _MSC_VER
 
169
# if _MSC_VER >= 1400
 
170
    RTMEMEF_NEW_AND_DELETE_OPERATORS();
 
171
# endif
 
172
#else
 
173
    RTMEMEF_NEW_AND_DELETE_OPERATORS();
 
174
#endif
169
175
 
170
176
    /** Case sensitivity selector. */
171
177
    enum CaseSensitivity
279
285
     *
280
286
     *  If the member string is empty, this allocates an empty BSTR in *pstr
281
287
     *  (i.e. makes it point to a new buffer with a null byte).
 
288
     *
 
289
     *  @deprecated Use cloneToEx instead to avoid throwing exceptions.
282
290
     */
283
291
    void cloneTo(BSTR *pstr) const
284
292
    {
293
301
    }
294
302
 
295
303
    /**
 
304
     *  A version of cloneTo that does not throw any out of memory exceptions, but
 
305
     *  returns E_OUTOFMEMORY intead.
 
306
     *  @returns S_OK or E_OUTOFMEMORY.
 
307
     */
 
308
    HRESULT cloneToEx(BSTR *pstr) const
 
309
    {
 
310
        if (!pstr)
 
311
            return S_OK;
 
312
        *pstr = ::SysAllocString((const OLECHAR *)raw());       // raw() returns a pointer to "" if empty
 
313
        return pstr ? S_OK : E_OUTOFMEMORY;
 
314
    }
 
315
 
 
316
    /**
296
317
     *  Intended to assign instances to |BSTR| out parameters from within the
297
318
     *  interface method. Transfers the ownership of the original string to the
298
319
     *  caller and resets the instance to null.
310
331
    void detachTo(BSTR *pbstrDst)
311
332
    {
312
333
        if (m_bstr)
 
334
        {
313
335
            *pbstrDst = m_bstr;
 
336
            m_bstr = NULL;
 
337
        }
314
338
        else
315
339
        {
316
340
            // allocate null BSTR
320
344
                throw std::bad_alloc();
321
345
#endif
322
346
        }
323
 
        m_bstr = NULL;
 
347
    }
 
348
 
 
349
    /**
 
350
     *  A version of detachTo that does not throw exceptions on out-of-memory
 
351
     *  conditions, but instead returns E_OUTOFMEMORY.
 
352
     *
 
353
     * @param   pbstrDst        The BSTR variable to detach the string to.
 
354
     * @returns S_OK or E_OUTOFMEMORY.
 
355
     */
 
356
    HRESULT detachToEx(BSTR *pbstrDst)
 
357
    {
 
358
        if (m_bstr)
 
359
        {
 
360
            *pbstrDst = m_bstr;
 
361
            m_bstr = NULL;
 
362
        }
 
363
        else
 
364
        {
 
365
            // allocate null BSTR
 
366
            *pbstrDst = ::SysAllocString((const OLECHAR *)g_bstrEmpty);
 
367
            if (!*pbstrDst)
 
368
                return E_OUTOFMEMORY;
 
369
        }
 
370
        return S_OK;
324
371
    }
325
372
 
326
373
    /**
463
510
        copyFrom(that);
464
511
    }
465
512
 
 
513
    Utf8Str(const char *a_pszSrc, size_t a_cchSrc)
 
514
        : RTCString(a_pszSrc, a_cchSrc)
 
515
    {
 
516
    }
 
517
 
466
518
    /**
467
519
     * Constructs a new string given the format string and the list of the
468
520
     * arguments for the format string.
506
558
 
507
559
    bool operator<(const RTCString &that) const { return RTCString::operator<(that); }
508
560
 
 
561
    /**
 
562
     * Extended assignment method that returns a COM status code instead of an
 
563
     * exception on failure.
 
564
     *
 
565
     * @returns S_OK or E_OUTOFMEMORY.
 
566
     * @param   a_rSrcStr   The source string
 
567
     */
 
568
    HRESULT assignEx(Utf8Str const &a_rSrcStr)
 
569
    {
 
570
        return copyFromExNComRC(a_rSrcStr.m_psz, a_rSrcStr.m_cch);
 
571
    }
 
572
 
 
573
    /**
 
574
     * Extended assignment method that returns a COM status code instead of an
 
575
     * exception on failure.
 
576
     *
 
577
     * @returns S_OK, E_OUTOFMEMORY or E_INVALIDARG.
 
578
     * @param   a_pcszSrc   The source string
 
579
     * @param   a_offSrc    The character (byte) offset of the substring.
 
580
     * @param   a_cchSrc    The number of characters (bytes) to copy from the source
 
581
     *                      string.
 
582
     */
 
583
    HRESULT assignEx(Utf8Str const &a_rSrcStr, size_t a_offSrc, size_t a_cchSrc)
 
584
    {
 
585
        if (   a_offSrc + a_cchSrc > a_rSrcStr.m_cch
 
586
            || a_offSrc > a_rSrcStr.m_cch)
 
587
            return E_INVALIDARG;
 
588
        return copyFromExNComRC(a_rSrcStr.m_psz, a_rSrcStr.m_cch);
 
589
    }
 
590
 
 
591
    /**
 
592
     * Extended assignment method that returns a COM status code instead of an
 
593
     * exception on failure.
 
594
     *
 
595
     * @returns S_OK or E_OUTOFMEMORY.
 
596
     * @param   a_pcszSrc   The source string
 
597
     */
 
598
    HRESULT assignEx(const char *a_pcszSrc)
 
599
    {
 
600
        return copyFromExNComRC(a_pcszSrc, a_pcszSrc ? strlen(a_pcszSrc) : 0);
 
601
    }
 
602
 
 
603
    /**
 
604
     * Extended assignment method that returns a COM status code instead of an
 
605
     * exception on failure.
 
606
     *
 
607
     * @returns S_OK or E_OUTOFMEMORY.
 
608
     * @param   a_pcszSrc   The source string
 
609
     * @param   a_cchSrc    The number of characters (bytes) to copy from the source
 
610
     *                      string.
 
611
     */
 
612
    HRESULT assignEx(const char *a_pcszSrc, size_t a_cchSrc)
 
613
    {
 
614
        return copyFromExNComRC(a_pcszSrc, a_cchSrc);
 
615
    }
 
616
 
509
617
    RTMEMEF_NEW_AND_DELETE_OPERATORS();
510
618
 
511
619
#if defined(VBOX_WITH_XPCOM)
520
628
     * like char* strings anyway.
521
629
     */
522
630
    void cloneTo(char **pstr) const;
 
631
 
 
632
    /**
 
633
     * A version of cloneTo that does not throw allocation errors but returns
 
634
     * E_OUTOFMEMORY instead.
 
635
     * @returns S_OK or E_OUTOFMEMORY (COM status codes).
 
636
     */
 
637
    HRESULT cloneToEx(char **pstr) const;
523
638
#endif
524
639
 
525
640
    /**
537
652
    }
538
653
 
539
654
    /**
 
655
     * A version of cloneTo that does not throw allocation errors but returns
 
656
     * E_OUTOFMEMORY instead.
 
657
     *
 
658
     * @param   pbstr Where to store a clone of the string.
 
659
     * @returns S_OK or E_OUTOFMEMORY (COM status codes).
 
660
     */
 
661
    HRESULT cloneToEx(BSTR *pbstr) const
 
662
    {
 
663
        if (!pbstr)
 
664
            return S_OK;
 
665
        Bstr bstr(*this);
 
666
        return bstr.detachToEx(pbstr);
 
667
    }
 
668
 
 
669
    /**
 
670
     * Safe assignment from BSTR.
 
671
     *
 
672
     * @param   pbstrSrc    The source string.
 
673
     * @returns S_OK or E_OUTOFMEMORY (COM status codes).
 
674
     */
 
675
    HRESULT cloneEx(CBSTR pbstrSrc)
 
676
    {
 
677
        cleanup();
 
678
        return copyFromEx(pbstrSrc);
 
679
    }
 
680
 
 
681
    /**
540
682
     * Removes a trailing slash from the member string, if present.
541
683
     * Calls RTPathStripTrailingSlash() without having to mess with mutableRaw().
542
684
     */
567
709
protected:
568
710
 
569
711
    void copyFrom(CBSTR a_pbstr);
 
712
    HRESULT copyFromEx(CBSTR a_pbstr);
 
713
    HRESULT copyFromExNComRC(const char *a_pcszSrc, size_t a_cchSrc);
570
714
 
571
715
    friend class Bstr; /* to access our raw_copy() */
572
716
};