Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1314 | runge | 1 | /* |
| 2 | * file.cpp |
||
| 3 | * |
||
| 4 | * Created on: Aug 04, 2009 |
||
| 5 | * Author: Mattias Runge |
||
| 6 | */ |
||
| 7 | |||
| 8 | #include "file.h" |
||
| 9 | |||
| 10 | namespace atom { |
||
| 11 | namespace file { |
||
| 12 | |||
| 13 | |||
| 14 | string get_contents(string filename) |
||
| 15 | { |
||
| 16 | ifstream srcfile(filename.c_str()); |
||
| 17 | |||
| 18 | if (!srcfile.is_open()) |
||
| 19 | { |
||
| 20 | srcfile.close(); |
||
| 21 | return ""; |
||
| 22 | } |
||
| 23 | |||
| 24 | string buffer = ""; |
||
| 25 | string line; |
||
| 26 | |||
| 27 | while (!srcfile.eof()) |
||
| 28 | { |
||
| 29 | getline(srcfile, line); |
||
| 30 | |||
| 31 | if (srcfile.eof()) break; |
||
| 32 | |||
| 33 | buffer += line + "\n"; |
||
| 34 | }; |
||
| 35 | |||
| 36 | srcfile.close(); |
||
| 37 | |||
| 38 | return buffer; |
||
| 39 | } |
||
| 40 | |||
| 41 | bool exists(string filename) |
||
| 42 | { |
||
| 43 | ifstream file(filename.c_str()); |
||
| 44 | if (file.is_open()) |
||
| 45 | { |
||
| 46 | file.close(); |
||
| 47 | return true; |
||
| 48 | } |
||
| 49 | |||
| 50 | return false; |
||
| 51 | } |
||
| 52 | |||
| 53 | |||
| 54 | } |
||
| 55 | } |