Permalink
Browse files

Function for printing element tree ready.

  • Loading branch information...
1 parent cceedb8 commit 7cd963e58986756fd9095b36721a4f7e73406b42 @radicke-atix-de committed Nov 18, 2011
Showing with 122 additions and 22 deletions.
  1. +17 −4 src/PrintElementTree.cpp
  2. +17 −2 src/PrintElementTree.h
  3. +67 −3 src/TexDocElement.cpp
  4. +15 −8 src/TexDocElement.h
  5. +2 −2 src/TexParser.cpp
  6. +2 −2 src/TexParser.h
  7. +2 −1 src/main.cpp
View
@@ -8,12 +8,25 @@
/** get debugging info */
#define DBINF cout << "[debug]"
-
using namespace std;
void PrintElementTree::printTree( TexDocElement& parentElement )
{
-DBINF "######### Starte mit PrintElementTree::printTree ############" << std::endl;
-
-
+// DBINF "######### Starte mit PrintElementTree::printTree ############" endl;
+ list<TexDocElement>::iterator itSubElement;
+ PrintElementTree::treedepth++;
+ for
+ (
+ itSubElement = parentElement.texDocElementsList.begin();
+ itSubElement != parentElement.texDocElementsList.end();
+ itSubElement++
+ )
+ {
+ cout << string(PrintElementTree::treedepth, '=')
+ << "[Typ: " << (*itSubElement).typToString((*itSubElement).getTexElementTyp()) << "][Zeiche: "
+ << ((*itSubElement).getTexElementValue()).size() << endl;
+ // got depth.
+ PrintElementTree::printTree(*itSubElement);
+ }
+ PrintElementTree::treedepth--;
}
View
@@ -7,10 +7,25 @@
#include "TexDocElement.h"
+using namespace std;
+
class PrintElementTree
{
-public:
- static void printTree( TexDocElement& parentElement );
+ public:
+
+ /**
+ * Print the document tree.
+ * @param parentElement a parent element.
+ */
+ void printTree( TexDocElement& parentElement );
+
+ /**
+ * constructor.
+ */
+ PrintElementTree(): treedepth( 0 ) {};
+
+ private:
+ size_t treedepth;
};
#endif
View
@@ -14,7 +14,7 @@ TexDocElement::~TexDocElement(void)
// G #########################################################################
-int TexDocElement::getTexElementTyp()
+enum TexDocElement::ElementType TexDocElement::getTexElementTyp()
{
return TexDocElement::texElementTyp;
}
@@ -27,12 +27,76 @@ std::string TexDocElement::getTexElementValue()
// S #########################################################################
-void TexDocElement::setTexElementTyp( int typ)
+void TexDocElement::setTexElementTyp( enum TexDocElement::ElementType typ)
{
TexDocElement::texElementTyp = typ;
}
void TexDocElement::setTexElementValue( std::string value )
{
TexDocElement::texElementValue = value;
-}
+}
+
+// T #########################################################################
+
+string TexDocElement::typToString(enum ElementType t) const {
+ switch(t) {
+ case AUTOR:
+ return "AUTOR";
+ case BIGSKIP:
+ return "BIGSKIP";
+ case DESCRIPTION:
+ return "DESCRIPTION";
+ case DOCUMENT:
+ return "DOCUMENT";
+ case INPUT:
+ return "INPUT";
+ case ITEM:
+ return "ITEM";
+ case ITEMIZE:
+ return "ITEMIZE";
+ case LABEL:
+ return "LABEL";
+ case LSTLISTING:
+ return "LSTLISTING";
+ case MAKETITLE:
+ return "MAKETITLE";
+ case METADATA:
+ return "METADATA";
+ case NEWCOMMAND:
+ return "NEWCOMMAND";
+ case PAGEREF:
+ return "PAGEREF";
+ case TABLEOFCONTENTS:
+ return "TABLEOFCONTENTS";
+ case TABULAR:
+ return "TABULAR";
+ case TEXT:
+ return "TEXT";
+ case TITLE:
+ return "TITLE";
+ case RAW:
+ return "RAW";
+ case REF:
+ return "REF";
+ case ROOTELEMENT:
+ return "ROOTELEMENT";
+ case SUBSUBSECTION:
+ return "SUBSUBSECTION";
+ case SUBSECTION:
+ return "SUBSECTION";
+ case SECTION:
+ return "SECTION";
+ case URL:
+ return "URL";
+ case VERB:
+ return "VERB";
+ case VERBATIM:
+ return "VERBATIM";
+ case VOID:
+ return "VOID";
+ default:
+ return "unknow";
+ }
+
+}
View
@@ -1,10 +1,11 @@
#ifndef TEXDOCELEMENT_H
#define TEXDOCELEMENT_H
-
#include <string>
#include <list>
+using namespace std;
+
class TexDocElement
{
public:
@@ -50,32 +51,38 @@ class TexDocElement
* if the object have other children object,
* then it is in this list.
*/
- std::list<TexDocElement> texDocElementsList;
+ list<TexDocElement> texDocElementsList;
// Methods ###############################################################
/**
* get the typ of element.
*/
- int getTexElementTyp();
+ enum ElementType getTexElementTyp();
/**
* get the value of element.
*/
- std::string getTexElementValue();
+ string getTexElementValue();
/**
* set the typ of element.
* @param typ an string of typ name.
*/
- void setTexElementTyp( int typ );
+ void setTexElementTyp( enum TexDocElement::ElementType typ );
/**
* set the value of element.
* @param typ an string of typ name.
*/
- void setTexElementValue( std::string typ );
+ void setTexElementValue( string typ );
+
+ /**
+ * Convert a enum ElementType in a String.
+ * @param t A enum ElementType
+ */
+ string typToString(enum ElementType t) const ;
private:
@@ -84,12 +91,12 @@ class TexDocElement
/**
* The name of imput file.
*/
- int texElementTyp;
+ enum ElementType texElementTyp;
/**
* If this object only a string, thas is the value.
*/
- std::string texElementValue;
+ string texElementValue;
// Methods ###############################################################
View
@@ -19,7 +19,7 @@ void TexParser::cutOutBeginEnd
(
TexDocElement& parentElement,
string keyWord,
- const int& typ
+ const enum TexDocElement::ElementType& typ
)
{
string beginKeyWord = "\\begin{" + keyWord + "}";
@@ -106,7 +106,7 @@ void TexParser::cutOutShortElements
(
TexDocElement& parentElement,
string keyWord,
- const int& typ
+ const enum TexDocElement::ElementType& typ
)
{
string beginKeyWord = "\\" + keyWord + "{";
View
@@ -57,7 +57,7 @@ class TexParser
(
TexDocElement& parentElement,
std::string keyWord,
- const int& typ
+ const enum TexDocElement::ElementType& typ
);
/**
@@ -73,7 +73,7 @@ class TexParser
(
TexDocElement& parentElement,
std::string keyWord,
- const int& typ
+ const enum TexDocElement::ElementType& typ
);
/**
View
@@ -90,7 +90,8 @@ int main(int argc,char *argv[])
TexParser texParser;
texParser.setInputFileName(imputFileName);
texParser.pars();
- PrintElementTree::printTree( texParser.getRootElement() );
+ PrintElementTree treePrinter;
+ treePrinter.printTree( texParser.getRootElement() );
return 0;
}
if( do_command == "pars")

0 comments on commit 7cd963e

Please sign in to comment.