Inherits from the ByteTree and implements the case where the ByteTree has children.
More...
#include <node.hpp>
Public Member Functions |
| Node () |
| Constructs an empty Node instance.
|
| Node (std::string &s) |
| Parses a string to generate the corresponding Node and removes the data read from it.
|
| Node (std::vector< uint8_t > &v) |
| Creates a Node from the corresponding vector of bytes and removes the data read from it.
|
| ~Node () |
| Destroys each element in children.
|
std::string | toString () |
| Turns this object into a string.
|
std::vector< uint8_t > | toVector () |
| Turns this object into a vector of bytes.
|
bool | isNode () |
| To know if the instance used is a Node.
|
bool | isLeaf () |
| To know if the instance used is a Leaf.
|
unsigned int | size () |
| The number of bytes in a Leaf and the number of ByteTrees in a Node.
|
void | prettyPrint (std::string indent) |
| Recursively prints an indented version of the ByteTree (mainly for debugging)
|
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.
|
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.
|
| ByteTree () |
| Empty constructor to please the compiler.
|
| ~ByteTree () |
| Empty destructor to please the compiler.
|
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 bool | compare (std::string s) |
| Compare the bytes contained in this leaf with those in the input.
|
Additional Inherited Members |
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!
|
Detailed Description
Inherits from the ByteTree and implements the case where the ByteTree has children.
- See Also
- btrtest.cpp
Definition at line 25 of file node.hpp.
Constructor & Destructor Documentation
Constructs an empty Node instance.
Definition at line 22 of file node.cpp.
Node::Node |
( |
std::string & |
s | ) |
|
Parses a string to generate the corresponding Node and removes the data read from it.
- Parameters
-
[in,out] | s | The string to parse. It must start with "00". |
Definition at line 34 of file node.cpp.
{
if ((s.compare(0,2,"00") != 0) || (s.size()%2 !=0))
{
std::cout<<"ERROR: in Node(string), input does not "
"start with '00' or has an odd length"
<<std::endl<<"input: '"<<s<<"'"<<std::endl;
exit(1);
}
else
{
s = s.substr(10,std::string::npos);
for (unsigned int i=0; i<l; i++)
}
}
Node::Node |
( |
std::vector< uint8_t > & |
v | ) |
|
Creates a Node from the corresponding vector of bytes and removes the data read from it.
- Parameters
-
[in,out] | v | The byte representation of the node we want to create. Must start with 0x0. |
Definition at line 55 of file node.cpp.
{
if (v[0] != 0)
{
std::cout<<"ERROR: in Node(vector), input does not "
"start with 0x0.\nv= " <<std::endl;
for (unsigned int i=0; i<v.size(); i++)
std::cout<<std::hex<<v[i]<<",";
std::cout<<std::endl;
exit(1);
}
else
{
unsigned int l = v[1]*0x1000000
+ v[2]*0x10000
+ v[3]*0x100
+ v[4];
v.assign(v.begin()+5, v.end());
for (unsigned int i=0; i<l; i++)
}
}
Destroys each element in children.
Definition at line 27 of file node.cpp.
{
for (
unsigned int i=0; i<
children.size(); i++)
}
Member Function Documentation
ByteTree * Node::getChild |
( |
unsigned int |
i | ) |
|
|
virtual |
To know if the instance used is a Leaf.
- Returns
- true if the type of this object is an instance of the class Leaf, false otherwise.
Reimplemented from verifierUtils::ByteTree.
Definition at line 117 of file node.cpp.
To know if the instance used is a Node.
- Returns
- true if the type of this object is an instance of the class Node, false otherwise.
Reimplemented from verifierUtils::ByteTree.
Definition at line 111 of file node.cpp.
void Node::prettyPrint |
( |
std::string |
indent | ) |
|
|
virtual |
Recursively prints an indented version of the ByteTree (mainly for debugging)
- Parameters
-
indent | The characters to be printed in the indentation. |
Reimplemented from verifierUtils::ByteTree.
Definition at line 129 of file node.cpp.
{
for (
unsigned int i=0; i<
children.size(); i++)
std::cout<<std::endl;
}
unsigned int Node::size |
( |
| ) |
|
|
virtual |
std::string Node::toString |
( |
| ) |
|
|
virtual |
Turns this object into a string.
- Returns
- The string representation of this instance.
Reimplemented from verifierUtils::ByteTree.
Definition at line 81 of file node.cpp.
{
std::string result;
std::vector<uint8_t> bytes =
toVector();
for (unsigned int i=0; i<bytes.size(); i++)
return result;
}
std::vector< uint8_t > Node::toVector |
( |
| ) |
|
|
virtual |
Turns this object into a vector of bytes.
This aim is to allow an easy hashing of the ByteTree's.
- Returns
- The byte representation of the ByteTree.
Reimplemented from verifierUtils::ByteTree.
Definition at line 91 of file node.cpp.
{
std::vector<uint8_t> result;
result.push_back(0);
result.push_back((byteNumber>>24) % 0x100);
result.push_back((byteNumber>>16) % 0x100);
result.push_back((byteNumber>> 8) % 0x100);
result.push_back( byteNumber % 0x100);
for (
unsigned int i=0; i<
children.size(); i++)
{
std::vector<uint8_t> bytesChild =
children[i]->toVector();
result.insert(result.end(),bytesChild.begin(), bytesChild.end());
}
return result;
}
Member Data Documentation
std::vector<ByteTree *> verifierUtils::Node::children |
|
private |
The documentation for this class was generated from the following files: