32#ifndef __PDS_BINARYTREENODE_HPP__
33#define __PDS_BINARYTREENODE_HPP__
57template <
typename Datum>
254 void Print(
const std::string &str=
"")
const;
262 void PrintNode(
const std::string &str,
const std::string &enddata=
"")
const;
280 std::string (*FuncDatumToString)(
const Datum &)
291 std::string (*FuncDatumToString)(
const Datum &)
331 std::string (*FuncDatumToXmlString)(
const Datum &)
360 std::string (*FuncDatumToXmlString)(
const Datum &)
387 std::string
ExportXmlToString( std::string (*FuncDatumToXmlString)(
const Datum &) )
const;
417 Datum (*FuncXmlStringToDatum)(
const std::string &)
434template <
typename Datum>
439 this->RightNode=NULL;
444template <
typename Datum>
447 this->P=
new Datum(Value);
449 this->RightNode=NULL;
455template <
typename Datum>
460 this->P=
new Datum(Value);
461 this->LeftNode=LeftNodePtr;
462 this->RightNode=RightNodePtr;
468template <
typename Datum>
473 this->P=
new Datum(Value);
476 this->LeftNode =NULL;
481 this->RightNode =NULL;
489template <
typename Datum>
494 this->RightNode=NULL;
501template <
typename Datum>
509template <
typename Datum>
512 if(
false==this->Copy(A))
519template <
typename Datum>
530 this->P=
new Datum(*Node.
P);
540 if( (this->LeftNode==NULL)&&(Node.
LeftNode!=NULL) )
546 if( (this->RightNode==NULL)&&(Node.
RightNode!=NULL) )
557template <
typename Datum>
566 if(this->LeftNode!=NULL)
568 delete this->LeftNode;
572 if(this->RightNode!=NULL)
574 delete this->RightNode;
575 this->RightNode=NULL;
580template <
typename Datum>
585 if(this->IsEmpty())
return;
587 std::cout<<
"\n"<<*(this->P);
589 if(this->LeftNode!=NULL)
591 std::cout<<
"CALL0\n";
592 this->LeftNode->
Print(str+std::to_string(0));
594 else std::cout<<
"NULL0\n";
596 if(this->RightNode!=NULL)
598 std::cout<<
"CALL1\n";
599 this->RightNode->
Print(str+std::to_string(1));
601 else std::cout<<
"NULL1\n";
606template <
typename Datum>
612 std::cout<<*(this->P);
617 std::cout<<this->LeftNode<<
"\n";
619 std::cout<<this->RightNode<<
"\n";
623template <
typename Datum>
627 if(this->P==NULL)
return ERROR;
632template <
typename Datum>
635 return this->LeftNode;
638template <
typename Datum>
641 return this->RightNode;
645template <
typename Datum>
648 if(this->P==NULL)
return true;
653template <
typename Datum>
656 if(this->LeftNode!=NULL)
return true;
661template <
typename Datum>
664 if(this->RightNode!=NULL)
return true;
670template <
typename Datum>
672 std::string (*FuncDatumToString)(
const Datum &)
675 if(this->IsEmpty())
return;
677 std::string STRING=FuncDatumToString(*(this->P));
679 myfile <<
"N"<<(
unsigned long)
this<<
"\t[ label =\""<<STRING<<
"\"];\n";
681 if(this->LeftNode!=NULL) myfile <<
"N"<<(
unsigned long)
this
682 <<
"\t->\tN"<<(
unsigned long)this->LeftNode
683 <<
"\t[label = \"0\"];\n";
685 if(this->RightNode!=NULL) myfile <<
"N"<<(
unsigned long)
this
686 <<
"\t->\tN"<<(
unsigned long)this->RightNode
687 <<
"\t[label = \"1\"];\n";
696template <
typename Datum>
698 std::string (*FuncDatumToString)(
const Datum &)
701 std::ofstream myfile;
702 myfile.open(filename);
703 if (myfile.is_open())
705 myfile <<
"// dot -Tpng -o "<<filename<<
".png "<<filename<<
"\n";
706 myfile <<
"digraph G {\n";
707 this->ExportDotInStreamFile(myfile,FuncDatumToString);
719template <
typename Datum>
721 std::string (*FuncDatumToXmlString)(
const Datum &)
726 if(this->IsEmpty()==
false)
728 sstream<<
"<Datum>\n";
729 sstream<<FuncDatumToXmlString(*this->P);
730 sstream<<
"</Datum>\n";
732 sstream<<
"<LeftNode>\n";
733 if(this->LeftNode!=NULL)
737 sstream<<
"</LeftNode>\n";
739 sstream<<
"<RightNode>\n";
740 if(this->RightNode!=NULL)
744 sstream<<
"</RightNode>\n";
752template <
typename Datum>
754 std::string (*FuncDatumToXmlString)(
const Datum &)
757 if(myfile.is_open()==
false)
return false;
759 std::stringstream ss;
760 this->ExportXmlToStringStream(ss,FuncDatumToXmlString);
766template <
typename Datum>
770 if(this->IsEmpty())
return "";
772 std::stringstream ss;
773 this->ExportXmlToStringStream(ss,FuncDatumToXmlString);
779template <
typename Datum>
781 Datum (*FuncXmlStringToDatum)(
const std::string &)
789 if(str.length()<=L)
return false;
791 std::string StrInNode;
798 if(StrInNode.size()==0)
return false;
800 std::vector<std::string> dat;
801 std::vector<std::string> tag;
804 std::string StrInDatum=
"";
805 std::string StrInLeftNode=
"";
806 std::string StrInRightNode=
"";
808 for(n=0;n<tag.size();n++)
810 if(tag[n].compare(
"Datum")==0)
814 else if(tag[n].compare(
"LeftNode")==0)
816 StrInLeftNode=dat[n];
818 else if(tag[n].compare(
"RightNode")==0)
820 StrInRightNode=dat[n];
824 if(StrInDatum.size()==0)
return false;
826 this->P=
new Datum();
827 *(this->P)=FuncXmlStringToDatum(StrInDatum);
829 if(StrInLeftNode.size()>L)
835 if(StrInRightNode.size()>L)
La clase tipo Pds::BinaryTreeNode. Esta clase genera una estructura de datos que contem um valor y do...
Pds::BinaryTreeNode< Datum > * LeftNode
Pds::BinaryTreeNode< Datum > * RightNode
std::string ExportXmlToString(std::string(*FuncDatumToXmlString)(const Datum &)) const
Escribe en un std::string en formato Xml el contenido de todo el arbol desde el Pds::BinaryTreeNode.
Pds::BinaryTreeNode< Datum > & operator=(const Pds::BinaryTreeNode< Datum > &B)
Copia en si mismo (A), un objeto B. Este operador es similar al método Copy().
bool HasChild1(void) const
Verifica si el nodo de la derecha es nulo.
bool Copy(const Pds::BinaryTreeNode< Datum > &B)
Copia en si mismo (A), el contenido de un objeto B. Este método es similar a usar el operador = .
Datum GetVal(void) const
Devuelve el contenido del nodo Pds::BinaryTreeNode.
bool ExportXmlToStringStream(std::stringstream &sstream, std::string(*FuncDatumToXmlString)(const Datum &)) const
Escribe en un std::stringstream en formato Xml el contenido de todo el arbol desde el Pds::BinaryTree...
bool HasChild0(void) const
Verifica si el nodo de la izquierda es nulo.
bool ImportXmlFromString(const std::string &str, Datum(*FuncXmlStringToDatum)(const std::string &))
Lee desde un std::string en formato Xml el contenido de todo el arbol desde el Pds::BinaryTreeNode.
BinaryTreeNode(void)
Crea un objeto de tipo Pds::BinaryTreeNode vacio.
const Pds::BinaryTreeNode< Datum > * GetChild0(void) const
Retorna la direccion del hijo relativo a 0 (izquierda).
void Print(const std::string &str="") const
Muestra en pantalla el Datum del Pds::BinaryTreeNode y de todos sus descendientes....
void MakeEmpty(void)
Limpia los datos internos. Despues de limpiar this->IsEmpty() es igual a true.
void PrintNode(const std::string &str, const std::string &enddata="") const
Muestra en pantalla los datos dentro del actual Pds::BinaryTreeNode. El elemento debe poder ser agreg...
void ExportDotInStreamFile(std::ofstream &streamfile, std::string(*FuncDatumToString)(const Datum &)) const
Salva en formato .dot el objeto de tipo Pds::BinaryTreeNode.
bool ExportDotFile(const std::string &filename, std::string(*FuncDatumToString)(const Datum &)) const
Salva en formato .dot el objeto de tipo Pds::BinaryTreeNode.
bool IsEmpty(void) const
Verifica si el nodo es nulo.
bool ExportXmlToStream(std::ofstream &myfile, std::string(*FuncDatumToXmlString)(const Datum &)) const
Escribe en un std::ofstream en formato Xml el contenido de todo el arbol desde el Pds::BinaryTreeNode...
const Pds::BinaryTreeNode< Datum > * GetChild1(void) const
Retorna la direccion del hijo relativo a 1 (derecha).
const std::string BinaryTreeNode
Tag de un objeto de tipo Pds::Ra::Tag::BinaryTreeNode.
std::string Trim(const std::string &str)
Esta función retorna una cadena que elimina al inicio y al final algunos caracteres si estos son cara...
std::string FirstSubInString(const std::string &str, const std::string &DelL, const std::string &DelR, bool Full=false)
Retorna la primera cadena de texto dentro de un par de delimitadores.
std::vector< std::string > SubsXmlInString(const std::string &str, bool Full, std::vector< std::string > &Tag)
Busca etiquetas tag entre '<' y '>' de modo de que se busca la forma <tag> dato </tag>....
Nombre de espacio para Pds (Procesamiento Digital de Senales)