A virtual class providing a partial common interface for Node and Leaf. More...
#include <bytetree.hpp>
Public Member Functions | |
ByteTree () | |
Empty constructor to please the compiler. | |
~ByteTree () | |
Empty destructor to please the compiler. | |
virtual bool | isLeaf () |
To know if the instance used is a Leaf. | |
virtual bool | isNode () |
To know if the instance used is a Node. | |
virtual std::string | toString () |
Turns this object into a string. | |
virtual std::vector< uint8_t > | toVector () |
Turns this object into a vector of bytes. | |
virtual mpz_class | toInteger () |
Turns this object into an arbitrarily large integer. | |
virtual std::vector< bool > | toBoolArray () |
Turns this object into a vector of boolean. | |
virtual unsigned int | size () |
The number of bytes in a Leaf and the number of ByteTrees in a Node. | |
virtual void | prettyPrint (std::string indent) |
Recursively prints an indented version of the ByteTree (mainly for debugging) | |
virtual bool | compare (std::string s) |
Compare the bytes contained in this leaf with those in the input. | |
virtual void | addChild (ByteTree *bt) |
Adds the ByteTree given in the argument to the children attribute in a Node; exits with exit code 1 if the ByteTree is a Leaf. | |
virtual ByteTree * | getChild (unsigned int i) |
Returns the child of index i if we have a Node; exits with exit code 1 if the ByteTree is a Leaf. |
Static Public Member Functions | |
static ByteTree * | parseString (std::string &s) |
Parses a string by constructing a ByteTree of the correct kind. | |
static ByteTree * | parseVector (std::vector< uint8_t > &v) |
Parses a vector of bytes by constructing a ByteTree of the correct kind; returns Leaf(0) if the vector is empty. | |
static ByteTree * | parseFile (std::string path) |
Parses a file containing the string representation of a bytetree and returns the said bytetree. If the file does not exist, returns NULL. | |
static ByteTree * | string2ByteTree (std::string s) |
Turns a string into its ByteTree representation. Not to be mistaken with parseString! |
A virtual class providing a partial common interface for Node and Leaf.
Look at the verificatum verifier specification (page 5) for a detailed, well, specification of how the ByteTree should behave. To stick close to the spec', we use to distinct classes for the nodes and the leaves but, in order for them to be easily used, we provide a common interface for them via the virtual ByteTree class.
Definition at line 39 of file bytetree.hpp.
ByteTree::ByteTree | ( | ) |
ByteTree::~ByteTree | ( | ) |
|
virtual |
Adds the ByteTree given in the argument to the children attribute in a Node; exits with exit code 1 if the ByteTree is a Leaf.
bt | The ByteTree to add. |
Reimplemented in verifierUtils::Node.
Definition at line 165 of file bytetree.cpp.
|
virtual |
Compare the bytes contained in this leaf with those in the input.
Functions (almost) like std::string.compare(): outputs false if the bytes in the leaf correspond to the string given in the input, true otherwise. For instance, Leaf(65,66,67).compare("ABC") == false.
s | The string to compare. |
Reimplemented in verifierUtils::Leaf.
Definition at line 159 of file bytetree.cpp.
|
virtual |
Returns the child of index i if we have a Node; exits with exit code 1 if the ByteTree is a Leaf.
Reimplemented in verifierUtils::Node.
Definition at line 176 of file bytetree.cpp.
|
virtual |
To know if the instance used is a Leaf.
Reimplemented in verifierUtils::Leaf, and verifierUtils::Node.
Definition at line 31 of file bytetree.cpp.
|
virtual |
To know if the instance used is a Node.
Reimplemented in verifierUtils::Leaf, and verifierUtils::Node.
Definition at line 37 of file bytetree.cpp.
|
static |
Parses a file containing the string representation of a bytetree and returns the said bytetree. If the file does not exist, returns NULL.
path | The path to the file storing the ByteTree. |
Definition at line 121 of file bytetree.cpp.
|
static |
Parses a string by constructing a ByteTree of the correct kind.
Returns a pointer to a Node if the input starts with "00" or a pointer to a Leaf otherwise. The data actually read from the string is removed from it, the idea being to easily go through it recursively.
[in,out] | s | The string to parse. |
Definition at line 74 of file bytetree.cpp.
|
static |
Parses a vector of bytes by constructing a ByteTree of the correct kind; returns Leaf(0) if the vector is empty.
Returns a pointer to a Node if the input starts with 0x0 or a pointer to a Leaf otherwise. The data actually read from the vector is removed from it, the idea being to easily go through it recursively.
[in,out] | v | The vector to parse. |
Definition at line 92 of file bytetree.cpp.
|
virtual |
Recursively prints an indented version of the ByteTree (mainly for debugging)
indent | The characters to be printed in the indentation. |
Reimplemented in verifierUtils::Leaf, and verifierUtils::Node.
Definition at line 154 of file bytetree.cpp.
|
virtual |
The number of bytes in a Leaf and the number of ByteTrees in a Node.
Reimplemented in verifierUtils::Leaf, and verifierUtils::Node.
Definition at line 148 of file bytetree.cpp.
|
static |
Turns a string into its ByteTree representation. Not to be mistaken with parseString!
Returns a pointer to Leaf containing the bytes of the string. For instance, string2ByteTree("ABCD") returns a leaf containing [0x65,0x66,0x67,0x68].
s | The string to turn into a ByteTree |
Definition at line 139 of file bytetree.cpp.
|
virtual |
Turns this object into a vector of boolean.
Reimplemented in verifierUtils::Leaf.
Definition at line 63 of file bytetree.cpp.
|
virtual |
Turns this object into an arbitrarily large integer.
Reimplemented in verifierUtils::Leaf.
Definition at line 50 of file bytetree.cpp.
|
virtual |
Turns this object into a string.
Reimplemented in verifierUtils::Leaf, and verifierUtils::Node.
Definition at line 43 of file bytetree.cpp.
|
virtual |
Turns this object into a vector of bytes.
This aim is to allow an easy hashing of the ByteTree's.
Reimplemented in verifierUtils::Leaf, and verifierUtils::Node.
Definition at line 56 of file bytetree.cpp.