Skip to content

Commit

Permalink
Usability improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-kirienko committed Mar 8, 2018
1 parent f855729 commit c11ffb3
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions legilimens.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ class Name
public:
constexpr Chunks() { }

template <typename... EncodedBlockTypes>
constexpr Chunks(EncodedBlockTypes... encoded_blocks) :
chunks_{encoded_blocks...}
template <typename... EncodedChunkTypes>
explicit constexpr Chunks(EncodedChunkTypes... encoded_chunks) :
chunks_{encoded_chunks...}
{
static_assert(sizeof...(EncodedBlockTypes) == NumberOfChunks, "Wrong number of arguments");
static_assert(sizeof...(EncodedChunkTypes) == NumberOfChunks, "Wrong number of arguments");
}

constexpr EncodedChunk& operator[](const std::size_t index)
Expand Down Expand Up @@ -207,16 +207,16 @@ class Name
chunks_(encode(name))
{ }

explicit Name(const senoval::String<MaxLength>& name) :
template <std::size_t Capacity>
explicit Name(const senoval::String<Capacity>& name) :
chunks_(encode(name.c_str()))
{ }

template <typename... EncodedBlockTypes>
explicit constexpr Name(EncodedBlockTypes... encoded_blocks) :
chunks_(std::forward<EncodedBlockTypes>(encoded_blocks)...)
{
static_assert(sizeof...(EncodedBlockTypes) == NumberOfChunks, "Wrong number of arguments");
}
/// The first argument is typed explicitly in order to prevent ambiguity with String constructors
template <typename... EncodedChunkTypes>
explicit constexpr Name(const EncodedChunk head, EncodedChunkTypes... tail) :
chunks_(head, tail...)
{ }

[[nodiscard]] bool operator==(const Name& rhs) const { return chunks_ == rhs.chunks_; }
[[nodiscard]] bool operator!=(const Name& rhs) const { return chunks_ != rhs.chunks_; }
Expand Down Expand Up @@ -526,6 +526,12 @@ static inline void copyBytesQuicklyAndUnsafely(std::size_t size,

} // namespace impl_

/**
* Alias for a fixed-capacity stack-backed vector of bytes that is used to keep sampled data.
* An empty vector is used to represent un-sampleable variable.
*/
using SampledBytes = senoval::Vector<std::uint8_t, MaxVariableSize>;

/**
* A runtime (i.e. non statically typed) descriptor of a probe.
* There is one instance of Category per probe name and type.
Expand Down Expand Up @@ -637,11 +643,11 @@ class Category
* Collects the data from the variable and returns it as an array of bytes.
* Returns an empty array if no such variable exists at this moment.
*/
[[nodiscard]] senoval::Vector<std::uint8_t, MaxVariableSize> sample() const
[[nodiscard]] SampledBytes sample() const
{
const std::size_t data_size = type_descriptor_.element_size * type_descriptor_.number_of_elements;
assert(data_size <= MaxVariableSize); // The size constraint is imposed at compile time also
senoval::Vector<std::uint8_t, MaxVariableSize> out(data_size, 0);
SampledBytes out(data_size, 0);
bool success = false;

// The critical section must be as short as possible!
Expand Down

0 comments on commit c11ffb3

Please sign in to comment.