GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/smt/managed_ostreams.h Lines: 4 10 40.0 %
Date: 2021-03-22 Branches: 0 2 0.0 %

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