|
Aegis
4.25.D505
|
00001 // 00002 // aegis - project change supervisor 00003 // Copyright (C) 1999, 2002, 2004-2006, 2008, 2009, 2012 Peter Miller 00004 // Copyright (C) 2008, 2009 Walter Franzini 00005 // 00006 // This program is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 3 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program. If not, see 00018 // <http://www.gnu.org/licenses/>. 00019 // 00020 00021 #ifndef LIBAEGIS_INPUT_H 00022 #define LIBAEGIS_INPUT_H 00023 00024 #include <common/ac/sys/types.h> 00025 00026 #include <common/nstring.h> 00027 00028 class input; // forward 00029 00033 class input_ty 00034 { 00035 public: 00036 typedef input_ty* pointer; 00037 00044 virtual ~input_ty(); 00045 00049 input_ty(); 00050 00066 ssize_t read(void *data, size_t nbytes); 00067 00079 void read_strictest(void *data, size_t size); 00080 00094 bool read_strict(void *data, size_t size); 00095 00105 void skip(size_t size); 00106 00114 void fatal_error(const char *msg); 00115 00122 void error(const char *msg); 00123 00134 bool one_line(nstring &result); 00135 00140 off_t ftell(); 00141 00145 virtual nstring name() = 0; 00146 00151 virtual off_t length() = 0; 00152 00157 int 00158 getch() 00159 { 00160 if (buffer_position < buffer_end) 00161 return *buffer_position++; 00162 return getc_complicated(); 00163 } 00164 00169 void 00170 ungetc(int c) 00171 { 00172 if (c >= 0) 00173 { 00174 if (buffer_position > buffer) 00175 *--buffer_position = c; 00176 else 00177 ungetc_complicated(c); 00178 } 00179 } 00180 00188 int 00189 peek() 00190 { 00191 int c = getch(); 00192 ungetc(c); 00193 return c; 00194 } 00195 00200 virtual void keepalive(); 00201 00206 void pushback_transfer(input &from); 00207 00212 void pullback_transfer(input_ty::pointer to); 00213 00218 void pullback_transfer(input &to); 00219 00230 void unread(const void *data, size_t nbytes); 00231 00236 bool at_end(); 00237 00245 virtual bool is_remote() const; 00246 00247 void reference_count_up(); 00248 void reference_count_down(); 00249 bool reference_count_valid() const { return (reference_count >= 1); } 00250 00251 protected: 00267 virtual ssize_t read_inner(void *data, size_t nbytes) = 0; 00268 00273 virtual off_t ftell_inner() = 0; 00274 00280 int getc_complicated(); 00281 00287 void ungetc_complicated(int c); 00288 00289 private: 00290 long reference_count; 00291 00297 unsigned char *buffer; 00298 00303 size_t buffer_size; 00304 00309 unsigned char *buffer_position; 00310 00315 unsigned char *buffer_end; 00316 }; 00317 00318 00324 class input 00325 { 00326 friend class input_ty; 00327 00328 public: 00336 ~input(); 00337 00344 input(); 00345 00355 input(input_ty::pointer arg); 00356 00360 input(const input &arg); 00361 00365 input &operator=(const input &arg); 00366 00367 #if 0 00368 00376 input &operator=(input *arg); 00377 #endif 00378 00387 input_ty::pointer operator->() { return ref; } 00388 00397 input_ty::pointer operator->() const { return ref; } 00398 00405 void close(); 00406 00412 bool is_open() const { return (ref != 0); } 00413 00418 bool valid() const; 00419 00420 private: 00425 input_ty::pointer ref; 00426 }; 00427 00428 00429 #endif // LIBAEGIS_INPUT_H 00430 // vim: set ts=8 sw=4 et :
1.7.6.1