Refactoring

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@507 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2012-07-22 07:11:55 +00:00
parent 7e4eb18cb0
commit d8dafff661
6 changed files with 213 additions and 169 deletions

View file

@ -4,8 +4,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "turtle", "turtle.vcxproj",
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "turtle_test", "turtle_test.vcxproj", "{74810A2A-33D8-47D6-9A50-71261F1683F5}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "turtle_bench", "turtle_bench.vcxproj", "{2D607783-30B9-46DE-81E2-28513B31D5D2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
debug|Win32 = debug|Win32
@ -30,14 +28,6 @@ Global
{74810A2A-33D8-47D6-9A50-71261F1683F5}.release|Win32.Build.0 = release|Win32
{74810A2A-33D8-47D6-9A50-71261F1683F5}.release|x64.ActiveCfg = release|x64
{74810A2A-33D8-47D6-9A50-71261F1683F5}.release|x64.Build.0 = release|x64
{2D607783-30B9-46DE-81E2-28513B31D5D2}.debug|Win32.ActiveCfg = debug|Win32
{2D607783-30B9-46DE-81E2-28513B31D5D2}.debug|Win32.Build.0 = debug|Win32
{2D607783-30B9-46DE-81E2-28513B31D5D2}.debug|x64.ActiveCfg = debug|x64
{2D607783-30B9-46DE-81E2-28513B31D5D2}.debug|x64.Build.0 = debug|x64
{2D607783-30B9-46DE-81E2-28513B31D5D2}.release|Win32.ActiveCfg = release|Win32
{2D607783-30B9-46DE-81E2-28513B31D5D2}.release|Win32.Build.0 = release|Win32
{2D607783-30B9-46DE-81E2-28513B31D5D2}.release|x64.ActiveCfg = release|x64
{2D607783-30B9-46DE-81E2-28513B31D5D2}.release|x64.Build.0 = release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -49,10 +49,12 @@
<ClInclude Include="..\..\turtle\detail\verifiable.hpp" />
<ClInclude Include="..\..\turtle\detail\yes_no_type.hpp" />
<ClInclude Include="..\..\turtle\error.hpp" />
<ClInclude Include="..\..\turtle\format.hpp" />
<ClInclude Include="..\..\turtle\log.hpp" />
<ClInclude Include="..\..\turtle\mock.hpp" />
<ClInclude Include="..\..\turtle\object.hpp" />
<ClInclude Include="..\..\turtle\sequence.hpp" />
<ClInclude Include="..\..\turtle\stream.hpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{831F2DEE-1E35-4533-A3B2-12C01BA8DA1D}</ProjectGuid>

View file

@ -112,5 +112,11 @@
<ClInclude Include="..\..\turtle\detail\is_functor.hpp">
<Filter>Source Files\detail</Filter>
</ClInclude>
<ClInclude Include="..\..\turtle\stream.hpp">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\..\turtle\format.hpp">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

56
turtle/format.hpp Normal file
View file

@ -0,0 +1,56 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef MOCK_FORMAT_HPP_INCLUDED
#define MOCK_FORMAT_HPP_INCLUDED
#include "stream.hpp"
#include <boost/utility/addressof.hpp>
namespace mock
{
namespace detail
{
template< typename T >
struct formatter
{
explicit formatter( const T& t )
: t_( boost::addressof( t ) )
{}
void serialize( stream& s ) const
{
mock::detail::serialize( s, *t_ );
}
const T* t_;
};
template< typename T >
stream& operator<<( stream& s, const formatter< T >& f )
{
f.serialize( s );
return s;
}
template< typename T >
std::ostream& operator<<( std::ostream& s, const formatter< T >& f )
{
stream ss( s );
f.serialize( ss );
return s;
}
}
template< typename T >
detail::formatter< T > format( const T& t )
{
return detail::formatter< T >( t );
}
} // mock
#endif // MOCK_FORMAT_HPP_INCLUDED

View file

@ -9,11 +9,11 @@
#ifndef MOCK_LOG_HPP_INCLUDED
#define MOCK_LOG_HPP_INCLUDED
#include "stream.hpp"
#include "format.hpp"
#include <boost/utility/enable_if.hpp>
#include <boost/detail/container_fwd.hpp>
#include <boost/function_types/is_callable_builtin.hpp>
#include <boost/utility/addressof.hpp>
#include <ostream>
#include <memory>
namespace boost
@ -38,157 +38,18 @@ namespace assign_detail
namespace mock
{
struct stream
{
explicit stream( std::ostream& s )
: s_( &s )
{}
std::ostream* s_;
};
#ifdef MOCK_USE_CONVERSIONS
namespace detail3
{
struct sink
{
template< typename T >
sink( const T& )
{}
};
inline std::ostream& operator<<( std::ostream& s, const sink& )
{
return s << '?';
}
struct holder
{
virtual ~holder()
{}
virtual void serialize( std::ostream& s ) const = 0;
};
template< typename T >
struct holder_imp : holder
{
explicit holder_imp( const T& t )
: t_( boost::addressof( t ) )
{}
virtual void serialize( std::ostream& s ) const
{
// if an error about an ambiguous conversion is generated by the
// line below the solution is to add a serialization operator to a
// mock::stream for T
s << *t_;
}
const T* t_;
};
struct data
{
template< typename T >
data( const T& t )
: h_( new holder_imp< T >( t ) )
{}
~data()
{
delete h_;
}
holder* h_;
};
}
inline stream& operator<<( stream& s, const detail3::data& d )
{
d.h_->serialize( *s.s_ );
return s;
}
#else // MOCK_USE_CONVERSIONS
namespace detail3
{
template< typename S, typename T >
S& operator<<( S &s, const T& )
{
return s << '?';
}
}
template< typename T >
stream& operator<<( stream& s, const T& t )
{
using namespace detail3;
*s.s_ << t;
return s;
}
#endif // MOCK_USE_CONVERSIONS
namespace detail2
namespace detail
{
template< typename T >
void serialize( stream& s, const T& t )
void serialize( stream& s, const T& begin, const T& end )
{
// if an error about an ambiguous conversion is generated by the
// line below the solution is to add a serialization operator to a
// mock::stream for T
s << t;
}
inline void serialize( stream& s, bool b )
{
s << (b ? "true" : "false");
}
template< typename C, typename T, typename A >
void serialize( stream& s, const std::basic_string< C, T, A >& str )
{
s << '"' << str << '"';
}
inline void serialize( stream& s, const char* const str )
{
s << '"' << str << '"';
}
inline void serialize( stream& s, unsigned char c )
{
s << static_cast< int >( c );
}
template< typename T >
struct formatter
{
explicit formatter( const T& t )
: t_( boost::addressof( t ) )
{}
void serialize( stream& s ) const
{
mock::detail2::serialize( s, *t_ );
}
const T* t_;
};
template< typename T >
stream& operator<<( stream& s, const formatter< T >& ser )
{
ser.serialize( s );
return s;
}
template< typename T >
std::ostream& operator<<( std::ostream& s, const formatter< T >& ser )
{
stream ss( s );
ser.serialize( ss );
return s;
s << '(';
for( T it = begin; it != end; ++it )
s << (it == begin ? "" : ",") << mock::format( *it );
s << ')';
}
}
template< typename T >
detail2::formatter< T > format( const T& t )
{
return detail2::formatter< T >( t );
}
template< typename T >
stream& operator<<( stream& s, const std::auto_ptr< T >& t )
{
@ -201,18 +62,6 @@ namespace detail2
<< ',' << mock::format( p.second ) << ')';
}
namespace detail
{
template< typename T >
void serialize( stream& s, const T& begin, const T& end )
{
s << '(';
for( T it = begin; it != end; ++it )
s << (it == begin ? "" : ",") << mock::format( *it );
s << ')';
}
}
template< typename T, typename A >
stream& operator<<( stream& s, const std::deque< T, A >& t )
{

141
turtle/stream.hpp Normal file
View file

@ -0,0 +1,141 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2011
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef MOCK_STREAM_HPP_INCLUDED
#define MOCK_STREAM_HPP_INCLUDED
#include <boost/utility/addressof.hpp>
#include <ostream>
namespace mock
{
struct stream
{
explicit stream( std::ostream& s )
: s_( &s )
{}
std::ostream* s_;
};
#ifdef MOCK_USE_CONVERSIONS
namespace detail
{
namespace conversion
{
struct sink
{
template< typename T >
sink( const T& )
{}
};
inline std::ostream& operator<<( std::ostream& s, const sink& )
{
return s << '?';
}
struct holder
{
virtual ~holder()
{}
virtual void serialize( std::ostream& s ) const = 0;
};
template< typename T >
struct holder_imp : holder
{
explicit holder_imp( const T& t )
: t_( boost::addressof( t ) )
{}
virtual void serialize( std::ostream& s ) const
{
// if an error about an ambiguous conversion is generated by the
// line below the solution is to add a serialization operator to a
// mock::stream for T
s << *t_;
}
const T* t_;
};
struct data
{
template< typename T >
data( const T& t )
: h_( new holder_imp< T >( t ) )
{}
~data()
{
delete h_;
}
holder* h_;
};
}
}
inline stream& operator<<( stream& s, const detail::conversion::data& d )
{
d.h_->serialize( *s.s_ );
return s;
}
#else // MOCK_USE_CONVERSIONS
namespace detail
{
namespace conversion
{
template< typename S, typename T >
S& operator<<( S &s, const T& )
{
return s << '?';
}
}
}
template< typename T >
stream& operator<<( stream& s, const T& t )
{
using namespace detail::conversion;
*s.s_ << t;
return s;
}
#endif // MOCK_USE_CONVERSIONS
namespace detail
{
template< typename T >
void serialize( stream& s, const T& t )
{
// if an error about an ambiguous conversion is generated by the
// line below the solution is to add a serialization operator to a
// mock::stream for T
s << t;
}
inline void serialize( stream& s, bool b )
{
s << (b ? "true" : "false");
}
template< typename C, typename T, typename A >
void serialize( stream& s, const std::basic_string< C, T, A >& str )
{
s << '"' << str << '"';
}
inline void serialize( stream& s, const char* const str )
{
s << '"' << str << '"';
}
inline void serialize( stream& s, unsigned char c )
{
s << static_cast< int >( c );
}
}
} // mock
#endif // MOCK_STREAM_HPP_INCLUDED