Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Input.h
1 /*
2  * $Id$
3  * Input class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2006-09, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_IO_INPUT_H
23 #define ELM_IO_INPUT_H
24 
25 #include <elm/types.h>
26 #include <elm/string/String.h>
27 #include <elm/string/CString.h>
28 #include <elm/io/InStream.h>
29 
30 namespace elm { namespace io {
31 
32 // Input class
33 class Input {
34 public:
35  inline Input(void): strm(&in), buf(-1) { };
36  inline Input(InStream& stream): strm(&stream), buf(-1) { };
37  inline InStream& stream(void) const { return *strm; };
38  inline void setStream(InStream& stream) { strm = &stream; buf = -1; };
39 
40  bool scanBool(void);
41  char scanChar(void);
42  t::int32 scanLong(void);
43  t::uint32 scanULong(void);
44  t::int64 scanLLong(void);
45  t::uint64 scanULLong(void);
46  double scanDouble(void);
47  String scanWord(void);
48  String scanLine(void);
49  void swallow(char chr);
50  void swallow(CString str);
51  void swallow(const String& str);
52  void swallowBlank(void);
53 
54  inline Input& operator>>(bool& value) { value = scanBool(); return *this; };
55  inline Input& operator>>(char& value) { value = scanChar(); return *this; };
56  inline Input& operator>>(unsigned char& value) { value = scanULong(); return *this; };
57  inline Input& operator>>(short& value) { value = scanLong(); return *this; };
58  inline Input& operator>>(unsigned short& value) { value = scanULong(); return *this; };
59  inline Input& operator>>(int& value) { value = scanLong(); return *this; };
60  inline Input& operator>>(unsigned int& value) { value = scanULong(); return *this; };
61 # ifndef __LP64__
62  inline Input& operator>>(signed long& value) { value = scanLong(); return *this; };
63  inline Input& operator>>(unsigned long& value) { value = scanULong(); return *this; };
64 # else
65  inline Input& operator>>(signed long& value) { value = scanLLong(); return *this; };
66  inline Input& operator>>(unsigned long& value) { value = scanULLong(); return *this; };
67 # endif
68  inline Input& operator>>(signed long long& value) { value = scanLLong(); return *this; };
69  inline Input& operator>>(unsigned long long& value) { value= scanULLong(); return *this; };
70  inline Input& operator>>(float& value) { value = scanDouble(); return *this; };
71  inline Input& operator>>(double& value) { value = scanDouble(); return *this; };
72  inline Input& operator>>(String& value) { value = scanLine(); return *this; };
73 
74  inline Input& operator>>(const string& text) { swallow(text); return *this; }
75  inline Input& operator>>(cstring text) { swallow(text); return *this; }
76  inline Input& operator>>(const char *text) { swallow(cstring(text)); return *this; }
77 
78  template <class T> struct def_scanner { static inline void scan(Input& in, T& v) { unsupported(); } };
79  template <class T> struct enum_scanner { static inline void scan(Input& in, T& v) { string s; in >> s; v = enum_info<T>::fromString(s); } };
80  template <class T> Input& operator>>(T& v)
81  { _if<type_info<T>::is_defined_enum, enum_scanner<T>, def_scanner<T> >::_::scan(*this, v); return *this; }
82 private:
83  static void unsupported(void);
84  InStream *strm;
85  int buf;
86  int get(void);
87  void back(int chr);
88 };
89 
90 } } // elm::io
91 
92 #endif // ELM_IO_INPUT_H
Input & operator>>(short &value)
Definition: Input.h:57
static void scan(Input &in, T &v)
Definition: Input.h:78
Definition: CString.h:17
Input(InStream &stream)
Definition: Input.h:36
Input & operator>>(signed long &value)
Definition: Input.h:62
void setStream(InStream &stream)
Definition: Input.h:38
int32_t int32
Definition: int.h:34
sys::SystemInStream & in
Definition: system_SystemIO.cpp:95
Input & operator>>(const char *text)
Definition: Input.h:76
String scanLine(void)
Definition: io_Input.cpp:407
Input & operator>>(unsigned long long &value)
Definition: Input.h:69
static void scan(Input &in, T &v)
Definition: Input.h:79
Definition: Input.h:78
value_t value(CString name, int value)
Definition: rtti.h:40
Definition: Input.h:33
Input(void)
Definition: Input.h:35
Input & operator>>(unsigned long &value)
Definition: Input.h:63
t::int64 scanLLong(void)
Definition: io_Input.cpp:308
Definition: meta.h:18
int64_t int64
Definition: int.h:36
Input & operator>>(float &value)
Definition: Input.h:70
t::uint64 scanULLong(void)
Definition: io_Input.cpp:263
static T fromString(const string &name)
Definition: enum_info.h:47
Input & operator>>(bool &value)
Definition: Input.h:54
char scanChar(void)
Definition: io_Input.cpp:149
double scanDouble(void)
Definition: io_Input.cpp:331
Input & operator>>(unsigned char &value)
Definition: Input.h:56
Definition: String.h:31
bool scanBool(void)
Definition: io_Input.cpp:109
Definition: Input.h:79
Input & operator>>(const string &text)
Definition: Input.h:74
Input & operator>>(unsigned int &value)
Definition: Input.h:60
Input & operator>>(T &v)
Definition: Input.h:80
Input & operator>>(int &value)
Definition: Input.h:59
Input & operator>>(char &value)
Definition: Input.h:55
Input & operator>>(String &value)
Definition: Input.h:72
Input & operator>>(double &value)
Definition: Input.h:71
CString cstring
Definition: CString.h:62
InStream & stream(void) const
Definition: Input.h:37
String scanWord(void)
Definition: io_Input.cpp:391
void swallowBlank(void)
Definition: io_Input.cpp:461
Definition: InStream.h:30
t::uint32 scanULong(void)
Definition: io_Input.cpp:187
Input & operator>>(unsigned short &value)
Definition: Input.h:58
Input & operator>>(cstring text)
Definition: Input.h:75
uint32_t uint32
Definition: int.h:35
uint64_t uint64
Definition: int.h:37
void swallow(char chr)
Definition: io_Input.cpp:424
Input & operator>>(signed long long &value)
Definition: Input.h:68
t::int32 scanLong(void)
Definition: io_Input.cpp:239