Ignore:
Timestamp:
2018-07-05T21:41:19Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c1e11d32
Parents:
e8c4c59
git-author:
Dzejrou <dzejrou@…> (2017-12-17 20:01:53)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:19)
Message:

cpp: added most of the integral extractors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/istream.hpp

    re8c4c59 r7c84fce  
    155155            basic_istream<Char, Traits>& operator>>(bool& x)
    156156            {
    157                 // TODO: implement
     157                sentry sen{*this, false};
     158
     159                if (sen)
     160                {
     161                    using num_get = num_get<Char, istreambuf_iterator<Char, Traits>>;
     162                    auto err = ios_base::goodbit;
     163
     164                    auto loc = this->getloc();
     165                    use_facet<num_get>(loc).get(*this, 0, *this, err, x);
     166                    this->setstate(err);
     167                }
     168
     169                return *this;
    158170            }
    159171
    160172            basic_istream<Char, Traits>& operator>>(short& x)
    161173            {
    162                 // TODO: implement
     174                sentry sen{*this, false};
     175
     176                if (sen)
     177                {
     178                    using num_get = num_get<Char, istreambuf_iterator<Char, Traits>>;
     179                    auto err = ios_base::goodbit;
     180
     181                    long tmp{};
     182                    auto loc = this->getloc();
     183                    use_facet<num_get>(loc).get(*this, 0, *this, err, tmp);
     184
     185                    if (tmp < numeric_limits<short>::min())
     186                    {
     187                        err |= ios_base::failbit;
     188                        x = numeric_limits<short>::min();
     189                    }
     190                    else if (numeric_limits<short>::max() < tmp)
     191                    {
     192                        err |= ios_base::failbit;
     193                        x = numeric_limits<short>::max();
     194                    }
     195                    else
     196                        x = static_cast<short>(tmp);
     197
     198                    this->setstate(err);
     199                }
     200
     201                return *this;
    163202            }
    164203
    165204            basic_istream<Char, Traits>& operator>>(unsigned short& x)
    166205            {
    167                 // TODO: implement
     206                sentry sen{*this, false};
     207
     208                if (sen)
     209                {
     210                    using num_get = num_get<Char, istreambuf_iterator<Char, Traits>>;
     211                    auto err = ios_base::goodbit;
     212
     213                    auto loc = this->getloc();
     214                    use_facet<num_get>(loc).get(*this, 0, *this, err, x);
     215                    this->setstate(err);
     216                }
     217
     218                return *this;
    168219            }
    169220
    170221            basic_istream<Char, Traits>& operator>>(int& x)
    171222            {
    172                 // TODO: implement
     223                sentry sen{*this, false};
     224
     225                if (sen)
     226                {
     227                    using num_get = num_get<Char, istreambuf_iterator<Char, Traits>>;
     228                    auto err = ios_base::goodbit;
     229
     230                    long tmp{};
     231                    auto loc = this->getloc();
     232                    use_facet<num_get>(loc).get(*this, 0, *this, err, tmp);
     233
     234                    if (tmp < numeric_limits<int>::min())
     235                    {
     236                        err |= ios_base::failbit;
     237                        x = numeric_limits<int>::min();
     238                    }
     239                    else if (numeric_limits<int>::max() < tmp)
     240                    {
     241                        err |= ios_base::failbit;
     242                        x = numeric_limits<int>::max();
     243                    }
     244                    else
     245                        x = static_cast<int>(tmp);
     246
     247                    this->setstate(err);
     248                }
     249
     250                return *this;
    173251            }
    174252
    175253            basic_istream<Char, Traits>& operator>>(unsigned int& x)
    176254            {
    177                 // TODO: implement
     255                sentry sen{*this, false};
     256
     257                if (sen)
     258                {
     259                    using num_get = num_get<Char, istreambuf_iterator<Char, Traits>>;
     260                    auto err = ios_base::goodbit;
     261
     262                    auto loc = this->getloc();
     263                    use_facet<num_get>(loc).get(*this, 0, *this, err, x);
     264                    this->setstate(err);
     265                }
     266
     267                return *this;
    178268            }
    179269
    180270            basic_istream<Char, Traits>& operator>>(long& x)
    181271            {
    182                 // TODO: implement
     272                sentry sen{*this, false};
     273
     274                if (sen)
     275                {
     276                    using num_get = num_get<Char, istreambuf_iterator<Char, Traits>>;
     277                    auto err = ios_base::goodbit;
     278
     279                    auto loc = this->getloc();
     280                    use_facet<num_get>(loc).get(*this, 0, *this, err, x);
     281                    this->setstate(err);
     282                }
     283
     284                return *this;
    183285            }
    184286
    185287            basic_istream<Char, Traits>& operator>>(unsigned long& x)
    186288            {
    187                 // TODO: implement
     289                sentry sen{*this, false};
     290
     291                if (sen)
     292                {
     293                    using num_get = num_get<Char, istreambuf_iterator<Char, Traits>>;
     294                    auto err = ios_base::goodbit;
     295
     296                    auto loc = this->getloc();
     297                    use_facet<num_get>(loc).get(*this, 0, *this, err, x);
     298                    this->setstate(err);
     299                }
     300
     301                return *this;
    188302            }
    189303
    190304            basic_istream<Char, Traits>& operator>>(long long& x)
    191305            {
    192                 // TODO: implement
     306                sentry sen{*this, false};
     307
     308                if (sen)
     309                {
     310                    using num_get = num_get<Char, istreambuf_iterator<Char, Traits>>;
     311                    auto err = ios_base::goodbit;
     312
     313                    auto loc = this->getloc();
     314                    use_facet<num_get>(loc).get(*this, 0, *this, err, x);
     315                    this->setstate(err);
     316                }
     317
     318                return *this;
    193319            }
    194320
    195321            basic_istream<Char, Traits>& operator>>(unsigned long long& x)
    196322            {
    197                 // TODO: implement
     323                sentry sen{*this, false};
     324
     325                if (sen)
     326                {
     327                    using num_get = num_get<Char, istreambuf_iterator<Char, Traits>>;
     328                    auto err = ios_base::goodbit;
     329
     330                    auto loc = this->getloc();
     331                    use_facet<num_get>(loc).get(*this, 0, *this, err, x);
     332                    this->setstate(err);
     333                }
     334
     335                return *this;
    198336            }
    199337
Note: See TracChangeset for help on using the changeset viewer.