spot  2.16
tmpfile.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) by the Spot authors, see the AUTHORS file for details.
3 //
4 // This file is part of Spot, a model checking library.
5 //
6 // Spot is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // Spot is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 // License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 #pragma once
20 
21 #include <spot/misc/common.hh>
22 #include <new>
23 #include <stdexcept>
24 #include <iostream>
25 #include <list>
26 #include <spot/misc/formater.hh>
27 
28 namespace spot
29 {
32 
48  class SPOT_API temporary_file: public printable
49  {
50  public:
52  typedef std::list<temporary_file*>::iterator cleanpos_t;
53 
55  SPOT_LOCAL temporary_file(char* name, cleanpos_t cp);
56 
57  temporary_file(const temporary_file& other) = delete;
58 
60  virtual ~temporary_file() override;
61 
63  const char* name() const
64  {
65  return name_;
66  }
67 
69  friend std::ostream& operator<<(std::ostream& os, const temporary_file* f)
70  {
71  os << f->name();
72  return os;
73  }
74 
76  virtual void
77  print(std::ostream& os, const char*) const final override
78  {
79  os << this;
80  }
81 
82  protected:
83  char* name_;
85  };
86 
94  class SPOT_API open_temporary_file final: public temporary_file
95  {
96  public:
98  SPOT_LOCAL open_temporary_file(char* name, cleanpos_t cp, int fd);
100  virtual ~open_temporary_file() override;
101 
103  void close();
104 
106  int fd() const
107  {
108  return fd_;
109  }
110 
111  protected:
112  int fd_;
113  };
114 
123  SPOT_API temporary_file*
124  create_tmpfile(const char* prefix, const char* suffix = nullptr);
125 
130  SPOT_API open_temporary_file*
131  create_open_tmpfile(const char* prefix, const char* suffix = nullptr);
132 
145  SPOT_API void
147 
149 }
Open temporary file.
Definition: tmpfile.hh:95
void close()
Close the file descriptor.
SPOT_LOCAL open_temporary_file(char *name, cleanpos_t cp, int fd)
Build an open temporary file wrapper.
virtual ~open_temporary_file() override
Destroy the temporary file and close the descriptor.
int fd_
File descriptor.
Definition: tmpfile.hh:112
int fd() const
Return the file descriptor.
Definition: tmpfile.hh:106
Abstract base class for objects that can be printed to a stream via a format string.
Definition: formater.hh:35
Temporary file name.
Definition: tmpfile.hh:49
virtual ~temporary_file() override
Destroy the temporary file.
const char * name() const
Return the file name.
Definition: tmpfile.hh:63
std::list< temporary_file * >::iterator cleanpos_t
Iterator position in the cleanup list.
Definition: tmpfile.hh:52
friend std::ostream & operator<<(std::ostream &os, const temporary_file *f)
Stream the file name.
Definition: tmpfile.hh:69
SPOT_LOCAL temporary_file(char *name, cleanpos_t cp)
Build a temporary file wrapper.
cleanpos_t cleanpos_
Cleanup-list position.
Definition: tmpfile.hh:84
char * name_
File name.
Definition: tmpfile.hh:83
virtual void print(std::ostream &os, const char *) const final override
Print the file name.
Definition: tmpfile.hh:77
Definition: automata.hh:26
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