-
Notifications
You must be signed in to change notification settings - Fork 2
/
binarylexeme.h
71 lines (57 loc) · 2.42 KB
/
binarylexeme.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
#include <limits>
#include <memory>
#include <span>
#include <string_view>
#include <vector>
namespace bpatch
{
/// <summary>
/// class provides representation of a binary lexeme
/// </summary>
///
class AbstractBinaryLexeme final
{
AbstractBinaryLexeme(const AbstractBinaryLexeme&) = delete;
AbstractBinaryLexeme(AbstractBinaryLexeme&&) = delete;
AbstractBinaryLexeme& operator = (const AbstractBinaryLexeme&) = delete;
AbstractBinaryLexeme& operator = (AbstractBinaryLexeme&&) = delete;
public:
~AbstractBinaryLexeme() = default;
/// <summary>
/// replace inner part of data with new AbstractBinaryLexeme
/// </summary>
/// <param name="at">position of replacement</param>
/// <param name="alength">size of data to replace</param>
/// <param name="awith">data to set instead of replaced </param>
/// <returns>span for access Lexeme</returns>
const std::span<const char>& Replace(size_t at, size_t alength, std::unique_ptr<AbstractBinaryLexeme>& awith);
/// <summary>
/// provides the way of access the lexeme data for reading
/// </summary>
/// <returns>span for access Lexeme</returns>
const std::span<const char>& access() const {return access_;};
protected:
///@brief our data is here
std::vector<char> dataSequence_;
/// here we hold access to provide
std::span<const char> access_;
public:
// Way of construction:
/// @brief moves vector to BinaryLexeme and holds data inside
static std::unique_ptr<AbstractBinaryLexeme> LexemeFromVector(std::vector<char>&& asrcVec);
/// @brief creates a copy of data from a string view
static std::unique_ptr<AbstractBinaryLexeme> LexemeFromStringView(const std::string_view asrc);
/// @brief creates a copy of data from a span
static std::unique_ptr<AbstractBinaryLexeme> LexemeFromSpan(const std::span<const char> asrc);
/// @brief holds copy of source binary lexeme inside
/// up to the end or length provided as second parameter
static std::unique_ptr<AbstractBinaryLexeme> LexemeFromLexeme(
std::unique_ptr<AbstractBinaryLexeme>& source,
const size_t length = std::numeric_limits<size_t>::max());
protected:
///@brief An AbstractBinaryLexeme can only be created from an existing vector,
/// which will subsequently be held internally.
AbstractBinaryLexeme(std::vector<char>&& asrcVec);
}; // class AbstractBinaryLexeme
};// namespace bpatch