26 #include <string_view> 29 #include <pstreams/pstream.h> 62 size_t readFile(
bool firstTime =
false);
71 Source(
const std::string& filePath) noexcept;
79 Source(
const std::string& program,
const std::vector<std::string>& arguments) noexcept;
99 const std::string&
path() const noexcept;
114 std::chrono::system_clock::time_point
timestamp() const noexcept;
133 bool reset() noexcept;
149 std::string_view::const_iterator
begin() const noexcept;
156 std::string_view::const_iterator
end() const noexcept;
164 std::string_view::const_iterator
getLine(
std::string_view::const_iterator
begin) const noexcept;
std::string_view contents_
Read-only view on the buffer_.
std::ifstream file_
For file sources, the file descriptor.
const std::string & path() const noexcept
Returns the file path or command to execute.
bool reset() noexcept
Resets the source: attempts to open the file or execute the command, allocates enough space for conte...
Class used to represent an expression (regex)
SourceType
Enum of existing source type.
std::string_view::const_iterator getLine(std::string_view::const_iterator begin) const noexcept
Returns an iterator to the end of the specified line.
std::vector< char > buffer_
Buffer for file contents or command output.
std::string_view::const_iterator begin() const noexcept
Returns the iterator to the beginning of the source's contents.
std::chrono::system_clock::time_point timestamp() const noexcept
Returns the timestamp of stored contents.
bool update() noexcept
Updates the source (read the file or execute command) and store the results.
redi::ipstream process_
For command sources, the child process.
std::vector< std::shared_ptr< Expression > > expressions_
Array of expressions used on the source's contents.
Class used to represent a source (file or command output) from which metrics can be matched...
std::string_view::const_iterator end() const noexcept
Returns the iterator to the end of the source's contents.
static std::vector< std::string > filePathsMatchingGlobbingPattern(const std::string &pattern) noexcept
Returns all file paths that match a pattern as defined by POSIX.
const std::vector< std::string > & pathParts() const noexcept
For file sources, returns the different parts of the file's path.
const std::string_view & contents() const noexcept
Returns the stored contents (file contents or command output)
SourceType type_
The type of the source.
std::chrono::system_clock::time_point timestamp_
Last contents or output fetching time.
std::vector< std::string > pathParts_
For file sources, the parts of the file's path.
Source(const std::string &filePath) noexcept
Construct a new Source object of file type.
std::string path_
Path of the file or command to execute.
size_t readFile(bool firstTime=false)
For file sources, put the file contents into the buffer_.
SourceType type()
Returns the source type.
std::vector< std::shared_ptr< Expression > > & expressions() noexcept
Returns the array of the receiver's expressions.
size_t executeCommand(bool firstTime=false)
For command sources, put the command output into the buffer_.