Skip to content

Commit

Permalink
add clean and doc in SpecReader
Browse files Browse the repository at this point in the history
issue #28
  • Loading branch information
Valentin Noel committed Dec 2, 2013
1 parent 4306009 commit 63eda1e
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 171 deletions.
31 changes: 15 additions & 16 deletions libraries/SpecReader/src/SpecReader/SpecChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SpecChecker::SpecChecker( rapidjson::Document* document, const std::string& file

void SpecChecker::check()
{
LOG_WARNING( "[speccheker] filepath: " << _filepath );
LOG_TRACE( "[speccheker] filepath: " << _filepath );
std::ifstream file( _filepath );

if( ! file.good() )
Expand All @@ -32,13 +32,13 @@ void SpecChecker::check()
if( _document->HasParseError() )
throw std::runtime_error( std::string( _document->GetParseError() ) + " @char:# " + std::to_string( _document->GetErrorOffset() ) );

LOG_WARNING( "[speccheker] _document OK !" );
checkSubFile( _document->FindMember( std::string( kHeader ).c_str() ) );
LOG_TRACE( "[speccheker] _document OK !" );
checkSubFile( _document->FindMember( std::string( kContent ).c_str() ) );
}

void SpecChecker::checkSubFile( rapidjson::Value::Member* member )
{
LOG_WARNING( "[speccheker] checkSubFile" );
LOG_TRACE( "[speccheker] checkSubFile" );
for( rapidjson::Value::ValueIterator node = member->value.Begin(); node != member->value.End(); ++node )
{
for( rapidjson::Value::ConstMemberIterator itr = node->MemberBegin(); itr != node->MemberEnd(); ++itr )
Expand All @@ -60,13 +60,16 @@ void SpecChecker::checkSubFile( rapidjson::Value::Member* member )
}

node->RemoveMember( std::string( kFile ).c_str() );
node->AddMember( std::string( kId ).c_str(), subDoc.FindMember( std::string( kStandard ).c_str() )->value.FindMember( std::string( kId ).c_str() )->value.GetString(), _document->GetAllocator() );
node->AddMember( std::string( kLabel ).c_str(), subDoc.FindMember( std::string( kStandard ).c_str() )->value.FindMember( std::string( kLabel ).c_str() )->value.GetString(), _document->GetAllocator() );
rapidjson::Value::Member* description = subDoc.FindMember( std::string( kDescription ).c_str() );
rapidjson::Value::Member* id = description->value.FindMember( std::string( kId ).c_str() );
rapidjson::Value::Member* label = description->value.FindMember( std::string( kLabel ).c_str() );
node->AddMember( std::string( kId ).c_str(), id->value.GetString(), _document->GetAllocator() );
node->AddMember( std::string( kLabel ).c_str(), label->value.GetString(), _document->GetAllocator() );

rapidjson::Value extNodes( rapidjson::kArrayType );
node->AddMember( std::string( kGroup ).c_str(), extNodes, _document->GetAllocator() );

rapidjson::Value::Member* subMember = subDoc.FindMember( std::string( kHeader ).c_str() );
rapidjson::Value::Member* subMember = subDoc.FindMember( std::string( kContent ).c_str() );
for( rapidjson::Value::ConstValueIterator subNode = subMember->value.Begin(); subNode != subMember->value.End(); ++subNode )
includeExtNode( node->FindMember( std::string( kGroup ).c_str() ), subNode );
break;
Expand All @@ -79,26 +82,22 @@ void SpecChecker::checkSubFile( rapidjson::Value::Member* member )

void SpecChecker::includeExtNode( rapidjson::Value::Member* member, rapidjson::Value::ConstValueIterator subNode )
{
LOG_WARNING( "[speccheker] includeExtNode" );
LOG_TRACE( "[speccheker] includeExtNode" );
rapidjson::Value object( rapidjson::kObjectType );

for( rapidjson::Value::ConstMemberIterator itr = subNode->MemberBegin(); itr != subNode->MemberEnd(); ++itr )
{
switch( itr->value.GetType() )
{
case rapidjson::kNullType : object.AddMember( itr->name.GetString(), std::string( kNull ).c_str(), _document->GetAllocator() ); break;
case rapidjson::kNullType : object.AddMember( itr->name.GetString(), std::string( kNull ).c_str(), _document->GetAllocator() ); break;
case rapidjson::kFalseType :
case rapidjson::kTrueType :
case rapidjson::kTrueType :
{
object.AddMember( itr->name.GetString(), itr->value.GetBool(), _document->GetAllocator() );
break;
}
case rapidjson::kObjectType :
{
// object.AddMember( itr->name.GetString(), "itr->value", document->GetAllocator() );
break;
}
case rapidjson::kArrayType :
case rapidjson::kObjectType : break;
case rapidjson::kArrayType :
{
rapidjson::Value array( rapidjson::kArrayType );
object.AddMember( itr->name.GetString(), array, _document->GetAllocator() );
Expand Down
15 changes: 15 additions & 0 deletions libraries/SpecReader/src/SpecReader/SpecChecker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,29 @@
namespace spec_reader
{

/**
* Specification files checker.
*/
class SpecChecker
{
public:
/**
* SpecChecker's constructor.
* @param document RapidJson document reference.
* @param filepath JSON file path.
*/
SpecChecker( rapidjson::Document* document, const std::string& filepath );

/**
* SpecChecker's destructor.
*/
~SpecChecker()
{
}

/**
* Checks the JSON document, and links with JSON subfiles.
*/
void check();

private:
Expand Down
Loading

0 comments on commit 63eda1e

Please sign in to comment.