Regina 7.4 Calculation Engine
regina::Base64SigEncoder Class Reference

A helper class for writing signatures that use base64 encodings. More...

#include <utilities/sigutils.h>

Public Member Functions

 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
 
Base64SigEncoderoperator= (const Base64SigEncoder &)=delete
 

Static Public Attributes

static constexpr char spare [] = "_./"
 A table of printable characters that are not amongst the base64 characters used by Base64SigEncoder and Base64SigDecoder.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Base64SigEncoder()

regina::Base64SigEncoder::Base64SigEncoder ( )
default

Creates a new encoder, with an empty base64 string.

Member Function Documentation

◆ append()

void regina::Base64SigEncoder::append ( char c)
inline

Appends the given character verbatim to this encoding.

Parameters
cthe character to append. This need not be one of the 64 characters used in this base64 encoding; however, ideally it should be printable.

◆ encodeInt()

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
InvalidArgumentThe 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
IntTypea native C++ integer type.
Parameters
valthe non-negative integer to encode.
nCharsthe number of base64 characters to use; typically this would be obtained through an earlier call to encodeSize().

◆ encodeInts()

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
InvalidArgumentSome 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
Iteratoran input iterator which, when dereferenced, gives a native C++ integer type.
Parameters
beginan iterator pointing to the first integer to encode.
enda past-the-end iterator pointing beyond the last integer to encode.
nCharsthe number of base64 characters to use for each integer; typically this would be obtained through an earlier call to encodeSize().

◆ encodeSingle()

template<typename IntType >
void regina::Base64SigEncoder::encodeSingle ( IntType c)
inline

Encodes the given 6-bit integer using a single base64 character.

The inverse to this routine is Base64SigDecoder::decodeSingle().

Exceptions
InvalidArgumentThe given integer is not between 0 and 63 inclusive.
Python
The template argument IntType is taken to be a native C++ long.
Template Parameters
IntTypea native C++ integer type.
Parameters
can integer between 0 and 63 inclusive.

◆ 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
sizethe non-negative integer to encode.
Returns
nChars the number of base64 characters required to write any integer between 0 and size inclusive.

◆ encodeTrits()

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
Iteratoran input iterator which, when dereferenced, can be cast as a native C++ unsigned 8-bit integer (uint8_t).
Parameters
beginTritsan iterator pointing to the first trit to encode.
endTritsa past-the-end iterator pointing beyond the last trit to encode.

◆ str() [1/2]

std::string && regina::Base64SigEncoder::str ( ) &&
inline

Moves the base64 encoding that has been constructed thus far out of this encoder.

After calling this function, this encoder object will be unusable.

Python
Not present. Instead use the variant of str() that returns its string by constant reference.
Returns
The current base64 encoding.

◆ str() [2/2]

const std::string & regina::Base64SigEncoder::str ( ) const &
inline

Returns the base64 encoding that has been constructed thus far.

Returns
The current base64 encoding.

Member Data Documentation

◆ spare

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.


The documentation for this class was generated from the following file: