Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
Data Structures | Macros | Functions
27.istream.sentry.cpp File Reference
#include <istream>
#include <locale>
#include <streambuf>
#include <rw_char.h>
#include <rw_printf.h>
#include <rw_driver.h>
Include dependency graph for 27.istream.sentry.cpp:

Go to the source code of this file.

Data Structures

struct  Ctype< charT >
 
struct  Streambuf< charT, Traits >
 

Macros

#define TEST(what, charT, Traits)    test_ ## what ((charT*)0, (Traits*)0, #charT, #Traits)
 

Functions

void memfun_info (int line, const char *cname, const char *tname, const char *fname)
 
template<class charT , class Traits >
void test_ctor (const charT *, const Traits *, const char *cname, const char *tname)
 
template<class charT , class Traits >
void test_ok (const charT *, const Traits *, const char *cname, const char *tname)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ TEST

#define TEST (   what,
  charT,
  Traits 
)     test_ ## what ((charT*)0, (Traits*)0, #charT, #Traits)

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 508 of file 27.istream.sentry.cpp.

◆ memfun_info()

void memfun_info ( int  line,
const char *  cname,
const char *  tname,
const char *  fname 
)

istream_sentry.cpp - test exercising basic_istream<charT>::sentry

$Id$

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2003-2006 Rogue Wave Software, Inc.

27.6.1.1.2   Class basic_istream::sentry   [lib.istream::sentry]

namespace std {
    template <class charT, class traits = char_traits<charT> >
    class basic_istream<charT, traits>::sentry {
        typedef traits traits_type;
        bool ok_;                            // exposition only
    public:
        explicit
        sentry (basic_istream<charT, traits>& is, bool noskipws = false);
        ~sentry ();
        operator bool() const { return ok_; }
    private:
        sentry (const sentry&);              // not defined
        sentry& operator= (const sentry&);   // not defined
    };
}

-1- The class sentry defines a class that is responsible for doing
    exception safe prefix and suffix operations.

explicit sentry(basic_istream<charT, traits>& is, bool noskipws = false);
-2- Effects: If is.good() is true, prepares for formatted or unformatted
    input. First, if is.tie() is not a null pointer, the function calls
    is.tie()­>flush() to synchronize the output sequence with any
    associated external C stream. Except that this call can be suppressed
    if the put area of is.tie() is empty. Further an implementation is
    allowed to defer the call to flush until a call of
    is->rdbuf()­>underflow occurs. If no such call occurs before the
    sentry object is destroyed, the call to flush may be eliminated
    entirely(279). If noskipws is zero and is.flags() & ios_base::skipws
    is nonzero, the function extracts and discards each character as long
    as the next available input character c is a whitespace character.
-3- Notes: The constructor explicit sentry(basic_istream<charT, traits>&
    is, bool noskipws = false) uses the currently imbued locale in is,
    to determine whether the next input character is whitespace or not.
-4- To decide if the character cis a whitespace character, the constructor
    performs "as if" it executes the following code fragment:
    const ctype<charT>& ctype = use_facet<ctype<charT> >(is.getloc());
    if (ctype.is (ctype.space,c) != 0)

c is a whitespace character. -5- If, after any preparation is completed, is.good() is true, ok_ != false otherwise, ok_ == false. During preparation, the constructor may call setstate(failbit) (which may throw ios_base::failure (27.4.4.3))(280)


279) This will be possible only in functions that are part of the library. The semantics of the constructor used in user code is as specified. 280) The sentry constructor and destructor can also perform additional implementation-dependent operations.

-6- [Example: A typical implementation of the sentry constructor might include code such as:

template <class charT, class traits = char_traits<charT> > basic_istream<charT,traits>::sentry( basic_istream<charT,traits>& is, bool noskipws = false) { ... int_type c; typedef ctype<charT> ctype_type; const ctype_type& ctype = use_facet<ctype_type>(is.getloc()); while ((c = is.rdbuf()­>snextc()) != traits::eof()) { if (ctype.is(ctype.space,c)==0) { is.rdbuf()­>sputbackc (c); break; } } ... } –end example]

~sentry(); -7- Effects: None.

operator bool() const; -8- Effects: Returns ok_.

Definition at line 120 of file 27.istream.sentry.cpp.

◆ test_ctor()

template<class charT , class Traits >
void test_ctor ( const charT *  ,
const Traits *  ,
const char *  cname,
const char *  tname 
)

Definition at line 235 of file 27.istream.sentry.cpp.

◆ test_ok()

template<class charT , class Traits >
void test_ok ( const charT *  ,
const Traits *  ,
const char *  cname,
const char *  tname 
)

Definition at line 371 of file 27.istream.sentry.cpp.