|
| Base64SigEncoder ()=default |
| Creates a new encoder, with an empty base64 string.
|
|
const std::string & | str () const & |
| Returns the base64 encoding that has been constructed thus far.
|
|
std::string && | str () && |
| Moves the base64 encoding that has been constructed thus far out of this encoder.
|
|
template<typename IntType > |
void | encodeSingle (IntType c) |
| Encodes the given 6-bit integer using a single base64 character.
|
|
int | encodeSize (size_t size) |
| Encodes the given non-negative integer (typically representing the size of some object), without knowing in advance how many base64 characters will be required.
|
|
template<typename IntType > |
void | encodeInt (IntType val, int nChars) |
| Encodes the given non-negative integer using a fixed number of base64 characters.
|
|
template<typename Iterator > |
void | encodeInts (Iterator begin, Iterator end, int nChars) |
| Encodes a sequence of non-negative integers, each using a fixed number of base64 characters.
|
|
template<typename Iterator > |
void | encodeTrits (Iterator beginTrits, Iterator endTrits) |
| Encodes a sequence of trits.
|
|
void | append (char c) |
| Appends the given character verbatim to this encoding.
|
|
| Base64SigEncoder (const Base64SigEncoder &)=delete |
|
Base64SigEncoder & | operator= (const Base64SigEncoder &)=delete |
|
A helper class for writing signatures that use base64 encodings.
These are (in particular) used in the default encodings for Regina's own isomorphism signatures and knot signatures.
To use this class: create a new Base64SigEncoder, call one or more of its member functions to write values to the encoding, and then call str() to extract the resulting base64 string.
This base64 encoding uses the characters: a..zA..Z0..9+-
Baes64 encoders are single-use objects: they cannot be copied, moved or swapped.
- Warning
- Note that this base64 encoding uses a different set of printable symbols from the encoding used in utilities/base64.h. This should not be a problem: Regina uses this encoding exclusively for signatures, and uses utilities/base64.h exclusively for encoding files.
template<typename IntType >
void regina::Base64SigEncoder::encodeInt |
( |
IntType | val, |
|
|
int | nChars ) |
|
inline |
Encodes the given non-negative integer using a fixed number of base64 characters.
Specifically, the integer val will be broken into nChars distinct 6-bit blocks, which will be encoded in order from lowest to highest significance.
The inverse to this routine is Base64SigDecoder::decodeInt().
- Exceptions
-
InvalidArgument | The given integer val is negative, or requires more than 6 × nChars bits. |
- Python
- The template argument IntType is taken to be a native C++
long
.
- Template Parameters
-
IntType | a native C++ integer type. |
- Parameters
-
val | the non-negative integer to encode. |
nChars | the number of base64 characters to use; typically this would be obtained through an earlier call to encodeSize(). |
template<typename Iterator >
void regina::Base64SigEncoder::encodeInts |
( |
Iterator | begin, |
|
|
Iterator | end, |
|
|
int | nChars ) |
|
inline |
Encodes a sequence of non-negative integers, each using a fixed number of base64 characters.
Each integer in the sequence will be encoded using encodeInt(). That is, each integer will be broken into nChars distinct 6-bit blocks, which will be encoded in order from lowest to highest significance.
The inverse to this routine is Base64SigDecoder::decodeInts().
- Exceptions
-
InvalidArgument | Some integer in the sequence is negative, or requires more than 6 × nChars bits. |
- Python
- Instead of a begin/end pair of iterators, this routine takes a Python sequence of integers. Each Python integer will be read as a native C++
long
.
- Template Parameters
-
Iterator | an input iterator which, when dereferenced, gives a native C++ integer type. |
- Parameters
-
begin | an iterator pointing to the first integer to encode. |
end | a past-the-end iterator pointing beyond the last integer to encode. |
nChars | the number of base64 characters to use for each integer; typically this would be obtained through an earlier call to encodeSize(). |
int regina::Base64SigEncoder::encodeSize |
( |
size_t | size | ) |
|
|
inline |
Encodes the given non-negative integer (typically representing the size of some object), without knowing in advance how many base64 characters will be required.
A typical use case would be where size represents the number of top-dimensional simplices in a triangulation, or the number of crossings in a link diagram.
This routine also computes the smallest integer b with the property that any integer x between 0 and size inclusive can be encoded using b base64 characters. In other words, any such x can be encoded by calling encodeInt(x, b)
. Typically these x would be indices into an object (e.g., top-dimensional simplex numbers, or crossing numbers). Note that encodeSize() itself might write more than b characters.
The inverse to this routine is Base64SigDecoder::decodeSize().
- Parameters
-
size | the non-negative integer to encode. |
- Returns
- nChars the number of base64 characters required to write any integer between 0 and size inclusive.
template<typename Iterator >
void regina::Base64SigEncoder::encodeTrits |
( |
Iterator | beginTrits, |
|
|
Iterator | endTrits ) |
|
inline |
Encodes a sequence of trits.
A trit is either 0, 1 or 2.
The trits will be packed into base64 characters, three at a time. For each individual base64 character, the three trits will use bits of the underlying 6-bit integer in order from lowest to highest significance. (The last base64 character might of course encode just one or two trits instead.)
Each trit will be obtained by dereferencing an iterator and casting to uint8_t
, and (as noted above) must take the value 0, 1 or 2.
The inverse to this routine is Base64SigDecoder::decodeTrits(), though that function only decodes three trits at a time.
- Python
- This routine takes a single argument, which is a Python sequence of integer trits.
- Template Parameters
-
Iterator | an input iterator which, when dereferenced, can be cast as a native C++ unsigned 8-bit integer (uint8_t ). |
- Parameters
-
beginTrits | an iterator pointing to the first trit to encode. |
endTrits | a past-the-end iterator pointing beyond the last trit to encode. |
char regina::Base64SigEncoder::spare[] = "_./" |
|
staticconstexpr |
A table of printable characters that are not amongst the base64 characters used by Base64SigEncoder and Base64SigDecoder.
These characters could (for example) be used to mark the boundaries of base64 blocks, or to indicate special cases.
These characters are presented as a string of length at least 3. Future versions of Regina may append new characters to the end of this string, but the existing characters spare[0..2]
will not change.