ARTS  1.0.222
iotraits.h
Go to the documentation of this file.
1 // <!!-*-C++-*- file: iotraits.h --->
2 // <!!-------------------------------------------------------------------------->
3 // <!! Copyright (C) 1996 Dietmar Kuehl >
4 // <!! Universitaet Konstanz, Lehrstuhl fuer praktische Informatik I >
5 // <!!>
6 // <!! Permission to use, copy, modify, distribute and sell this >
7 // <!! software for any purpose is hereby granted without fee, provided >
8 // <!! that the above copyright notice appears in all copies and that >
9 // <!! both that copyright notice and this permission notice appear in >
10 // <!! supporting documentation. Dietmar Kuehl makes no representations >
11 // <!! about the suitability of this software for any purpose. It is >
12 // <!! provided "as is" without express or implied warranty. >
13 // <!!-------------------------------------------------------------------------->
14 
15 // Author: Dietmar Kühl dietmar.kuehl@uni-konstanz.de www.informatik.uni-konstanz.de/~kuehl
16 // Title: The definition of the iotraits classes
17 
18 //------------------------------------------------------------------------------
19 
20 #if !defined(IOTRAITS_H)
21 #define IOTRAITS_H
22 
23 #include <cstring>
24 #include <cctype>
25 #include <streambuf.h>
26 
27 #if defined(__GNUC__) && __GNUC_MINOR__ <= 7
28 # define PORT_TEMPLATE_SPECIALIZATION
29 #else
30 # define PORT_TEMPLATE_SPECIALIZATION template <>
31 #endif
32 
33 //------------------------------------------------------------------------------
34 
35 template <class charT> struct ctype {};
36 
38 struct ctype<char>
39 {
40  typedef char char_type;
41  typedef int int_type;
42 
43  //--- fix needed: bool isspace(int_type c) const { return isspace(c); }
44  char_type newline() const { return '\n'; }
45 };
46 
47 //------------------------------------------------------------------------------
48 
49 template <class charT> struct ios_traits {};
50 
51 //------------------------------------------------------------------------------
52 
54 struct ios_traits<char>
55 {
56  typedef char char_type;
57  typedef int int_type;
58  typedef streampos pos_type;
59  typedef streamoff off_type;
60  typedef int state_type;
61 
62  static inline char_type eos() { return char_type(); }
63  static inline int_type eof() { return -1; }
64  static inline int_type not_eof(int_type c) { return c == eof()? eof() + 1: c; }
65  static inline char_type newline() { return '\n'; }
66 
67  static inline bool eq(char_type c1, char_type c2) { return c1 == c2; }
68  static inline bool eq_int_type(int_type i1, int_type i2) { return i1 == i2; }
69  static inline void assign(char& to, char from) { to = from; }
70 
71  static inline char_type to_char_type(int_type c) { return char_type(c); }
72  static inline int_type to_int_type(char_type c) { return int_type(c); }
73 
74  static inline char_type *copy(char_type *dst, char_type const *src, pos_type n)
75  {
76  memcpy(dst, src, n);
77  return dst;
78  }
79  static inline size_t length(char_type const *s) { return strlen(s); }
80 };
81 
82 //------------------------------------------------------------------------------
83 
84 #endif /* IOTRAITS_H */
ios_traits< char >::state_type
int state_type
Definition: iotraits.h:60
ios_traits< char >::to_char_type
static char_type to_char_type(int_type c)
Definition: iotraits.h:71
ios_traits< char >::eof
static int_type eof()
Definition: iotraits.h:63
ios_traits< char >::length
static size_t length(char_type const *s)
Definition: iotraits.h:79
ctype< char >::int_type
int int_type
Definition: iotraits.h:41
ios_traits< char >::eq_int_type
static bool eq_int_type(int_type i1, int_type i2)
Definition: iotraits.h:68
ios_traits< char >::char_type
char char_type
Definition: iotraits.h:56
ios_traits
Definition: iotraits.h:49
ctype< char >::newline
char_type newline() const
Definition: iotraits.h:44
PORT_TEMPLATE_SPECIALIZATION
#define PORT_TEMPLATE_SPECIALIZATION
Definition: iotraits.h:30
ios_traits< char >::not_eof
static int_type not_eof(int_type c)
Definition: iotraits.h:64
ios_traits< char >::eos
static char_type eos()
Definition: iotraits.h:62
ios_traits< char >::newline
static char_type newline()
Definition: iotraits.h:65
ios_traits< char >::to_int_type
static int_type to_int_type(char_type c)
Definition: iotraits.h:72
ctype< char >::char_type
char char_type
Definition: iotraits.h:40
ios_traits< char >::assign
static void assign(char &to, char from)
Definition: iotraits.h:69
ios_traits< char >::off_type
streamoff off_type
Definition: iotraits.h:59
ios_traits< char >::copy
static char_type * copy(char_type *dst, char_type const *src, pos_type n)
Definition: iotraits.h:74
ios_traits< char >::pos_type
streampos pos_type
Definition: iotraits.h:58
ctype
Definition: iotraits.h:35
ios_traits< char >::eq
static bool eq(char_type c1, char_type c2)
Definition: iotraits.h:67
ios_traits< char >::int_type
int int_type
Definition: iotraits.h:57