std::string optFormulaFilename("cvc4-optimized-formula-XXXXXX");
{
- std::fstream formStream = openTmpFile(&formulaFilename);
- const int64_t startPos = static_cast<int64_t>(formStream.tellp());
- printDimacs(formStream, d_clauses, d_originalClauseIndices);
+ std::unique_ptr<std::fstream> formStream = openTmpFile(&formulaFilename);
+ const int64_t startPos = static_cast<int64_t>(formStream->tellp());
+ printDimacs(*formStream, d_clauses, d_originalClauseIndices);
d_dratOptimizationStatistics.d_initialFormulaSize.setData(
- static_cast<int64_t>(formStream.tellp()) - startPos);
- formStream.close();
+ static_cast<int64_t>(formStream->tellp()) - startPos);
+ formStream->close();
}
{
- std::fstream dratStream = openTmpFile(&dratFilename);
- const int64_t startPos = static_cast<int64_t>(dratStream.tellp());
- dratStream << d_binaryDratProof.str();
+ std::unique_ptr<std::fstream> dratStream = openTmpFile(&dratFilename);
+ const int64_t startPos = static_cast<int64_t>(dratStream->tellp());
+ (*dratStream) << d_binaryDratProof.str();
d_dratOptimizationStatistics.d_initialDratSize.setData(
- static_cast<int64_t>(dratStream.tellp()) - startPos);
- dratStream.close();
+ static_cast<int64_t>(dratStream->tellp()) - startPos);
+ dratStream->close();
}
- std::fstream optDratStream = openTmpFile(&optDratFilename);
- std::fstream optFormulaStream = openTmpFile(&optFormulaFilename);
+ std::unique_ptr<std::fstream> optDratStream = openTmpFile(&optDratFilename);
+ std::unique_ptr<std::fstream> optFormulaStream =
+ openTmpFile(&optFormulaFilename);
#if CVC4_USE_DRAT2ER
{
std::vector<prop::SatClause> core = parseDimacs(optFormulaStream);
d_dratOptimizationStatistics.d_optimizedFormulaSize.setData(
static_cast<int64_t>(optFormulaStream.tellg()) - startPos);
- optFormulaStream.close();
CodeTimer clauseMatchingTimer{
d_dratOptimizationStatistics.d_clauseMatchingTime};
d_coreClauseIndices = d_originalClauseIndices;
}
- optFormulaStream.close();
+ optFormulaStream->close();
Assert(d_coreClauseIndices.size() > 0);
remove(formulaFilename.c_str());
std::string tracecheckFilename("cvc4-tracecheck-er-XXXXXX");
// Write the formula
- std::fstream formStream = openTmpFile(&formulaFilename);
- printDimacs(formStream, clauses, usedIds);
- formStream.close();
+ std::unique_ptr<std::fstream> formStream = openTmpFile(&formulaFilename);
+ printDimacs(*formStream, clauses, usedIds);
+ formStream->close();
// Write the (binary) DRAT proof
- std::fstream dratStream = openTmpFile(&dratFilename);
- dratStream << dratBinary;
- dratStream.close();
+ std::unique_ptr<std::fstream> dratStream = openTmpFile(&dratFilename);
+ (*dratStream) << dratBinary;
+ dratStream->close();
- std::fstream tracecheckStream = openTmpFile(&tracecheckFilename);
+ std::unique_ptr<std::fstream> tracecheckStream =
+ openTmpFile(&tracecheckFilename);
// Invoke drat2er
{
}
// Parse the resulting TRACECHECK proof into an ER proof.
- TraceCheckProof pf = TraceCheckProof::fromText(tracecheckStream);
+ TraceCheckProof pf = TraceCheckProof::fromText(*tracecheckStream);
ErProof proof(clauses, usedIds, std::move(pf));
- tracecheckStream.close();
+ tracecheckStream->close();
remove(formulaFilename.c_str());
remove(dratFilename.c_str());
std::string dratFilename("cvc4-drat-XXXXXX");
std::string lratFilename("cvc4-lrat-XXXXXX");
- std::fstream formStream = openTmpFile(&formulaFilename);
- printDimacs(formStream, clauses, usedIds);
- formStream.close();
+ std::unique_ptr<std::fstream> formStream = openTmpFile(&formulaFilename);
+ printDimacs(*formStream, clauses, usedIds);
+ formStream->close();
- std::fstream dratStream = openTmpFile(&dratFilename);
- dratStream << dratBinary;
- dratStream.close();
+ std::unique_ptr<std::fstream> dratStream = openTmpFile(&dratFilename);
+ (*dratStream) << dratBinary;
+ dratStream->close();
- std::fstream lratStream = openTmpFile(&lratFilename);
+ std::unique_ptr<std::fstream> lratStream = openTmpFile(&lratFilename);
{
CodeTimer blockTimer{toolTimer};
#endif
}
- LratProof lrat(lratStream);
+ LratProof lrat(*lratStream);
remove(formulaFilename.c_str());
remove(dratFilename.c_str());
remove(lratFilename.c_str());
namespace CVC4 {
-std::fstream openTmpFile(std::string* pattern)
+std::unique_ptr<std::fstream> openTmpFile(std::string* pattern)
{
char* tmpDir = getenv("TMPDIR");
if (tmpDir != nullptr)
{
CVC4_FATAL() << "Could not create temporary file " << *pattern;
}
- std::fstream tmpStream(tmpName);
+ std::unique_ptr<std::fstream> tmpStream(new std::fstream(tmpName));
close(r);
*pattern = std::string(tmpName);
delete[] tmpName;
#include <algorithm>
#include <fstream>
#include <functional>
+#include <memory>
#include <string>
#include <utility>
* @param pattern The filename pattern. This string is modified to contain the
* name of the temporary file.
*
- * @return A filestream for the temporary file.
+ * @return A unique pointer to the filestream for the temporary file.
+ *
+ * Note: We use `std::unique_ptr<std::fstream>` instead of `std::fstream`
+ * because GCC < 5 does not support the move constructor of `std::fstream`. See
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316 for details.
*/
-std::fstream openTmpFile(std::string* pattern);
+std::unique_ptr<std::fstream> openTmpFile(std::string* pattern);
}/* CVC4 namespace */