Advertisement
theultraman20

Untitled

Oct 8th, 2024
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1.  
  2.  
  3.  
  4. template<typename T> PDB<T>::PDB(std::string filename) {
  5.     std::ifstream is(filename, std::ios::binary);
  6.     //I prefer !good instead of bad because
  7.     //I try to stay positive
  8.     if (!is.good()) { throw std::exception(); }
  9.  
  10.     uint32_t size;
  11.     is >> size;
  12.  
  13.     //saw this one on SO
  14.     std::vector<uint8_t> bytes(
  15.           (std::istreambuf_iterator<char>(is)),
  16.           (std::istreambuf_iterator<char>()));
  17.  
  18.     if (!is.good()) { throw std::exception(); }
  19.     is.close();
  20.  
  21.     data = bytes;
  22. }
  23.  
  24. template<typename T> PDB<T>::serialize(std::string filename) {
  25.     std::ofstream os(filename, std::ios::binary);
  26.     if (!is.good()) { throw std::exception(); }
  27.  
  28.     std::copy(data.begin(), data.end(), std::ostreambuf_iterator<uint8_t>(os));
  29.     if (!os.good()) { throw std::exception(); }
  30. };
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement