VirtualBox

Changeset 95993 in vbox for trunk/include/iprt/nocrt


Ignore:
Timestamp:
Aug 3, 2022 9:25:58 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
152765
Message:

include/iprt/nocrt: More on ostream, limits. Stubbed std::sort. bugref:10261

Location:
trunk/include/iprt/nocrt
Files:
6 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/nocrt/float.h

    r95975 r95993  
    4343#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64) || defined(RT_ARCH_ARM64)
    4444
    45 # define FLT_MAX        (3.40282347E+38F)
    46 # define FLT_MIN        (1.17549435E-38F)
    47 # define FLT_MAX_EXP    (128)
    48 # define FLT_MIN_EXP    (-125)
    49 # define FLT_EPSILON    (1.192092896E-07F)
     45# define FLT_MAX            (3.40282347E+38F)
     46# define FLT_MIN            (1.17549435E-38F)
     47# define FLT_TRUE_MIN       (1.40129846E-45F)
     48# define FLT_MAX_EXP        (128)
     49# define FLT_MIN_EXP        (-125)
     50# define FLT_MAX_10_EXP     (38)
     51# define FLT_MIN_10_EXP     (-37)
     52# define FLT_EPSILON        (1.192092896E-07F)
     53# define FLT_DIG            (6)
     54# define FLT_DECIMAL_DIG    (9)
     55# define FLT_MANT_DIG       (24)
     56# define FLT_HAS_SUBNORM    (1)
    5057
    5158#endif
     
    5663#if defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64) || defined(RT_ARCH_ARM64)
    5764
    58 # define DBL_MAX        (1.7976931348623157E+308)
    59 # define DBL_MIN        (2.2250738585072014E-308)
    60 # define DBL_MAX_EXP    (1024)
    61 # define DBL_MIN_EXP    (-1021)
    62 # define DBL_EPSILON    (2.2204460492503131E-16)
     65# define DBL_MAX            (1.7976931348623157E+308)
     66# define DBL_MIN            (2.2250738585072014E-308)
     67# define DBL_TRUE_MIN       (4.9406564584124654E-324)
     68# define DBL_MAX_EXP        (1024)
     69# define DBL_MIN_EXP        (-1021)
     70# define DBL_MAX_10_EXP     (308)
     71# define DBL_MIN_10_EXP     (-307)
     72# define DBL_EPSILON        (2.2204460492503131E-16)
     73# define DBL_DIG            (15)
     74# define DBL_DECIMAL_DIG    (17)
     75# define DBL_MANT_DIG       (53)
     76# define DBL_HAS_SUBNORM    (1)
    6377
    6478#endif
     
    6781 * long double
    6882 */
    69 #if (defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)) && defined(RT_OS_WINDOWS)
    70 # define LDBL_MAX        DBL_MAX
    71 # define LDBL_MIN        DBL_MIN
    72 # define LDBL_MAX_EXP    DBL_MAX_EXP
    73 # define LDBL_MIN_EXP    DBL_MIN_EXP
    74 # define LDBL_EPSIOLON   DBL_EPSIOLON
     83#if ((defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)) && defined(RT_OS_WINDOWS)) || defined(RT_ARCH_ARM64) /*?*/
     84
     85# define LDBL_MAX           DBL_MAX
     86# define LDBL_MIN           DBL_MIN
     87# define LDBL_TRUE_MIN      DBL_TRUE_MIN
     88# define LDBL_MAX_EXP       DBL_MAX_EXP
     89# define LDBL_MIN_EXP       DBL_MIN_EXP
     90# define LDBL_MAX_10_EXP    DBL_MAX_10_EXP
     91# define LDBL_MIN_10_EXP    DBL_MIN_10_EXP
     92# define LDBL_EPSILON       DBL_EPSILON
     93# define LDBL_DIG           DBL_DIG
     94# define LDBL_DECIMAL_DIG   DBL_DECIMAL_DIG
     95# define LDBL_MANT_DIG      DBL_MANT_DIG
     96# define LDBL_HAS_SUBNORM   DBL_HAS_SUBNORM
     97
     98#elif defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)
     99
     100# define LDBL_MAX           (1.1897314953572317650E+4932L)
     101# define LDBL_MIN           (3.3621031431120935063E-4932L)
     102# define LDBL_TRUE_MIN      (3.6451995318824746025E-4951L)
     103# define LDBL_MAX_EXP       (-16381)
     104# define LDBL_MIN_EXP       (16384)
     105# define LDBL_MAX_10_EXP    (4932)
     106# define LDBL_MIN_10_EXP    (-4931)
     107# define LDBL_EPSILON       (1.0842021724855044340E-19L)
     108# define LDBL_DIG           (18)
     109# define LDBL_DECIMAL_DIG   (21)
     110# define LDBL_MANT_DIG      (64)
     111# define LDBL_HAS_SUBNORM   (1)
     112
    75113#endif
    76114
  • trunk/include/iprt/nocrt/ios

    r95985 r95993  
    5454namespace std
    5555{
    56     typedef RTFOFF streamsize;
     56    typedef ptrdiff_t streamsize;
    5757
    5858    /**
    5959     * I/O stream format flags.
    6060     */
    61     enum rtNoCrtIosFmtFlags
     61    class rtNoCrtIosEnums
    6262    {
    63         /* int: */
    64         dec         = 0x00000001,
    65         oct         = 0x00000002,
    66         hex         = 0x00000004,
    67         basefield   = 0x00000007,
    68         /* float: */
    69         scientific  = 0x00000010,
    70         fixed       = 0x00000020,
    71         floatfield  = 0x00000030,
    72         /* int and float output tweaks: */
    73         showbase    = 0x00000100,
    74         showpoint   = 0x00000200,
    75         showpos     = 0x00000400,
    76         /* bool: */
    77         boolalpha   = 0x00000800,
    78         /* adjustment: */
    79         left        = 0x00001000,
    80         right       = 0x00002000,
    81         internal    = 0x00004000,
    82         adjustfield = 0x00007000,
    83         /* misc: */
    84         skipws      = 0x00010000,
    85         unitbuf     = 0x00020000,
    86         uppercase   = 0x00040000,
     63    public:
     64        enum fmtflags
     65        {
     66            /* int: */
     67            dec         = 0x00000001,
     68            oct         = 0x00000002,
     69            hex         = 0x00000004,
     70            basefield   = 0x00000007,
     71            /* float: */
     72            scientific  = 0x00000010,
     73            fixed       = 0x00000020,
     74            floatfield  = 0x00000030,
     75            /* int and float output tweaks: */
     76            showbase    = 0x00000100,
     77            showpoint   = 0x00000200,
     78            showpos     = 0x00000400,
     79            /* bool: */
     80            boolalpha   = 0x00000800,
     81            /* adjustment: */
     82            left        = 0x00001000,
     83            right       = 0x00002000,
     84            internal    = 0x00004000,
     85            adjustfield = 0x00007000,
     86            /* misc: */
     87            skipws      = 0x00010000,
     88            unitbuf     = 0x00020000,
     89            uppercase   = 0x00040000,
     90        };
     91
     92        enum seekdir
     93        {
     94            beg = 1,
     95            end,
     96            cur,
     97        };
     98
     99        enum openmode
     100        {
     101            app = 1,
     102            binary,
     103            in,
     104            out,
     105            trunc,
     106            ate
     107        };
     108
     109        enum iostate
     110        {
     111            goodbit = 0,
     112            badbit  = 1,
     113            failbit = 2,
     114            eofbit  = 4
     115        };
    87116    };
    88     RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosFmtFlags, int)
    89 
    90     enum rtNoCrtIosSeekDir
    91     {
    92         beg = 1,
    93         end,
    94         cur,
    95     };
    96     RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosSeekDir, int)
    97 
    98     enum rtNoCrtIosOpenMode
    99     {
    100         app = 1,
    101         binary,
    102         in,
    103         out,
    104         trunc,
    105         ate
    106     };
    107     RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosOpenMode, int)
    108 
    109     enum rtNoCrtIosState
    110     {
    111         goodbit = 0,
    112         badbit  = 1,
    113         failbit = 2,
    114         eofbit  = 4
    115     };
    116     RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosState, int)
     117    RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosEnums::fmtflags, int)
     118    RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosEnums::seekdir, int)
     119    RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosEnums::openmode, int)
     120    RTNOCRT_IOS_ENUM_BIT_OPS(rtNoCrtIosEnums::iostate, int)
    117121
    118122
     
    120124     * I/O stream base class.
    121125     */
    122     class ios_base
     126    class ios_base : public rtNoCrtIosEnums
    123127    {
    124128    public:
    125         typedef rtNoCrtIosFmtFlags fmtflags;
    126         typedef rtNoCrtIosSeekDir  seekdir;
    127         typedef rtNoCrtIosOpenMode openmode;
    128         typedef rtNoCrtIosState    iostate;
     129        //typedef rtNoCrtIosFmtFlags fmtflags;
     130        //typedef rtNoCrtIosSeekDir  seekdir;
     131        //typedef rtNoCrtIosOpenMode openmode;
     132        //typedef rtNoCrtIosState    iostate;
    129133
    130134    protected:
     
    222226
    223227    protected:
    224         basic_streambuf()
    225         {
    226         }
    227 
    228         basic_streambuf(const basic_streambuf &a_rSrc)
     228        /** @name Put buffering
     229         * @{ */
     230        char_type   *m_pachPut;     /**< The put buffer pointer. */
     231        std::size_t  m_cchPut;      /**< Put buffer size. */
     232        std::size_t  m_offPutNext;  /**< The current put buffer position (where to write next). */
     233        std::size_t  m_offPutStart; /**< Where the buffered put sequence starts. */
     234
     235        void setp(char_type *a_pachNewBuf, char_type *a_pachNewBufEnd)
     236        {
     237            Assert((uintptr_t)a_pachNewBuf <= (uintptr_t)a_pachNewBufEnd);
     238            m_pachPut     = a_pachNewBuf;
     239            m_cchPut      = static_cast<std::size_t>(a_pachNewBufEnd - a_pachNewBuf);
     240            m_offPutNext  = 0;
     241            m_offPutStart = 0;
     242        }
     243
     244        char_type *pbbase() const RT_NOEXCEPT
     245        {
     246            Assert(m_offPutNext >= m_offPutStart); Assert(m_offPutNext <= m_cchPut); Assert(m_offPutStart <= m_cchPut);
     247            return &m_pachPut[m_offPutStart];
     248        }
     249
     250        char_type *pptr()  const RT_NOEXCEPT
     251        {
     252            Assert(m_offPutNext <= m_cchPut);
     253            return &m_pachPut[m_offPutNext];
     254        }
     255
     256        char_type *epptr()  const RT_NOEXCEPT
     257        {
     258            return &m_pachBuf[m_cchPut];
     259        }
     260
     261        void pbump(int a_cchAdvance)  const RT_NOEXCEPT
     262        {
     263            Assert(m_offPutNext <= m_cchPut);
     264            m_offPutNext      += a_cchAdvance;
     265            Assert(m_offPutNext <= m_cchPut);
     266        }
     267        /** @} */
     268
     269    protected:
     270        basic_streambuf() RT_NOEXCEPT
     271            : m_pachPut(NULL)
     272            , m_cchPut(0)
     273            , m_offPutNext(0)
     274            , m_offPutStart(0)
     275        {
     276        }
     277
     278        basic_streambuf(const basic_streambuf &a_rSrc) RT_NOEXCEPT
     279            : m_pachPut(a_rSrc.m_pachPut)
     280            , m_cchPut(a_rSrc.m_cchPut)
     281            , m_offPutNext(a_rSrc.m_offPutNext)
     282            , m_offPutStart(a_rSrc.m_offPutStart)
    229283        {
    230284        }
     
    246300        basic_streambuf *pubsetbuf(char_type *a_pchBuf, std::streamsize a_cchBuf)
    247301        {
    248             return setbuf(a_off, a_enmDir, a_enmTarget);
     302            return setbuf(a_pchBuf, a_cchBuf);
    249303        }
    250304
     
    253307                                 std::ios_base::openmode a_enmTarget = ios_base::in | ios_base::out)
    254308        {
    255             RT_NOREF(a_off, a_enmDir, out);
     309            RT_NOREF(a_off, a_enmDir, a_enmTarget);
    256310            return pos_type(off_type(-1));
    257311        }
     
    266320        virtual pos_type seekpos(pos_type a_pos, std::ios_base::openmode a_enmTarget = ios_base::in | ios_base::out)
    267321        {
    268             RT_NOREF(a_off, a_enmDir, out);
     322            RT_NOREF(a_pos, a_enmTarget);
    269323            return pos_type(off_type(-1));
    270324        }
     
    287341        /** @} */
    288342
    289         /** @todo add the remainin members... */
     343        /** @name Output
     344         * @{ */
     345    protected:
     346        virtual int_type overflow(int_type a_iChar)
     347        {
     348            RT_NOREF(a_iChar);
     349            return traits_type::eof();
     350        }
     351
     352        virtual std::streamsize xsputn(char_type const *a_pchSrc, std::streamsize a_cchSrc)
     353        {
     354            std::streamsize cchWritten = 0;
     355            while (a_cchSrc > 0)
     356            {
     357                std::size_t cchCopied = m_cchPut - m_offPutNext;
     358                if (cchCopied > 0)
     359                {
     360                    cchCopied = RT_MIN(cchCopied, a_cchSrc);
     361                    traits_type::copy(&m_pachPut[m_offPutNext], a_pchSrc, cchCopied);
     362                    m_cchPut += cchCopied;
     363                }
     364                else
     365                {
     366                    if (overflow(traits_type::to_int_type(m_pachPut[m_offPutNext])) != traits_type::eof())
     367                        cchCopied = 1;
     368                    else
     369                        break;
     370                }
     371                a_pchSrc += cchCopied;
     372                a_cchSrc -= cchCopied;
     373            }
     374            return cchWritten;
     375        }
     376
     377    public:
     378        int_type sputc(char_type a_ch)
     379        {
     380            if (m_offPutNext < m_cchPut)
     381            {
     382                m_pachPut[m_offPutNext++] = a_ch;
     383                return traits_type::to_int_type(a_ch);
     384            }
     385            return overflow(traits_type::to_int_type(a_ch));
     386        }
     387
     388        std::streamsize sputn(char_type const *a_pchSrc, std::streamsize a_cchSrc)
     389        {
     390            AssertReturn(a_cchSrc >= 0, 0);
     391            return xsputn(a_pchSrc, a_cchSrc);
     392        }
     393
     394        /** @} */
     395
     396        /** @todo add the remaining members... */
    290397    };
    291398
     
    306413    protected:
    307414        basic_streambuf<a_CharType, a_CharTraits>  *m_pBuf;
    308 
    309     protected:
    310         void init(const std::basic_streambuf<a_CharType, a_CharTraits> *a_pBuf)
     415        basic_ostream<a_CharType, a_CharTraits>    *m_pTiedStream;
     416
     417    protected:
     418        void init(std::basic_streambuf<a_CharType, a_CharTraits> *a_pBuf)
    311419        {
    312420            m_pBuf         = a_pBuf;
    313421            m_cWidth       = 0;
    314422            m_cPrecision   = 6;
    315             m_fFlags       = ios_base::dec | ios_base::wskip;
     423            m_fFlags       = ios_base::dec | ios_base::skipws;
    316424            m_fState       = ios_base::goodbit;
    317425        }
     
    319427    public:
    320428        basic_ios()
    321             : m_pBuf(NULL)
    322             , ios_base()
    323         {
    324         }
    325 
    326         basic_ios(const std::basic_streambuf<a_CharType, a_CharTraits> *a_pBuf)
    327             : m_pBuf(NULL)
    328             , ios_base()
    329         {
    330             init(a_pBuf)
     429            : ios_base()
     430            , m_pBuf(NULL)
     431            , m_pTiedStream(NULL)
     432        {
     433        }
     434
     435        basic_ios(std::basic_streambuf<a_CharType, a_CharTraits> *a_pBuf)
     436            : ios_base()
     437            , m_pBuf(NULL)
     438            , m_pTiedStream(NULL)
     439        {
     440            init(a_pBuf);
    331441        }
    332442    private:
     
    384494            return pOldBuf;
    385495        }
     496
     497        std::basic_ostream<a_CharType, a_CharTraits> *tie() const
     498        {
     499            return m_pTiedStream;
     500        }
     501
     502        std::basic_ostream<a_CharType, a_CharTraits> tie(std::basic_ostream<a_CharType, a_CharTraits> *a_pNew) const RT_NOEXCEPT
     503        {
     504            std::basic_ostream<a_CharType, a_CharTraits> * const pOld = m_pTiedStream;
     505            m_pTiedStream = a_pNew;
     506            return pOld;
     507        }
    386508        /** @}  */
    387509
  • trunk/include/iprt/nocrt/iosfwd

    r95985 r95993  
    4949    template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > class basic_ostream;
    5050    template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > class basic_iostream;
     51    template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > class basic_ifstream;
     52    template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > class basic_ofstream;
     53    template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> > class basic_fstream;
    5154
    5255
     
    5659    typedef basic_ostream<char>         ostream;
    5760    typedef basic_iostream<char>        iostream;
     61    typedef basic_ifstream<char>        ifstream;
     62    typedef basic_ofstream<char>        ofstream;
     63    typedef basic_fstream<char>         fstream;
    5864}
    5965
  • trunk/include/iprt/nocrt/memory

    r95978 r95993  
    9191        }
    9292    };
     93
     94    /** @todo make_unique and unique   */
    9395}
    9496
  • trunk/include/iprt/nocrt/ostream

    r95985 r95993  
    4141    class basic_ostream : public basic_ios<a_CharType, a_CharTraits>
    4242    {
     43    protected:
     44        /** Sentry class that performs pre and post output work. */
     45        class sentry
     46        {
     47        private:
     48            basic_ostream &m_rParent;
     49
     50        public:
     51            explicit sentry(basic_ostream &a_rParent)
     52                : m_rParent(a_rParent)
     53            {
     54                if (a_rParent.good())
     55                {
     56                    basic_ostream *pTiedStream = a_rParent.tie();
     57                    if (!pTiedStream)
     58                    { /* likely? */ }
     59                    else
     60                    {
     61                        pTiedStream->flush();
     62                        if (!pTiedStream->good())
     63                            a_rParent.setstate(failbit);
     64                    }
     65                }
     66            }
     67
     68            explicit operator bool() const
     69            {
     70                return m_rParent.good();
     71            }
     72
     73            ~sentry()
     74            {
     75                if (   (m_rParent.flags() & std::ios_base::unitbuf)
     76                    && m_rParent.good())
     77                    m_rParent.rdbuf()->pubsync();
     78            }
     79        };
     80
    4381    public:
    4482        explicit basic_ostream(std::basic_streambuf<a_CharType,a_CharTraits> *a_pBuf)
     
    5593
    5694    public:
    57         basic_ostream &put(char_type a_ch);
    58         basic_ostream &write(const char_type *a_pchSrc, std::streamsize a_cchToWrite);
     95        basic_ostream &put(char_type a_ch)
     96        {
     97            sentry PrePost(*this);
     98            if (PrePost)
     99            {
     100                if (m_pBuf->sputc(a_ch) == traits_type::eof())
     101                    m_fState |= badbit;
     102            }
     103            return *this;
     104        }
     105
     106        basic_ostream &write(const char_type *a_pchSrc, std::streamsize a_cchToWrite)
     107        {
     108            sentry PrePost(*this);
     109            if (PrePost)
     110            {
     111                std::streamsize cchWritten = m_pBuf->sputn(a_pchSrc, a_cchToWrite);
     112                if (cchWritten != a_cchToWrite)
     113                    m_fState |= badbit;
     114            }
     115            return *this;
     116        }
     117
    59118        basic_ostream &flush();
    60119        pos_type       tellp() RT_NOEXCEPT;
     
    91150        }
    92151
    93         basic_ostream &formatInteger(uint64_t a_uValue, uint32_t fFlags)
    94         {
    95             fFlags |= intGetIntegerFlags();
     152        basic_ostream &formatInteger(uint64_t a_uValue, uint32_t a_fFlags, unsigned a_uBase = 0)
     153        {
     154            a_fFlags |= intGetIntegerFlags();
    96155            char szTmp[72];
    97             int  cchTmp = RTStrFormatNumber(szTmp, a_uValue, intGetIntegerBase(), 0, 0, fFlags);
     156            int  cchTmp = RTStrFormatNumber(szTmp, a_uValue, !a_uBase ? intGetIntegerBase() : a_uBase, 0, 0, a_fFlags);
    98157
    99158            /** @todo apply cchWidth and padding.  */
     
    171230                                    RTSTR_F_VALSIGNED | (sizeof(a_uValue) > sizeof(uint32_t) ? RTSTR_F_64BIT : RTSTR_F_32BIT));
    172231    }
     232
     233    template<typename a_CharType, typename a_CharTraits = std::char_traits<a_CharType> >
     234    basic_ostream<a_CharType, a_CharTraits> &operator<<(basic_ostream<a_CharType, a_CharTraits> &a_rDst, void const *a_pvValue)
     235    {
     236        return a_rDst.formatInteger((uintptr_t)a_pvValue,
     237                                    (sizeof(a_pvValue) > sizeof(uint32_t) ? RTSTR_F_64BIT : RTSTR_F_32BIT), 16);
     238    }
    173239    /** @} */
    174240
     241    template<>
     242    basic_ostream<char> &basic_ostream<char>::intWrite(const char *a_pchSrc, std::streamsize a_cchToWrite)
     243    {
     244        return write(a_pchSrc, a_cchToWrite);
     245    }
     246
     247
    175248}
    176249
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette