Update of /cvsroot/cpptool/rfta/src/rftatest
In directory sc8-pr-cvs1:/tmp/cvs-serv31944/src/rftatest
Added Files:
SourceBuilder.cpp
Log Message:
* moved SourceBuilder to include/rfta/test and src/rftatest
--- NEW FILE: SourceBuilder.cpp ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2002/11/27
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <rfta/test/SourceBuilder.h>
namespace Refactoring { namespace Testing
{
SourceBuilder::SourceBuilder( std::string &source )
: source_( source )
{
}
SourceRange
SourceBuilder::mark( const std::string &key )
{
return addKeyed( "", key );
}
SourceRange
SourceBuilder::add( const std::string &source )
{
int startIndex = source_.length();
source_ += source;
int endIndex = source_.length();
return SourceRange( startIndex, endIndex - startIndex );
}
SourceRange
SourceBuilder::addKeyed( const std::string &source,
const std::string &key )
{
CPPUNIT_ASSERT_MESSAGE( "SourceBuilder::add(), key already exists: " + key,
ranges_.count(key) == 0 );
SourceRange range( add( source ) );
ranges_[ key ] = range;
return range;
}
SourceRange
SourceBuilder::addKeyingMid( const std::string &addedSource1,
const std::string &keyedSource,
const std::string &addedSource2,
const std::string &key )
{
source_ += addedSource1;
SourceRange range = addKeyed( keyedSource, key );
source_ += addedSource2;
return range;
}
SourceRange
SourceBuilder::extend( const std::string &key )
{
Ranges::iterator it = ranges_.find( key );
CPPUNIT_ASSERT_MESSAGE( "SourceBuilder::extend(), key does not exits: " + key,
it != ranges_.end() );
SourceRange &range = it->second;
int endIndex = source_.length();
range.setLength( endIndex - range.getStartIndex() );
return range;
}
const SourceRange &
SourceBuilder::getRange( const std::string &key ) const
{
Ranges::const_iterator it = ranges_.find( key );
CPPUNIT_ASSERT_MESSAGE( "SourceBuilder::getRange(), key does not exits: " + key,
it != ranges_.end() );
return it->second;
}
int
SourceBuilder::getStartIndex( const std::string &key ) const
{
return getRange(key).getStartIndex();
}
int
SourceBuilder::getEndIndex( const std::string &key ) const
{
return getRange(key).getEndIndex();
}
int
SourceBuilder::getLength( const std::string &key ) const
{
return getRange(key).getLength();
}
bool
SourceBuilder::hasKey( const std::string &key ) const
{
return ranges_.count( key ) > 0;
}
const std::string &
SourceBuilder::getSource() const
{
return source_;
}
} // namespace Testing
} // namespace Refactoring
|