1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Tim King, Mathias Preiner, Gereon Kremer |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* Wrappers to handle memory management of ostreams. |
14 |
|
* |
15 |
|
* This file contains wrappers to handle special cases of managing memory |
16 |
|
* related to ostreams. |
17 |
|
*/ |
18 |
|
|
19 |
|
#include "cvc5_private.h" |
20 |
|
|
21 |
|
#ifndef CVC5__MANAGED_OSTREAMS_H |
22 |
|
#define CVC5__MANAGED_OSTREAMS_H |
23 |
|
|
24 |
|
#include <ostream> |
25 |
|
|
26 |
|
namespace cvc5 { |
27 |
|
|
28 |
|
class OstreamOpener; |
29 |
|
|
30 |
|
/** This abstracts the management of ostream memory and initialization. */ |
31 |
|
class ManagedOstream { |
32 |
|
public: |
33 |
|
/** Initially getManagedOstream() == NULL. */ |
34 |
|
ManagedOstream(); |
35 |
|
virtual ~ManagedOstream(); |
36 |
|
|
37 |
|
/** Returns the pointer to the managed ostream. */ |
38 |
70215 |
std::ostream* getManagedOstream() const { return d_managed; } |
39 |
|
|
40 |
|
/** Returns the name of the ostream geing managed. */ |
41 |
|
virtual const char* getName() const = 0; |
42 |
|
|
43 |
|
/** |
44 |
|
* Set opens a file with filename, initializes the stream. |
45 |
|
* If the opened ostream is marked as managed, this calls manage(stream). |
46 |
|
* If the opened ostream is not marked as managed, this calls manage(NULL). |
47 |
|
*/ |
48 |
|
void set(const std::string& filename); |
49 |
|
|
50 |
|
/** If this is associated with an option, return the string value. */ |
51 |
|
virtual std::string defaultSource() const { return ""; } |
52 |
|
|
53 |
|
protected: |
54 |
|
|
55 |
|
/** |
56 |
|
* Opens an ostream using OstreamOpener with the name getName() with the |
57 |
|
* special cases added by addSpecialCases(). |
58 |
|
*/ |
59 |
|
std::pair<bool, std::ostream*> open(const std::string& filename) const; |
60 |
|
|
61 |
|
/** |
62 |
|
* Updates the value of managed pointer. Whenever this changes, |
63 |
|
* beforeRelease() is called on the old value. |
64 |
|
*/ |
65 |
|
void manage(std::ostream* new_managed_value); |
66 |
|
|
67 |
|
/** Initializes an output stream. Not necessarily managed. */ |
68 |
|
virtual void initialize(std::ostream* outStream) {} |
69 |
|
|
70 |
|
/** Adds special cases to an ostreamopener. */ |
71 |
|
virtual void addSpecialCases(OstreamOpener* opener) const {} |
72 |
|
|
73 |
|
private: |
74 |
|
std::ostream* d_managed; |
75 |
|
}; /* class ManagedOstream */ |
76 |
|
|
77 |
|
/** |
78 |
|
* This controls the memory associated with --dump-to. |
79 |
|
* This is is assumed to recieve a set whenever diagnosticChannelName |
80 |
|
* is updated. |
81 |
|
*/ |
82 |
|
class ManagedDumpOStream : public ManagedOstream { |
83 |
|
public: |
84 |
10093 |
ManagedDumpOStream(){} |
85 |
|
~ManagedDumpOStream(); |
86 |
|
|
87 |
|
const char* getName() const override { return "dump-to"; } |
88 |
|
std::string defaultSource() const override; |
89 |
|
|
90 |
|
protected: |
91 |
|
/** Initializes an output stream. Not necessarily managed. */ |
92 |
|
void initialize(std::ostream* outStream) override; |
93 |
|
|
94 |
|
/** Adds special cases to an ostreamopener. */ |
95 |
|
void addSpecialCases(OstreamOpener* opener) const override; |
96 |
|
};/* class ManagedDumpOStream */ |
97 |
|
|
98 |
|
/** |
99 |
|
* When d_managedRegularChannel is non-null, it owns the memory allocated |
100 |
|
* with the regular-output-channel. This is set when |
101 |
|
* options::regularChannelName is set. |
102 |
|
*/ |
103 |
|
class ManagedRegularOutputChannel : public ManagedOstream { |
104 |
|
public: |
105 |
10093 |
ManagedRegularOutputChannel(){} |
106 |
|
|
107 |
|
/** Assumes Options are in scope. */ |
108 |
|
~ManagedRegularOutputChannel(); |
109 |
|
|
110 |
|
const char* getName() const override { return "regular-output-channel"; } |
111 |
|
std::string defaultSource() const override; |
112 |
|
|
113 |
|
protected: |
114 |
|
/** Initializes an output stream. Not necessarily managed. */ |
115 |
|
void initialize(std::ostream* outStream) override; |
116 |
|
|
117 |
|
/** Adds special cases to an ostreamopener. */ |
118 |
|
void addSpecialCases(OstreamOpener* opener) const override; |
119 |
|
};/* class ManagedRegularOutputChannel */ |
120 |
|
|
121 |
|
|
122 |
|
/** |
123 |
|
* This controls the memory associated with diagnostic-output-channel. |
124 |
|
* This is is assumed to recieve a set whenever options::diagnosticChannelName |
125 |
|
* is updated. |
126 |
|
*/ |
127 |
|
class ManagedDiagnosticOutputChannel : public ManagedOstream { |
128 |
|
public: |
129 |
10093 |
ManagedDiagnosticOutputChannel(){} |
130 |
|
|
131 |
|
/** Assumes Options are in scope. */ |
132 |
|
~ManagedDiagnosticOutputChannel(); |
133 |
|
|
134 |
|
const char* getName() const override { return "diagnostic-output-channel"; } |
135 |
|
std::string defaultSource() const override; |
136 |
|
|
137 |
|
protected: |
138 |
|
/** Initializes an output stream. Not necessarily managed. */ |
139 |
|
void initialize(std::ostream* outStream) override; |
140 |
|
|
141 |
|
/** Adds special cases to an ostreamopener. */ |
142 |
|
void addSpecialCases(OstreamOpener* opener) const override; |
143 |
|
};/* class ManagedRegularOutputChannel */ |
144 |
|
|
145 |
|
} // namespace cvc5 |
146 |
|
|
147 |
|
#endif /* CVC5__MANAGED_OSTREAMS_H */ |