spot  2.11.6
tmpfile.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2013, 2015, 2017 Laboratoire de Recherche et
3 // Développement de l'Epita (LRDE).
4 //
5 // This file is part of Spot, a model checking library.
6 //
7 // Spot is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Spot is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 
20 #pragma once
21 
22 #include <spot/misc/common.hh>
23 #include <new>
24 #include <stdexcept>
25 #include <iostream>
26 #include <list>
27 #include <spot/misc/formater.hh>
28 
29 namespace spot
30 {
33 
49  class SPOT_API temporary_file: public printable
50  {
51  public:
52  typedef std::list<temporary_file*>::iterator cleanpos_t;
53 
54  SPOT_LOCAL temporary_file(char* name, cleanpos_t cp);
55 
56  temporary_file(const temporary_file& other) = delete;
57 
58  virtual ~temporary_file() override;
59 
60  const char* name() const
61  {
62  return name_;
63  }
64 
65  friend std::ostream& operator<<(std::ostream& os, const temporary_file* f)
66  {
67  os << f->name();
68  return os;
69  }
70 
71  virtual void
72  print(std::ostream& os, const char*) const final override
73  {
74  os << this;
75  }
76 
77  protected:
78  char* name_;
79  cleanpos_t cleanpos_;
80  };
81 
89  class SPOT_API open_temporary_file final: public temporary_file
90  {
91  public:
92  SPOT_LOCAL open_temporary_file(char* name, cleanpos_t cp, int fd);
93  virtual ~open_temporary_file() override;
94 
95  void close();
96 
97  int fd() const
98  {
99  return fd_;
100  }
101 
102  protected:
103  int fd_;
104  };
105 
114  SPOT_API temporary_file*
115  create_tmpfile(const char* prefix, const char* suffix = nullptr);
116 
121  SPOT_API open_temporary_file*
122  create_open_tmpfile(const char* prefix, const char* suffix = nullptr);
123 
136  SPOT_API void
138 
140 }
Open temporary file.
Definition: tmpfile.hh:90
Definition: formater.hh:31
Temporary file name.
Definition: tmpfile.hh:50
Definition: automata.hh:27
void cleanup_tmpfiles()
Delete all temporary files.
open_temporary_file * create_open_tmpfile(const char *prefix, const char *suffix=nullptr)
Create a temporary file and leave it open for writing.
temporary_file * create_tmpfile(const char *prefix, const char *suffix=nullptr)
Create a temporary file.

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Fri Feb 27 2015 10:00:07 for spot by doxygen 1.9.1