G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Base64 Class Reference

Detailed Description

Encode for base64 export.

Static class to provide functionality to encode any type of vector into an ascii string (uncompressed) and its inverse operation.

Static Public Member Functions

template<typename OutputType >
static std::vector< OutputType > Decode (const std::string &base64string)
 Reading a B64 string, transforming it into a vector of a specific type. More...
 
template<typename ScalarType >
static void DecodeIntoGsType (const std::string &base64_string, const std::string &base_type_flag_, gsMatrix< ScalarType > &result)
 Decode a string and copy into requested gismo Type. More...
 
template<typename ScalarType >
static void DecodeIntoGsType (const std::string &base64_string, const std::string &base_type_flag_, std::vector< ScalarType > &result)
 Decode a string and copy into requested gismo Type. More...
 
template<typename BaseType >
static std::string Encode (const std::vector< BaseType > &data_vector)
 Helper routine for std::vector data. More...
 
template<typename BaseType >
static std::string Encode (const gsMatrix< BaseType > &data_vector, const bool &row_wise=true)
 Helper routine for gsMatrix Types (non-sparse) More...
 

Private Types

using ByteRepresentation = unsigned char
 Alias for one byte type.
 

Static Private Member Functions

static unsigned char_decode_table (const unsigned &index)
 Lookup Table for Decoding B64 string.
 
static char char_encode_table (const unsigned &index)
 Look up table.
 
template<typename BaseType , typename TargetType >
static void CopyIntoGsMatrix (const std::vector< BaseType > &base_vector, gsMatrix< TargetType > &result)
 Copy a read vector of type BaseType into a gsMatrix with ScalarType TargetType. More...
 
template<typename BaseType , typename TargetType >
static void CopyIntoVector (const std::vector< BaseType > &base_vector, std::vector< TargetType > &result)
 Cast a vector of a base type into a vector of TargetType. More...
 
static std::string Encode_ (const ByteRepresentation *byte_vector_ptr, const std::size_t &minimum_n_bytes_required)
 Actual encoding routine where byte-stream is transformed and encoded. More...
 
static const std::array
< unsigned, 256 > 
ReverseCharEncodeTable_ ()
 Reverse the encoding table in an array. More...
 
static std::string trimWhitespaces (const std::string &s)
 Trim trailing and preceding whitespaces. More...
 

Member Function Documentation

static void CopyIntoGsMatrix ( const std::vector< BaseType > &  base_vector,
gsMatrix< TargetType > &  result 
)
inlinestaticprivate

Copy a read vector of type BaseType into a gsMatrix with ScalarType TargetType.

This is required as they might differ from each other, e.g., double into float, uint into int, etc.. Further, most matrices in Gismo (like coefficients) are stored in a different order (colwise) than the input stream, which prohibits the use of writing directly on the pointer

Template Parameters
BaseTypeType as encoded into the input file
TargetTypeType as requested from target
Parameters
base_vectordecoded std::vector with base type
resultgsMatrix passed as reference
static void CopyIntoVector ( const std::vector< BaseType > &  base_vector,
std::vector< TargetType > &  result 
)
inlinestaticprivate

Cast a vector of a base type into a vector of TargetType.

Template Parameters
BaseTypeType as encoded into the input file
TargetTypeType as requested from target
Parameters
base_vectordecoded std::vector with base type
resultdecoded std::vector with target type
static std::vector<OutputType> Decode ( const std::string &  base64string)
inlinestatic

Reading a B64 string, transforming it into a vector of a specific type.

Todo:
: In the future copies could be avoided by using string_view
Template Parameters
OutputTypetarget type
static void DecodeIntoGsType ( const std::string &  base64_string,
const std::string &  base_type_flag_,
gsMatrix< ScalarType > &  result 
)
inlinestatic

Decode a string and copy into requested gismo Type.

Read a base64 string depending on a format flag (that determines base type) and write it into gsMatrix<ScalarType>. Other overloads provide functions to copy into a std::vector<ScalarType>

Template Parameters
ScalarType
Parameters
base64_string
base_type_flag_
result
static void DecodeIntoGsType ( const std::string &  base64_string,
const std::string &  base_type_flag_,
std::vector< ScalarType > &  result 
)
inlinestatic

Decode a string and copy into requested gismo Type.

Read a base64 string depending on a format flag (that determines base type) and write it into std::vector<ScalarType>. Other overloads provide functions to copy into a gsMatrix<ScalarType>

Template Parameters
ScalarType
Parameters
base64_string
base_type_flag_
result
static std::string Encode ( const std::vector< BaseType > &  data_vector)
inlinestatic

Helper routine for std::vector data.

Template Parameters
BaseTypetype of individual data entries
Parameters
data_vectordata to be encoded
Returns
std::string encoded data
static std::string Encode ( const gsMatrix< BaseType > &  data_vector,
const bool &  row_wise = true 
)
inlinestatic

Helper routine for gsMatrix Types (non-sparse)

Template Parameters
BaseTypetype of individual data entries
Parameters
data_vectordata to be encoded
row_wiseEncode in row_wise style
Returns
std::string encoded data
static std::string Encode_ ( const ByteRepresentation byte_vector_ptr,
const std::size_t &  minimum_n_bytes_required 
)
inlinestaticprivate

Actual encoding routine where byte-stream is transformed and encoded.

Parameters
byte_vector_ptrpointer to start of an array (contiguous)
minimum_n_bytes_requirednumber_of_bytes in byte-stream
Returns
std::string encoded data
static const std::array<unsigned, 256> ReverseCharEncodeTable_ ( )
inlinestaticprivate

Reverse the encoding table in an array.

Chars are casted to unsigned types for indexing, function will only be called once

Returns
std::array<unsigned, 256>
static std::string trimWhitespaces ( const std::string &  s)
inlinestaticprivate

Trim trailing and preceding whitespaces.

Parameters
sstring to be processed
Returns
std::string