00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef LIBAEGIS_INPUT_H
00021 #define LIBAEGIS_INPUT_H
00022
00023 #include <common/nstring.h>
00024 #include <common/main.h>
00025
00026 class input;
00027
00031 class input_ty
00032 {
00033 public:
00040 virtual ~input_ty();
00041
00045 input_ty();
00046
00062 long read(void *data, size_t nbytes);
00063
00075 void read_strictest(void *data, size_t size);
00076
00090 bool read_strict(void *data, size_t size);
00091
00101 void skip(size_t size);
00102
00107 void fatal_error(const char *msg);
00108
00119 bool one_line(nstring &result);
00120
00125 long ftell();
00126
00130 virtual nstring name() = 0;
00131
00136 virtual long length() = 0;
00137
00142 int
00143 getch()
00144 {
00145 if (buffer_position < buffer_end)
00146 return *buffer_position++;
00147 return getc_complicated();
00148 }
00149
00154 void
00155 ungetc(int c)
00156 {
00157 if (c >= 0)
00158 {
00159 if (buffer_position > buffer)
00160 *--buffer_position = c;
00161 else
00162 ungetc_complicated(c);
00163 }
00164 }
00165
00173 int
00174 peek()
00175 {
00176 int c = getch();
00177 ungetc(c);
00178 return c;
00179 }
00180
00185 virtual void keepalive();
00186
00191 void pushback_transfer(input &from);
00192
00197 void pullback_transfer(input_ty *to);
00198
00203 void pullback_transfer(input &to);
00204
00215 void unread(const void *data, size_t nbytes);
00216
00221 bool at_end();
00222
00230 virtual bool is_remote() const;
00231
00232 void reference_count_up();
00233 void reference_count_down();
00234 bool reference_count_valid() const { return (reference_count >= 1); }
00235
00236 protected:
00252 virtual long read_inner(void *data, size_t nbytes) = 0;
00253
00258 virtual long ftell_inner() = 0;
00259
00265 int getc_complicated();
00266
00272 void ungetc_complicated(int c);
00273
00274 private:
00275 long reference_count;
00276
00282 unsigned char *buffer;
00283
00288 size_t buffer_size;
00289
00294 unsigned char *buffer_position;
00295
00300 unsigned char *buffer_end;
00301 };
00302
00303
00304 inline DEPRECATED string_ty *
00305 input_name(input_ty *ip)
00306 {
00307 return ip->name().get_ref();
00308 }
00309
00310
00311 inline DEPRECATED void
00312 input_delete(input_ty *ip)
00313 {
00314 ip->reference_count_down();
00315 }
00316
00317
00318 inline DEPRECATED int
00319 input_getc(input_ty *ip)
00320 {
00321 return ip->getch();
00322 }
00323
00324
00325 inline DEPRECATED void
00326 input_ungetc(input_ty *ip, int c)
00327 {
00328 ip->ungetc(c);
00329 }
00330
00331
00332 inline DEPRECATED long
00333 input_length(input_ty *ip)
00334 {
00335 return ip->length();
00336 }
00337
00338
00339 inline DEPRECATED long
00340 input_read(input_ty *ip, void *data, size_t nbytes)
00341 {
00342 return ip->read(data, nbytes);
00343 }
00344
00345
00346 inline DEPRECATED void
00347 input_fatal_error(input_ty *ip, const char *msg)
00348 {
00349 ip->fatal_error(msg);
00350 }
00351
00352
00358 class input
00359 {
00360 friend class input_ty;
00361
00362 public:
00370 ~input();
00371
00378 input();
00379
00389 input(input_ty *arg);
00390
00394 input(const input &arg);
00395
00399 input &operator=(const input &arg);
00400
00401 #if 0
00402
00410 input &operator=(input *arg);
00411 #endif
00412
00421 input_ty *operator->() { return ref; }
00422
00431 const input_ty *operator->() const { return ref; }
00432
00439 void close();
00440
00446 bool is_open() const { return (ref != 0); }
00447
00452 bool valid() const;
00453
00454 private:
00459 input_ty *ref;
00460 };
00461
00462
00463 #endif // LIBAEGIS_INPUT_H