slsdetectorgroup / aare

Data analysis library for PSI hybrid detectors
Other
0 stars 0 forks source link

add contextManager to hanldle files #27

Closed Bechir-Brahem closed 7 months ago

Bechir-Brahem commented 7 months ago

squash merge of PR #26

other solutions that can also be done: FileWrapper that takes File* and destroys it when out of scope,

erikfrojdh commented 7 months ago

Sorry I commented on the other PR first. Didn't realize that you it was based on this. My main question is what is the benefit of the contextManager compared to handle it on a file by file basis.

class File{
  FileInterface* m_fileptr;
public:
  File(filenam){/*open file*/}
  ~File(){{/*close file*/}
}

int main(){
  File f("/some/file.name", "r");
  // do stuff with the file
  // once the files goes out of scope it's closed
}
Bechir-Brahem commented 7 months ago

that's what I meant with the FileWrapper. The problem with it is that we will have to implement the FileInterface in it and whenever we change the interface we will have to change in the File wrapper.