mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
bytecode_ptr: some small improvements
This commit is contained in:
parent
a197074c5d
commit
67779e0c0a
@ -35,7 +35,9 @@
|
|||||||
#define UTIL_BYTECODE_PTR_H
|
#define UTIL_BYTECODE_PTR_H
|
||||||
|
|
||||||
#include "util/alloc.h"
|
#include "util/alloc.h"
|
||||||
|
#include "util/operators.h"
|
||||||
|
|
||||||
|
#include <algorithm> // std::max
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@ -47,7 +49,7 @@ namespace ue2 {
|
|||||||
* This is intended to be used for flat aligned memory regions that will
|
* This is intended to be used for flat aligned memory regions that will
|
||||||
* eventually end up copied into the Hyperscan bytecode.
|
* eventually end up copied into the Hyperscan bytecode.
|
||||||
*/
|
*/
|
||||||
template<typename T> class bytecode_ptr {
|
template<typename T> class bytecode_ptr : totally_ordered<bytecode_ptr<T>> {
|
||||||
public:
|
public:
|
||||||
bytecode_ptr() = default;
|
bytecode_ptr() = default;
|
||||||
explicit bytecode_ptr(size_t size, size_t align = alignof(T))
|
explicit bytecode_ptr(size_t size, size_t align = alignof(T))
|
||||||
@ -83,6 +85,13 @@ public:
|
|||||||
|
|
||||||
void reset(T *p = nullptr) { ptr.reset(p); }
|
void reset(T *p = nullptr) { ptr.reset(p); }
|
||||||
|
|
||||||
|
T *release() {
|
||||||
|
auto *p = ptr.release();
|
||||||
|
bytes = 0;
|
||||||
|
alignment = 0;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
void swap(bytecode_ptr &other) {
|
void swap(bytecode_ptr &other) {
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(ptr, other.ptr);
|
swap(ptr, other.ptr);
|
||||||
@ -97,11 +106,7 @@ public:
|
|||||||
size_t align() const { return alignment; }
|
size_t align() const { return alignment; }
|
||||||
|
|
||||||
bool operator==(const bytecode_ptr &a) const { return ptr == a.ptr; }
|
bool operator==(const bytecode_ptr &a) const { return ptr == a.ptr; }
|
||||||
bool operator!=(const bytecode_ptr &a) const { return ptr != a.ptr; }
|
|
||||||
bool operator<(const bytecode_ptr &a) const { return ptr < a.ptr; }
|
bool operator<(const bytecode_ptr &a) const { return ptr < a.ptr; }
|
||||||
bool operator<=(const bytecode_ptr &a) const { return ptr <= a.ptr; }
|
|
||||||
bool operator>(const bytecode_ptr &a) const { return ptr > a.ptr; }
|
|
||||||
bool operator>=(const bytecode_ptr &a) const { return ptr >= a.ptr; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** \brief Deleter function for std::unique_ptr. */
|
/** \brief Deleter function for std::unique_ptr. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user