| Line | |
|---|
| 1 | #include "File.h"
|
|---|
| 2 |
|
|---|
| 3 | #include <stdlib.h>
|
|---|
| 4 |
|
|---|
| 5 | File::File(const char *name, const char *flags)
|
|---|
| 6 | {
|
|---|
| 7 | f = fopen(name, flags);
|
|---|
| 8 | }
|
|---|
| 9 |
|
|---|
| 10 | File::~File()
|
|---|
| 11 | {
|
|---|
| 12 | fclose(f);
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | char File::Getc() const
|
|---|
| 16 | {
|
|---|
| 17 | return fgetc(f);
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | int File::Eof() const
|
|---|
| 21 | {
|
|---|
| 22 | return feof(f);
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | void File::Seek(long pos) const
|
|---|
| 26 | {
|
|---|
| 27 | fseek(f, pos, SEEK_SET);
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | void File::Reset() const
|
|---|
| 31 | {
|
|---|
| 32 | fseek(f, 0, SEEK_SET);
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | long File::Tell() const
|
|---|
| 36 | {
|
|---|
| 37 | return ftell(f);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | long File::Size() const
|
|---|
| 41 | {
|
|---|
| 42 | long l = ftell(f);
|
|---|
| 43 | fseek(f, 0, SEEK_END);
|
|---|
| 44 | long s = ftell(f);
|
|---|
| 45 | fseek(f, l, SEEK_SET);
|
|---|
| 46 | return s;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | char *File::Gets(char *c, int cnt) const
|
|---|
| 50 | {
|
|---|
| 51 | for (int i=0; i<cnt; i++)
|
|---|
| 52 | *c++=fgetc(f);
|
|---|
| 53 | *c='\0';
|
|---|
| 54 |
|
|---|
| 55 | return c;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | void File::Newline() const
|
|---|
| 59 | {
|
|---|
| 60 | int g;
|
|---|
| 61 | do g=fgetc(f);
|
|---|
| 62 | while (g!=0x0A && g!=EOF);
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | int File::Geti(int cnt) const
|
|---|
| 66 | {
|
|---|
| 67 | char *c = new char[cnt+1];
|
|---|
| 68 | Gets(c, cnt);
|
|---|
| 69 | int result = atoi(c);
|
|---|
| 70 | delete c;
|
|---|
| 71 | return result;
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | float File::Getf(int cnt) const
|
|---|
| 75 | {
|
|---|
| 76 | char *c = new char[cnt+1];
|
|---|
| 77 | Gets(c, cnt);
|
|---|
| 78 | float result = atof(c);
|
|---|
| 79 | delete c;
|
|---|
| 80 | return result;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | void File::Skip(int cnt) const
|
|---|
| 84 | {
|
|---|
| 85 | char *c = new char[cnt+1];
|
|---|
| 86 | Gets(c, cnt);
|
|---|
| 87 | delete c;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.