Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DiagnosticStream to QueryPlanner & ByteCodeInterpreter.
- Loading branch information
Showing
14 changed files
with
213 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,74 @@ | |||
#include "DiagnosticStream.h" | |||
#include "BitFunnel/Utilities/Factories.h" | |||
|
|||
|
|||
namespace BitFunnel | |||
{ | |||
std::unique_ptr<IDiagnosticStream> Factories::CreateDiagnosticStream(std::ostream& stream) | |||
{ | |||
return std::unique_ptr<IDiagnosticStream>(new DiagnosticStream(stream)); | |||
} | |||
|
|||
|
|||
DiagnosticStream::DiagnosticStream(std::ostream& stream) | |||
: m_stream(stream) | |||
{ | |||
} | |||
|
|||
|
|||
void DiagnosticStream::Enable(char const * diagnostic) | |||
{ | |||
// TODO: REVIEW: check for duplicates? | |||
m_enabled.push_back(diagnostic); | |||
} | |||
|
|||
|
|||
void DiagnosticStream::Disable(char const * diagnostic) | |||
{ | |||
// TODO: REVIEW: check for mismatch? | |||
for (unsigned i = 0 ; i < m_enabled.size(); ++i) | |||
{ | |||
if (m_enabled[i].compare(diagnostic) == 0) | |||
{ | |||
m_enabled.erase(m_enabled.begin() + i); | |||
|
|||
// TODO: REVIEW: Assuming there is only one to remove. | |||
break; | |||
} | |||
} | |||
} | |||
|
|||
|
|||
// Returns true if text starts with prefix. | |||
bool StartsWith(char const * text, std::string const & prefix) | |||
{ | |||
for (unsigned i = 0 ; i < prefix.size(); ++i) | |||
{ | |||
if (*text != prefix[i]) | |||
{ | |||
return false; | |||
} | |||
++text; | |||
} | |||
return true; | |||
} | |||
|
|||
|
|||
bool DiagnosticStream::IsEnabled(char const * diagnostic) const | |||
{ | |||
for (unsigned i = 0; i < m_enabled.size(); ++i) | |||
{ | |||
if (StartsWith(diagnostic, m_enabled[i])) | |||
{ | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
|
|||
|
|||
std::ostream& DiagnosticStream::GetStream() | |||
{ | |||
return m_stream; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,49 @@ | |||
#pragma once | |||
|
|||
#include <string> // Embeds std::string. | |||
#include <vector> // Embeds std::vector. | |||
|
|||
#include "BitFunnel/IDiagnosticStream.h" // Inherits from IDiagnosticStream. | |||
#include "BitFunnel/NonCopyable.h" // Inherits from NonCopyable. | |||
|
|||
|
|||
namespace BitFunnel | |||
{ | |||
//************************************************************************* | |||
// | |||
// DiagnosticStream implements the IDiagnosticStream interface to provice | |||
// an std::ostream used to output diagnostic information. | |||
// | |||
// DiagnosticStream maintains a list of diagnostic keyword prefixes that | |||
// enable diagnostics for various parts of the system. Code with the | |||
// ability to emit diagnostic information should use the IsEnabled() method | |||
// to determine whether to actually write to the diagnostic stream. | |||
// | |||
//************************************************************************* | |||
class DiagnosticStream : public IDiagnosticStream, NonCopyable | |||
{ | |||
public: | |||
// Constructs a DiagnosticStream that outputs to the specified stream. | |||
DiagnosticStream(std::ostream& stream); | |||
|
|||
// Adds the diagnostic keyword prefix to the list of prefixes that | |||
// enable diagnostics. | |||
void Enable(char const * diagnostic); | |||
|
|||
// Removes the diagnostic keyword prefix from the list of prefixes | |||
// that enable diagnostics. | |||
void Disable(char const * diagnostic); | |||
|
|||
// Returns true if the diagnostic keyword begins with one of the | |||
// prefixes. | |||
bool IsEnabled(char const * diagnostic) const; | |||
|
|||
// Returns a reference to the stream used for diagnostic output. | |||
std::ostream& GetStream(); | |||
|
|||
private: | |||
std::ostream& m_stream; | |||
|
|||
std::vector<std::string> m_enabled; | |||
}; | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.