Regina 7.3 Calculation Engine
Static Public Member Functions | List of all members
regina::Base64SigEncoding Struct Reference

General helper tools for signatures that use base64 encodings. More...

#include <utilities/sigutils.h>

Inheritance diagram for regina::Base64SigEncoding:
regina::IsoSigPrintable< dim >

Static Public Member Functions

static constexpr unsigned decodeSingle (char c)
 Determine the integer value represented by the given base64 character. More...
 
static constexpr char encodeSingle (unsigned c)
 Determine the base64 character that represents the given integer value. More...
 
static constexpr bool isValid (char c)
 Is the given character a valid base64 character? More...
 
template<typename IntType >
static void encodeInt (std::string &s, IntType val, unsigned nChars)
 Append a base64 encoding of the given integer to the given string. More...
 
template<typename IntType >
static IntType decodeInt (const char *s, unsigned nChars)
 Read the integer that is encoded at the beginning of the given base64 string. More...
 
template<typename InputIterator >
static char encodeTrits (InputIterator trits, unsigned nTrits)
 Returns a single base64 character that encodes up to three trits, given using an input iterator. More...
 
template<int nTrits>
static constexpr char encodeTrits (const std::array< uint8_t, nTrits > &trits)
 Returns a single base64 character that encodes up to three trits, given using a fixed-size array. More...
 
template<typename OutputIterator >
static void decodeTrits (char c, OutputIterator result)
 Decodes a single base64 character into three trits, and returns these using an output iterator. More...
 
static constexpr std::array< uint8_t, 3 > decodeTrits (char c)
 Decodes a single base64 character into three trits, and returns these as a fixed-size array. More...
 

Detailed Description

General helper tools for signatures that use base64 encodings.

These are (in particular) used in the default encodings for Regina's own isomorphism signatures and knot signatures.

This base64 encoding uses the characters: a..zA..Z0..9+-

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.

Member Function Documentation

◆ decodeInt()

template<typename IntType >
static IntType regina::Base64SigEncoding::decodeInt ( const char *  s,
unsigned  nChars 
)
inlinestatic

Read the integer that is encoded at the beginning of the given base64 string.

It will be assumed that the integer is encoded using nChars base64 characters, each containing 6 bits of the integer, with the lowest-significance bits encoded in the first characters.

The inverse to this routine is encodeInt().

Precondition
The given string contains at least nChars characters.
Python
The template argument IntType is taken to be a native C++ long.
Template Parameters
IntTypea native C++ integer type, such as uint8_t, or unsigned, or long long. The result will be assembled using bitwise OR and bitwise shift lefts, and it is assumed that the programmer has chosen an integer type large enough to contain whatever values they expect to read.
Parameters
sthe string from which the encoded base64 characters should be read.
nCharsthe number of base64 characters to read.
Returns
the native integer that was encoded.

◆ decodeSingle()

static constexpr unsigned regina::Base64SigEncoding::decodeSingle ( char  c)
inlinestaticconstexpr

Determine the integer value represented by the given base64 character.

The inverse to this routine is encodeSingle().

Parameters
ca base64 character, which must be one of the 64 printable characters described in the class notes.
Returns
the corresponding integer, which will be between 0 and 63 inclusive.

◆ decodeTrits() [1/2]

static constexpr std::array< uint8_t, 3 > regina::Base64SigEncoding::decodeTrits ( char  c)
inlinestaticconstexpr

Decodes a single base64 character into three trits, and returns these as a fixed-size array.

A trit is either 0, 1 or 2.

The inverse to this routine is encodeTrits(); see that routine for details of the encoding.

Parameters
cthe base64 character to decode.
Returns
an array containing the three trits that had been encoded in the given base64 character.

◆ decodeTrits() [2/2]

template<typename OutputIterator >
static void regina::Base64SigEncoding::decodeTrits ( char  c,
OutputIterator  result 
)
inlinestatic

Decodes a single base64 character into three trits, and returns these using an output iterator.

A trit is either 0, 1 or 2.

The inverse to this routine is encodeTrits(); see that routine for details of the encoding.

Python
Not present. Instead you can use the variant of this routine that takes one argument and returns a fixed-size array.
Parameters
cthe base64 character to decode.
resultan output iterator pointing to the location where the resulting trits will be stored; it must be possible to write and advance this iterator at least three times. Each trit will be written as a uint8_t.

◆ encodeInt()

template<typename IntType >
static void regina::Base64SigEncoding::encodeInt ( std::string &  s,
IntType  val,
unsigned  nChars 
)
inlinestatic

Append a base64 encoding of the given integer to the given string.

The integer will be broken into nChars distinct 6-bit blocks, and the lowest-significance blocks will be written first.

The inverse to this routine is decodeInt().

Precondition
The given integer val is non-negative, and fits within 6nChars bits.
Python
The template argument IntType is taken to be a native C++ long.
Template Parameters
IntTypea native C++ integer type, such as uint8_t, or unsigned, or long long.
Parameters
sthe string that resulting characters should be appended to.
valthe integer to encode.
nCharsthe number of base64 characters to use.

◆ encodeSingle()

static constexpr char regina::Base64SigEncoding::encodeSingle ( unsigned  c)
inlinestaticconstexpr

Determine the base64 character that represents the given integer value.

The inverse to this routine is decodeSingle().

Parameters
can integer between 0 and 63 inclusive.
Returns
the corresponding printable base64 character.

◆ encodeTrits() [1/2]

template<int nTrits>
static constexpr char regina::Base64SigEncoding::encodeTrits ( const std::array< uint8_t, nTrits > &  trits)
inlinestaticconstexpr

Returns a single base64 character that encodes up to three trits, given using a fixed-size array.

A trit is either 0, 1 or 2.

The given trits will be packed into a single base64 character, with the first trit representing the lowest-significance bits of the underlying integer and so on.

The inverse to this routine is decodeTrits().

Template Parameters
nTritsthe number of trits to encode; this must be between 0 and 3 inclusive.
Parameters
tritsthe array of trits to encode. Each trit must take the value 0, 1 or 2.
Returns
the resulting printable base64 character.

◆ encodeTrits() [2/2]

template<typename InputIterator >
static char regina::Base64SigEncoding::encodeTrits ( InputIterator  trits,
unsigned  nTrits 
)
inlinestatic

Returns a single base64 character that encodes up to three trits, given using an input iterator.

A trit is either 0, 1 or 2.

The given trits will be packed into a single base64 character, with the first trit representing the lowest-significance bits of the underlying integer and so on.

The inverse to this routine is decodeTrits().

Python
Not present. Instead you can use the variant of this routine that takes the trits as a fixed-size array.
Parameters
tritsan input iterator pointing to the first trit to encode; it must be possible to read and advance this iterator at least nTrits times. Each trit will be cast to a uint8_t, and must take the value 0, 1 or 2.
nTritsthe number of trits to encode; this must be at most 3.
Returns
the resulting printable base64 character.

◆ isValid()

static constexpr bool regina::Base64SigEncoding::isValid ( char  c)
inlinestaticconstexpr

Is the given character a valid base64 character?

Returns
true if and only if the given character is one of the 64 printable characters described in the class notes.

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

Copyright © 1999-2023, The Regina development team
This software is released under the GNU General Public License, with some additional permissions; see the source code for details.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@maths.uq.edu.au).