Ce texte est un listage en peu remanié des fichiers d'entête trouvés dans les distributions IBM/AIX/xlC et Linux. Pour une présentation des notions voir le lien cppEs.html; ce lien est utilisé plusieurs fois dans la suite du texte.
Les déclarations de classes sont réparties dans plusieurs fichiers d'entête. Nous présentons un extrait de ces fichiers; leur contenu dépend de l'environnement de programmation utilisé. Les valeurs numériques associées aux constantes symboliques ne doivent pas être utilisées, car elles dépendent de l'environnement; il faut utiliser le nom symbolique.
typedef unsigned long fmtflags; typedef long int streampos; typedef long int streamoff; class ostream; class streambuf;
class ios : public _ios_fields { ios& operator=(ios&); /* Not allowed! */ ios (const ios&); /* Not allowed! */ public: // voir état d'un flot enum io_state { goodbit=0x00, badbit=0x01, eofbit=0x02, failbit=0x04 }; // voir ouverture d'un fichier enum open_mode { in=0x01, out=0x02, ate=0x04, app=0x08, trunc=0x0100, nocreate=0x0200, noreplace=0x0400, binary=0x0800 }; // voir position dans un fichier enum seek_dir { beg, cur, end}; typedef enum seek_dir seekdir; // Formatage enum { // Indications du formatage // arguments de setf(bits) skipws=0x1000, showbase=0x0200, showpoint=0x0400, uppercase=0x4000, showpos=0x0800, unitbuf=0x2000, stdio=0x8000 // 1er argument de setf(bits, masque) left=0x0020, right=0x0080, internal=0x0010, dec=0x0002, oct=0x0040, hex=0x0008, scientific=0x0100, fixed=0x0004, }; enum { // Masque, 2eme argument de setf(bits, masque). basefield=dec+oct+hex, floatfield = scientific+fixed, adjustfield = left+right+internal }; // Informations de formatage et exemple char fill() const; // caractère de remplissage int precision() const; // nb.chiffres après la virgule int precision(int newp); int width() const; // largeur du champ d'affichage int width(int val); unsigned long flags() const; unsigned long flags(unsigned long new_bits); unsigned long setf(unsigned long bits); // active un ou des bits unsigned long setf(unsigned long bits, unsigned long mask); unsigned long unsetf(unsigned long mask); // desactive 1 ou des bits // Test de l'état d'erreur d'un flot int good() const; int eof() const; int fail() const; int bad() const; operator void*() const { return fail() ? (void*)0 : (void*)(-1); } int operator!() const { return fail(); } // Gestion du mot d'état iostate rdstate() const; // récupération du mot void clear(iostate state = 0); // change le mot void set(iostate flag); // change un ou des bits void setstate(iostate flag) // Exceptions #ifdef _IO_THROW class failure : public xmsg { ios* _stream; public: failure(ios* stream) { _stream = stream; } failure(string cause, ios* stream) { _stream = stream; } ios* rdios() const { return _stream; } }; #endif #ifdef _IO_THROW void _throw_failure() const { throw new ios::failure(this); } #else void _throw_failure() const { } #endif iostate exceptions() const { return _exceptions; } void exceptions(iostate enable) { _exceptions = enable; if (_state & _exceptions) _throw_failure(); } // Divers streambuf* rdbuf() const; streambuf* rdbuf(streambuf *_s); ostream* tie() const; ostream* tie(ostream* val); static int sync_with_stdio(int on); static void sync_with_stdio() { sync_with_stdio(1); } static unsigned long bitalloc(); static int xalloc(); void*& pword(int); void* pword(int) const; long& iword(int); long iword(int) const; protected: inline ios(streambuf* sb = 0, ostream* tie_to = 0); inline virtual ~ios(); inline void init(streambuf* sb, ostream* tie = 0); };
class ostream : virtual public ios { public: ostream() { } ostream(streambuf* sb, ostream* tied=NULL); // // écriture binaire ou sans formatage ostream& write(const char *s, streamsize n); ostream& write(const unsigned char *s, streamsize n) { return write((const char*)s, n);} ostream& write(const signed char *s, streamsize n) { return write((const char*)s, n);} ostream& write(const void *s, streamsize n) { return write((const char*)s, n);} // déplacement dans le flot de sortie ostream& seekp(streampos); ostream& seekp(streamoff, _seek_dir); streampos tellp(); ostream& put(char c) { _strbuf->sputc(c); return *this; } ostream& put(unsigned char c) { return put((char)c); } ostream& put(signed char c) { return put((char)c); } ostream& flush(); // vider le flot // Redéfinitions de operator<< sortie avec formatage ostream& operator<<(char c); ostream& operator<<(unsigned char c) {return (*this) << (char)c;} ostream& operator<<(signed char c) {return (*this) << (char)c;} ostream& operator<<(const char *s); ostream& operator<<(const unsigned char *s) { return (*this) << (const char*)s; } ostream& operator<<(const signed char *s) { return (*this) << (const char*)s; } ostream& operator<<(const void *p); ostream& operator<<(int n); ostream& operator<<(unsigned int n); ostream& operator<<(long n); ostream& operator<<(unsigned long n); ostream& operator<<(short n) {return operator<<((int)n);} ostream& operator<<(unsigned short n) {return operator<<((unsigned int)n);} ostream& operator<<(bool b) { return operator<<((int)b); } ostream& operator<<(double n); ostream& operator<<(float n) { return operator<<((double)n); } ostream& operator<<(long double n); // Action des manipulateurs sans paramètre ostream& operator<<(__omanip func) { return (*func)(*this); } ostream& operator<<(__manip func) {(*func)(*this); return *this;} ostream& operator<<(streambuf*); // ostream& form(const char *format ...); ostream& vform(const char *format, _IO_va_list args); // int opfx(); void osfx(); };
class istream : virtual public ios { public: istream(): _gcount (0) { } istream(streambuf* sb, ostream*tied=NULL); // // Opérateur de lecture avec formatage istream& operator>>(char*); istream& operator>>(char& c); istream& operator>>(int&); istream& operator>>(long&); istream& operator>>(short&); istream& operator>>(bool&); istream& operator>>(float&); istream& operator>>(double&); istream& operator>>(long double&); // Lecture de chaîne de caractères istream& get(char* ptr, int len, char delim = '\n'); istream& getline(char* ptr, int len, char delim = '\n'); istream& get(streambuf& sb, char delim = '\n'); istream& gets(char **s, char delim = '\n'); long int gcount(); // nombre de caractères lus istream& ignore(int n=1, int delim=EOF); // enlever des caractères // Lecture binaire ou copie simple istream& read(char *ptr, streamsize n); istream& read(void *ptr, streamsize n); // Déplacements. istream& seekg(streampos); // déplacement absolu istream& seekg(streamoff, _seek_dir); // déplacement relatif streampos tellg(); // position dans le fichier // Cas d'un seul octet, espace possible istream& get(char& c); // lecture d'un octet int get() int peek(); // examiner le prochain caractère istream& putback(char ch); // remettre un caractère istream& unget(); // Action des manipulateurs sans paramètre istream& operator>>( __manip func) {(*func)(*this); return *this;} istream& operator>>(__imanip func) { return (*func)(*this); } istream& operator>>(streambuf*); // int sync (); int ipfx(int need = 0); int ipfx0(); int ipfx1(); void isfx(); istream& scan(const char *format ...); istream& vscan(const char *format, _IO_va_list args); };
class iostream : public istream, public ostream { public: iostream() { } iostream(streambuf* sb, ostream*tied=NULL); };
extern _IO_istream_withassign cin; extern _IO_ostream_withassign cout, cerr; extern _IO_ostream_withassign clog;
class istream; class ostream; // Définitions de __manip, __imanip et __omanip typedef ios& (*__manip)(ios&); typedef istream& (*__imanip)(istream&); typedef ostream& (*__omanip)(ostream&); extern istream& ws(istream& ins); // ignorer les espaces (white space) extern ostream& flush(ostream& outs); // vider le tampon extern ostream& endl(ostream& outs); // saut de ligne et vider le tampon extern ostream& ends(ostream& outs); // fin de chaîne (avec ostrstream)
inline ios& oct(ios& i) { i.setf(ios::oct, ios::dec|ios::hex|ios::oct); return i; } inline ios& dec(ios& i) { i.setf(ios::dec, ios::dec|ios::hex|ios::oct); return i; } inline ios& hex(ios& i) { i.setf(ios::hex, ios::dec|ios::hex|ios::oct); return i; }
class _IO_istream_withassign : public istream { public: _IO_istream_withassign& operator=(istream&); _IO_istream_withassign& operator=(_IO_istream_withassign& rhs) { return operator= (static_cast<istream&> (rhs)); } }; class _IO_ostream_withassign : public ostream { public: _IO_ostream_withassign& operator=(ostream&); _IO_ostream_withassign& operator=(_IO_ostream_withassign& rhs) { return operator= (static_cast<ostream&> (rhs)); } };
class fstreambase : virtual public ios { public: fstreambase(); fstreambase(int fd); fstreambase(const char *name, int mode, int prot=0664); void close(); // fermer un fichier filebuf* rdbuf() const; // Ouverture explicite void open(const char *name, int mode, int prot=0664); int is_open() const; void setbuf(char *ptr, int len); void attach(int fd); };
class ifstream : public fstreambase, public istream { public: ifstream() : fstreambase() { } ifstream(int fd); // Flot en lecture, exemple 1 et exemple 2 ifstream(const char *name, int mode=ios::in, int prot=0664); // Ouverture explicite void open(const char *name, int mode=ios::in, int prot=0664); };
class ofstream : public fstreambase, public ostream { public: ofstream() : fstreambase() { } ofstream(int fd); ofstream(const char *name, int mode=ios::out, int prot=0664); // Ouverture explicite void open(const char *name, int mode=ios::out, int prot=0664); };
class fstream : public fstreambase, public iostream { public: fstream() : fstreambase() { } fstream(int fd); fstream(const char *name, int mode, int prot=0664); void open(const char *name, int mode, int prot=0664); };
class strstreambuf : public streambuf { struct _IO_str_fields _s; friend class istrstream; void init_dynamic(_IO_alloc_type alloc, _IO_free_type free, int initial_size = 0); void init_static(char *ptr, int size, char *pstart); void init_readonly(const char *ptr, int size); protected: virtual int overflow(int = EOF); virtual int underflow(); virtual int pbackfail(int c); public: virtual ~strstreambuf(); strstreambuf(); strstreambuf(int initial_size); strstreambuf(char *ptr, int size, char *pstart = NULL); strstreambuf(unsigned char *ptr,int size,unsigned char *pstart=NULL); strstreambuf(const char *ptr, int size); strstreambuf(const unsigned char *ptr, int size); strstreambuf(signed char *ptr, int size, signed char *pstart = NULL); strstreambuf(const signed char *ptr, int size); strstreambuf(void *(*__alloc)(_IO_size_t), void (*__free)(void*)); // int frozen(); void freeze(int n=1); char *str(); long int pcount(); virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out); };
class strstreambase : virtual public ios { protected: strstreambuf __my_sb; public: strstreambuf* rdbuf() { return &__my_sb; } protected: strstreambase() { init (&__my_sb); } strstreambase(char *cp, int n, int mode=ios::out); };
class istrstream : public strstreambase, public istream { public: istrstream(const char*, int=0); };
class ostrstream : public strstreambase, public ostream { public: ostrstream(); ostrstream(char *cp, int n, int mode=ios::out); // voir un exemple. long int pcount(); // voir exemple. char *str(); // voir exemple. void freeze(int n = 1); int frozen(); };
class strstream : public strstreambase, public iostream { public: strstream() { } strstream(char *cp, int n, int mode=ios::out) :strstreambase(cp,n,mode){} long int pcount() { return ((strstreambuf*)_strbuf)->pcount(); } char *str() { return ((strstreambuf*)_strbuf)->str(); } void freeze(int n = 1) { ((strstreambuf*)_strbuf)->freeze(n); } int frozen() { return ((strstreambuf*)_strbuf)->frozen(); } };