KeinMitleid

More Trainwreck Code

Jul 21st, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <fstream>
  2. #include <string>
  3.  
  4. class File {
  5. public:
  6.     enum { exist, notexist, notvalid };
  7.  
  8.     void open(const std::string& type, int binary, const std::string& name) {
  9.         if (name.find_last_of(type) == std::string::npos) _status = notvalid;
  10.         else {
  11.             if (binary) file.open(name.c_str(),
  12.                 std::fstream::in | std::fstream::out | std::fstream::binary);
  13.             else file.open(name.c_str(),
  14.                 std::fstream::in | std::fstream::out);
  15.  
  16.             if (!file.is_open()) _status = notexist;
  17.             else _status = exist;
  18.         }
  19.     }
  20.     void close() { file.close(); }
  21.     int status() { return _status; }
  22.  
  23. protected:
  24.     std::fstream file;
  25.     int _status;
  26. };
  27.  
  28. class VMF: public File {
  29. public:
  30.     VMF(const std::string& name) { open(".vmf", 0, name); }
  31. };
  32.  
  33. int main() {
  34.     VMF vmf("test.cpp");
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment