Skip to content

Commit

Permalink
Index werkt; Structure begonnen
Browse files Browse the repository at this point in the history
  • Loading branch information
Langeveld committed Feb 25, 2010
1 parent 08b3190 commit 3ceb6d3
Show file tree
Hide file tree
Showing 17 changed files with 783 additions and 536 deletions.
82 changes: 18 additions & 64 deletions csource/mocks/IndexParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,14 @@
#include <string>

#include <loki/SafeFormat.h>
#include <tinyxml/tinyxml.h>

using Loki::Printf;
using std::string;

namespace
{

typedef std::map< std::string, std::string > AttributeMap;

struct ElementParser
{

ElementParser();
~ElementParser();

};

void parseAttribute( const TiXmlAttribute* pAttribute, AttributeMap& pAttribs )
{
if ( !pAttribute )
{
return;
}
pAttribs[ pAttribute->Name() ] = pAttribute->Value();
parseAttribute( pAttribute->Next(), pAttribs );
}

const std::string COMPOUND_TAG = "compound";
}

// *tors
Expand All @@ -56,8 +37,7 @@ void parseAttribute( const TiXmlAttribute* pAttribute, AttributeMap& pAttribs )
** Eerste versie.
***************/
IndexParser::IndexParser()
{
}
{}

/** Default destructor.
**
Expand All @@ -69,55 +49,29 @@ IndexParser::~IndexParser()

// members

void IndexParser::enterElement( const TiXmlElement& pElement, const TiXmlAttribute* pAttribute )
{
const string elemValue = pElement.Value();
}

void IndexParser::parseDocument( TiXmlDocument& pIndex )
Structure IndexParser::findNextStructure( TiXmlElement* pElement )
{
pIndex.Accept( this );
}

void IndexParser::parseCompoundElement( const TiXmlElement& pElement, const TiXmlAttribute* pAttribute )
{
AttributeMap attribs;
parseAttribute( pAttribute, attribs );
mCurrentStructure.reset( attribs[ "kind" ] );
}

void IndexParser::parseNameElement( const TiXmlElement& pElement, const TiXmlAttribute* pAttribute )
{
// mCurrentStructure.setName( )
}

bool IndexParser::VisitEnter( const TiXmlElement& pElement, const TiXmlAttribute* pAttribute )
{
this->enterElement( pElement, pAttribute );

const string elemValue = pElement.Value();

// parseCompoundElement( pElement, pAttribute );
// parseNameElement( pElement, pAttribute );
if ( pElement == 0 )
{
return Structure();
}

if ( !mCurrentStructure.getType().empty() )
const string kind = pElement->Attribute( "kind" );
if ( kind != "class" && kind != "struct" )
{
Printf( "--- %s %s ---" ) ( mCurrentStructure.getType() ) ( mCurrentStructure.getName() );
return this->findNextStructure( pElement->NextSiblingElement( COMPOUND_TAG ) );
}
return mLister.VisitEnter( pElement, pAttribute );

return Structure( pElement->NextSiblingElement( COMPOUND_TAG ), kind, this->findName( pElement ) );
}

bool IndexParser::VisitExit( const TiXmlElement& pElement )
Structure IndexParser::findStructure( TiXmlDocument& pIndex )
{
if ( !mCurrentStructure.getType().empty() )
{
Printf( "--- %s %s ---" ) ( mCurrentStructure.getType() ) ( mCurrentStructure.getName() );
mParsedStructures.push_back( mCurrentStructure );
}
return mLister.VisitExit( pElement );
TiXmlElement* elem = pIndex.RootElement()->FirstChildElement( COMPOUND_TAG );
return findNextStructure( elem );
}

bool IndexParser::Visit( const TiXmlText& pText )
Structure IndexParser::findStructure( const Structure& pPreviousStructure )
{
return mLister.Visit( pText );
return this->findNextStructure( pPreviousStructure.element );
}
24 changes: 6 additions & 18 deletions csource/mocks/IndexParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,25 @@
#ifndef __INDEXPARSER_HPP__
#define __INDEXPARSER_HPP__

#include "StructLister.hpp"
#include "Structure.hpp"
#include "XmlParser.hpp"

#include <string>
#include <vector>

#include <tinyxml/tinyxml.h>
class TiXmlDocument;

class IndexParser
: public TiXmlVisitor
: public XmlParser
{
public:
mutable std::vector< Structure > mParsedStructures;

IndexParser();
~IndexParser();

void parseDocument( TiXmlDocument& pIndex );

virtual bool VisitEnter( const TiXmlElement& pElement, const TiXmlAttribute* pAttribute );
virtual bool VisitExit( const TiXmlElement& pElement );
virtual bool Visit( const TiXmlText& pText );
Structure findStructure( TiXmlDocument& pIndex );
Structure findStructure( const Structure& pPreviousStructure );

private:
Structure mCurrentStructure;
StructLister mLister;

void enterElement( const TiXmlElement& pElement, const TiXmlAttribute* pAttribute );
void parseCompoundElement( const TiXmlElement& pElement, const TiXmlAttribute* pAttribute );
void parseNameElement( const TiXmlElement& pElement, const TiXmlAttribute* pAttribute );

Structure findNextStructure( TiXmlElement* pElement );
};

#endif
104 changes: 0 additions & 104 deletions csource/mocks/StructLister.cpp

This file was deleted.

40 changes: 0 additions & 40 deletions csource/mocks/StructLister.hpp

This file was deleted.

41 changes: 9 additions & 32 deletions csource/mocks/Structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,14 @@

#include "Structure.hpp"

#include <loki/SafeFormat.h>
// *tors

using Loki::Printf;
Structure::Structure()
: element( 0 )
{}

// members

const std::string& Structure::getType() const
{
return mType;
}

const std::string& Structure::getName() const
{
return mName;
}

void Structure::reset( const std::string& pKind )
{
if ( "struct" == pKind || "class" == pKind )
{
mType = pKind;
}
else
{
mType.clear();
}

mName.clear();
}

void Structure::setName( const std::string& pName )
{
mName = pName;
}
Structure::Structure( TiXmlElement* pElement, const std::string& pType, const std::string& pName )
: element( pElement )
, type( pType )
, name( pName )
{}
18 changes: 8 additions & 10 deletions csource/mocks/Structure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@

#include <string>

class Structure
{
mutable std::string mType;
mutable std::string mName;

public:
class TiXmlElement;

const std::string& getType() const;
const std::string& getName() const;
struct Structure
{
TiXmlElement* element;
std::string type;
std::string name;

void reset( const std::string& pKind );
void setName( const std::string& pName );
Structure();
Structure( TiXmlElement* pElement, const std::string& pType, const std::string& pName );
};

#endif
Loading

0 comments on commit 3ceb6d3

Please sign in to comment.