Code Documentation

The Entry Point

The main file.

This file is the main file of the tool.

Author

Andrea Esposito <github.com/espositoandrea>

Functions

int main(int argc, char **argv)

The main entry point.

This is the entry point of the tool.

Return

An exit code based on the execution.

Parameters
  • argc: The length of argv.

  • argv: The array of arguments given through the command line.

The CLI

exit_codes setup_options(int argc, char **argv, std::vector<std::string> &images)

Set up the tool’s options and arguments.

This function is responsible of the CLI API of the tool. It sets and handles the available options and arguments.

Return

An exit code:

  • exit_codes::OK If the given arguments are valid and no errors occurred.

  • exit_codes::HALT If the given arguments are valid but the argument combination stops the execution.

  • exit_codes::ARGUMENT_ERROR If the given arguments are invalid

  • exit_codes::UNKNOWN_ARGUMENT_ERROR If an unknown error occurred.

Parameters
  • argc: The length of argv.

  • argv: The array of arguments passed via CLI.

  • images: A variable that will contain the images passed through the CLI API.

The Exit Codes

enum exit_codes

A collection of all the exit codes of the tool.

This enum contains all the (expected) exit codes of the tool.

Values:

OK = 0

The tool exited with no error completing its tasks.

HALT = 1

The tool exited with no error, but without completing its tasks.

ARGUMENT_ERROR = 2

The tool exited due to errors in the given arguments.

UNKNOWN_ARGUMENT_ERROR = 3

The tool exited due to unknown errors while parsing the arguments.

The Data URI

class data_uri

A utility class to handle data URIs.

This class represents a data URI. A data URI is defined by MDN as a string with the followind sintax: data:[<mediatype>][;base64],<data>.

Public Functions

data_uri(const std::string &s)

The class constructor.

This constructor creates a data_uri from a string.

Parameters
  • s: The string representing the data uri.

Exceptions

std::string get_type() const

Get the media type.

This function returns the media type of the data URI.

Return

The media type (<mediatype> in data:<mediatype>;base64,<data>).

std::string get_data() const

Get the data.

This function returns the data contained in the data URI.

Return

The data (<data> in data:<mediatype>;base64,<data>).

std::string get_uri() const

Get the URI.

This function returns the entire URI as a string.

Return

The URI as a string.

Public Static Functions

bool is_data_uri(const std::string &s)

Check if a string is a data URI.

The function checks if a string is in the format data:<mediatype>;base64,<data>.

Return

True if s is a data URI, false otherwise.

Parameters
  • s: The string to be checked

class string_not_uri : public exception

An exception raised if a string is not an URI.

This exception is thrown if a string, assumed to be one, is not a data URI.

The Base64 Utilities

namespace base64

Namespace for dealing with base64 strings.

This namespace contains utilities to deal with base64 strings.

Functions

std::string encode(const std::string &s)

Encode a string to base64.

This function encodes a string to a base64 string.

Return

The encoded string.

Parameters
  • s: The string to be encoded.

std::string encode(unsigned char const *s, unsigned int len)

Encode a string to base64.

This function encodes a string to a base64 string.

Return

The encoded string.

Parameters
  • s: The string to be encoded.

  • len: The length of the string s.

std::string decode(std::string const &s)

Decode a base64 string.

This function decodes a base64 string to a binary string.

Return

The decoded string.

Parameters
  • s: The string to be decoded.