IODA Bundle
TemporaryFiles.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 #ifndef odc_tests_TemporaryODB_H
12 #define odc_tests_TemporaryODB_H
13 
14 #include "eckit/filesystem/PathName.h"
15 
16 #include "odc/Writer.h"
17 
18 //----------------------------------------------------------------------------------------------------------------------
19 
20 /// A class to be used as a fixture, which writes a temporary ODB file using the supplied
21 /// initialisation function, and then ensures that it is correctly cleaned up at the
22 /// end of the test.
23 
24 
26 
27 public: // methods
28 
30  path_(eckit::PathName::unique("_temporary_testing_file")) {}
31 
32  virtual ~TemporaryFile() {
33  if (path_.exists()) {
34  path_.unlink();
35  }
36  }
37 
38  const eckit::PathName& path() const { return path_; }
39 
40 private: // members
41 
42  eckit::PathName path_;
43 };
44 
45 
46 //----------------------------------------------------------------------------------------------------------------------
47 
48 #endif // odc_tests_TemporaryODB_H
eckit::PathName path_
virtual ~TemporaryFile()
const eckit::PathName & path() const