/usr/include/wreport/opcodes.h is in libwreport-dev 3.6-1build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | #ifndef WREPORT_OPCODE_H
#define WREPORT_OPCODE_H
#include <wreport/varinfo.h>
#include <wreport/error.h>
#include <vector>
#include <cstdio>
namespace wreport {
/**
* Sequence of opcodes, as a slice of a Varcode vector.
*
* This is used for BUFR and CREX encoding and decoding.
*
* It can be considered as a sort of subroutine to be interpreted by the
* encoders/decoders.
*/
struct Opcodes
{
/// First element of the varcode sequence
const Varcode* begin;
/// One-past-the-last element of the varcode sequence
const Varcode* end;
/// Sequence spanning the whole vector
Opcodes(const std::vector<Varcode>& vals) : begin(vals.data()), end(begin + vals.size()) {}
/// Sequence from begin (inclusive) to end (excluded)
Opcodes(const Varcode* begin, const Varcode* end)
: begin(begin), end(end) {}
Opcodes(const Opcodes& o) = default;
Opcodes& operator=(const Opcodes& o) = default;
/// Return the i-th varcode in the chain
Varcode operator[](unsigned i) const
{
if (begin + i > end)
return 0;
else
return begin[i];
}
/// Number of items in this opcode list
unsigned size() const { return end - begin; }
/// True if there are no opcodes
bool empty() const { return begin == end; }
/**
* Return the first element and advance begin to the next one.
*
* If the sequence is empty, throw an exception
*/
Varcode pop_left()
{
if (empty()) throw error_consistency("cannot do pop_left on an empty opcode sequence");
return *begin++;
}
/**
* Return the first \a count elements and advance begin to the first opcode
* after the sequence.
*
* If the sequence has less that \a count elements, throw an exception
*/
Opcodes pop_left(unsigned count)
{
if (size() < count)
error_consistency::throwf("cannot do pop_left(%u) on an opcode sequence of only %u elements", count, size());
Opcodes res(begin, begin + count);
begin += count;
return res;
}
/// First opcode in the list (0 if the list is empty)
Varcode head() const
{
if (begin == end)
return 0;
return *begin;
}
/**
* List of all opcodes after the first one
*
* If the list is empty, return the empty list
*/
Opcodes next() const
{
if (begin == end)
return *this;
else
return Opcodes(begin+1, end);
}
/// Return the opcodes from \a skip until the end
Opcodes sub(unsigned skip) const
{
if (begin + skip > end)
return Opcodes(end, end);
else
return Opcodes(begin + skip, end);
}
/// Return \a len opcodes starting from \a skip
Opcodes sub(unsigned skip, unsigned len) const
{
if (begin + skip > end)
return Opcodes(end, end);
else if (begin + skip + len >= end)
return Opcodes(begin + skip, end);
else
return Opcodes(begin + skip, begin + skip + len);
}
/// Print the contents of this opcode list
void print(FILE* out) const;
};
}
#endif
|