Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions guides/cpp_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,13 @@
- Enum values use `CamelCase`.
- Mark non-inheritable classes with `final`.
- Use `override` for overridden virtual methods.

## Semantic values

- Avoid magic numbers: do not leave unnamed numbers such as `0xD0` when the meaning is not obvious.
- Avoid magic literals: apply the same rule to strings, bytes, characters, regexes, paths, and flags.
- Use intention-revealing names: the name should explain the value role, such as `invalid_utf8_leading_byte` instead of `byte`.
- Make invalid and edge cases explicit: test data for errors should state which error it validates.
- Prefer named constants for semantic values: if a value has domain meaning, give it a name.
- Separate data meaning from representation: `0xD0` is representation; truncated UTF-8 leading byte is meaning.
- Follow the Principle of Least Astonishment: readers should not have to guess why a specific byte or literal was chosen.
49 changes: 49 additions & 0 deletions include/logit_cpp/logit/loggers/ILogReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <cstdint>
#include <string>
#include <vector>
#if __cplusplus >= 201703L
#include <optional>
#endif

namespace logit {

Expand All @@ -34,6 +37,28 @@ namespace logit {
Descending ///< Newest first.
};

#if __cplusplus >= 201703L
/// \enum LogReadError
/// \brief Result status for log read APIs that preserve failure details.
enum class LogReadError {
None,
NotFound,
StorageError,
DecodeError,
UnsupportedVersion,
DecompressionError
};

/// \struct LogReadResult
/// \brief Value-or-error result returned by detailed log read APIs.
template <typename T>
struct LogReadResult {
std::optional<T> value; ///< Present when the read succeeded with a value.
LogReadError error = LogReadError::None; ///< Error status, or None on success.
std::string message; ///< Optional diagnostic message for failed reads.
};
#endif

/// \class ILogReader
/// \brief Optional interface for backends that expose stored records.
///
Expand All @@ -54,6 +79,18 @@ namespace logit {
int64_t to_ms,
std::size_t limit = 0) const = 0;

#if __cplusplus >= 201703L
/// \brief Reads records and preserves backend-specific read errors.
virtual LogReadResult<std::vector<LogRecordView>> read_range_result(
int64_t from_ms,
int64_t to_ms,
std::size_t limit = 0) const {
LogReadResult<std::vector<LogRecordView>> result;
result.value = read_range(from_ms, to_ms, limit);
return result;
}
#endif

/// \brief Reads the most recent records.
/// \param limit Maximum number of records (0 = unlimited).
/// \param period_ms Time window in milliseconds from now backward (0 = unlimited).
Expand All @@ -63,6 +100,18 @@ namespace logit {
std::size_t limit,
int64_t period_ms = 0,
LogReadOrder order = LogReadOrder::Ascending) const = 0;

#if __cplusplus >= 201703L
/// \brief Reads recent records and preserves backend-specific read errors.
virtual LogReadResult<std::vector<LogRecordView>> read_recent_result(
std::size_t limit,
int64_t period_ms = 0,
LogReadOrder order = LogReadOrder::Ascending) const {
LogReadResult<std::vector<LogRecordView>> result;
result.value = read_recent(limit, period_ms, order);
return result;
}
#endif
};

} // namespace logit
Expand Down
Loading
Loading