Esempio n. 1
0
 void file::write(types::str const &str)
 {
   if (not is_open)
     throw ValueError("I/O operation on closed file");
   if (mode.find_first_of("wa+") == -1)
     throw IOError("file.write() :  File not opened for writing.");
   fwrite(str.c_str(), sizeof(char), str.size(), **data);
 }
Esempio n. 2
0
    // Modifiers
    void file::open(types::str const &filename, types::str const &strmode)
    {
      const char *smode = strmode.c_str();
      // Python enforces that the mode, after stripping 'U', begins with 'r',
      // 'w' or 'a'.
      if (*smode == 'U') {
        ++smode;
      } // Not implemented yet

      data = utils::shared_ref<container_type>(filename, smode);
      if (not**data)
        throw types::IOError("Couldn't open file " + filename);
      is_open = true;
    }
Esempio n. 3
0
 _file::_file(types::str const &filename, types::str const &strmode)
     : f(fopen(filename.c_str(), strmode.c_str())), _buffer(nullptr),
       _buffer_size(0)
 {
 }
Esempio n. 4
0
 // TODO : no check on file existance?
 _file::_file(types::str const &filename, types::str const &strmode)
     : f(fopen(filename.c_str(), strmode.c_str()))
 {
 }