Loading...
Searching...
No Matches
StdValueTraits.h
Go to the documentation of this file.
#ifndef __cxxtest_StdValueTraits_h__
#define __cxxtest_StdValueTraits_h__
//
// This file defines ValueTraits for std:: stuff.
// It is #included by <cxxtest/ValueTraits.h> if you
// define CXXTEST_HAVE_STD
//
#include <cxxtest/ValueTraits.h>
#include <cxxtest/StdHeaders.h>
#ifdef _CXXTEST_OLD_STD
# define CXXTEST_STD(x) x
#else // !_CXXTEST_OLD_STD
# define CXXTEST_STD(x) std::x
#endif // _CXXTEST_OLD_STD
#ifndef CXXTEST_USER_VALUE_TRAITS
namespace CxxTest
{
//
// NOTE: This should have been
// template<class Char, class Traits, class Allocator>
// class ValueTraits< std::basic_string<Char, Traits, Allocator> > {};
// But MSVC doesn't support it (yet).
//
//
// If we have std::string, we might as well use it
//
class StdTraitsBase
{
public:
StdTraitsBase &operator<<( const CXXTEST_STD(string) &s ) { _s += s; return *this; }
const char *asString() const { return _s.c_str(); }
private:
CXXTEST_STD(string) _s;
};
//
// std::string
//
CXXTEST_TEMPLATE_INSTANTIATION
class ValueTraits<const CXXTEST_STD(string)> : public StdTraitsBase
{
public:
ValueTraits( const CXXTEST_STD(string) &s )
{
*this << "\"";
for ( unsigned i = 0; i < s.length(); ++ i ) {
char c[sizeof("\\xXX")];
charToString( s[i], c );
*this << c;
}
*this << "\"";
}
};
CXXTEST_COPY_CONST_TRAITS( CXXTEST_STD(string) );
#ifndef _CXXTEST_OLD_STD
//
// std::wstring
//
CXXTEST_TEMPLATE_INSTANTIATION
class ValueTraits<const CXXTEST_STD(basic_string<wchar_t>)> : public StdTraitsBase
{
public:
ValueTraits( const CXXTEST_STD(basic_string<wchar_t>) &s )
{
*this << "L\"";
for ( unsigned i = 0; i < s.length(); ++ i ) {
char c[sizeof("\\x12345678")];
charToString( (unsigned long)s[i], c );
*this << c;
}
*this << "\"";
}
};
CXXTEST_COPY_CONST_TRAITS( CXXTEST_STD(basic_string<wchar_t>) );
#endif // _CXXTEST_OLD_STD
//
// Convert a range defined by iterators to a string
// This is useful for almost all STL containers
//
template<class Stream, class Iterator>
void dumpRange( Stream &s, Iterator first, Iterator last )
{
s << "{ ";
while ( first != last ) {
s << TS_AS_STRING(*first);
++ first;
s << ((first == last) ? " }" : ", ");
}
}
#ifdef _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
//
// std::pair
//
template<class First, class Second>
class ValueTraits< CXXTEST_STD(pair)<First, Second> > : public StdTraitsBase
{
public:
ValueTraits( const CXXTEST_STD(pair)<First, Second> &p )
{
*this << "<" << TS_AS_STRING( p.first ) << ", " << TS_AS_STRING( p.second ) << ">";
}
};
//
// std::vector
//
template<class Element>
class ValueTraits< CXXTEST_STD(vector)<Element> > : public StdTraitsBase
{
public:
ValueTraits( const CXXTEST_STD(vector)<Element> &v )
{
dumpRange( *this, v.begin(), v.end() );
}
};
//
// std::list
//
template<class Element>
class ValueTraits< CXXTEST_STD(list)<Element> > : public StdTraitsBase
{
public:
ValueTraits( const CXXTEST_STD(list)<Element> &l )
{
dumpRange( *this, l.begin(), l.end() );
}
};
//
// std::set
//
template<class Element>
class ValueTraits< CXXTEST_STD(set)<Element> > : public StdTraitsBase
{
public:
ValueTraits( const CXXTEST_STD(set)<Element> &s )
{
dumpRange( *this, s.begin(), s.end() );
}
};
//
// std::map
//
template<class Key, class Value>
class ValueTraits< CXXTEST_STD(map)<Key, Value> > : public StdTraitsBase
{
public:
ValueTraits( const CXXTEST_STD(map)<Key, Value> &m )
{
dumpRange( *this, m.begin(), m.end() );
}
};
//
// std::deque
//
template<class Element>
class ValueTraits< CXXTEST_STD(deque)<Element> > : public StdTraitsBase
{
public:
ValueTraits( const CXXTEST_STD(deque)<Element> &d )
{
dumpRange( *this, d.begin(), d.end() );
}
};
//
// std::multiset
//
template<class Element>
class ValueTraits< CXXTEST_STD(multiset)<Element> > : public StdTraitsBase
{
public:
ValueTraits( const CXXTEST_STD(multiset)<Element> &ms )
{
dumpRange( *this, ms.begin(), ms.end() );
}
};
//
// std::multimap
//
template<class Key, class Value>
class ValueTraits< CXXTEST_STD(multimap)<Key, Value> > : public StdTraitsBase
{
public:
ValueTraits( const CXXTEST_STD(multimap)<Key, Value> &mm )
{
dumpRange( *this, mm.begin(), mm.end() );
}
};
//
// std::complex
//
template<class Number>
class ValueTraits< CXXTEST_STD(complex)<Number> > : public StdTraitsBase
{
public:
ValueTraits( const CXXTEST_STD(complex)<Number> &c )
{
if ( !c.imag() )
*this << TS_AS_STRING(c.real());
else if ( !c.real() )
*this << "(" << TS_AS_STRING(c.imag()) << " * i)";
else
*this << "(" << TS_AS_STRING(c.real()) << " + " << TS_AS_STRING(c.imag()) << " * i)";
}
};
#endif // _CXXTEST_PARTIAL_TEMPLATE_SPECIALIZATION
};
#endif // CXXTEST_USER_VALUE_TRAITS
#endif // __cxxtest_StdValueTraits_h__
StdHeaders.h
CXXTEST_STD
#define CXXTEST_STD(x)
Definition StdValueTraits.h:16
ValueTraits.h
CXXTEST_TEMPLATE_INSTANTIATION
#define CXXTEST_TEMPLATE_INSTANTIATION
Definition ValueTraits.h:18
CXXTEST_COPY_CONST_TRAITS
#define CXXTEST_COPY_CONST_TRAITS(CXXTEST_CLASS)
Definition ValueTraits.h:113
TS_AS_STRING
#define TS_AS_STRING(x)
Definition ValueTraits.h:26
l
int l
Definition cfEzgcd.cc:100
m
int m
Definition cfEzgcd.cc:128
i
int i
Definition cfEzgcd.cc:132
p
int p
Definition cfModGcd.cc:4086
map
CanonicalForm map(const CanonicalForm &primElem, const Variable &alpha, const CanonicalForm &F, const Variable &beta)
map from to such that is mapped onto
Definition cf_map_ext.cc:505
CxxTest::StdTraitsBase
Definition StdValueTraits.h:34
CxxTest::StdTraitsBase::asString
const char * asString() const
Definition StdValueTraits.h:37
CxxTest::StdTraitsBase::operator<<
StdTraitsBase & operator<<(const CXXTEST_STD(string) &s)
Definition StdValueTraits.h:36
CxxTest::StdTraitsBase::CXXTEST_STD
CXXTEST_STD(string) _s
CxxTest::ValueTraits< const CXXTEST_STD(basic_string< wchar_t >)>::ValueTraits
ValueTraits(const CXXTEST_STD(basic_string< wchar_t >) &s)
Definition StdValueTraits.h:72
CxxTest::ValueTraits< const CXXTEST_STD(string)>::ValueTraits
ValueTraits(const CXXTEST_STD(string) &s)
Definition StdValueTraits.h:50
CxxTest::ValueTraits
Definition ValueTraits.h:75
CxxTest::ValueTraits::ValueTraits
ValueTraits(const T &t)
Definition ValueTraits.h:80
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
const
#define const
Definition fegetopt.c:39
last
STATIC_VAR poly last
Definition hdegree.cc:1138
string
#define string
Definition libparse.cc:1252
CxxTest
Definition Descriptions.cpp:7
CxxTest::dumpRange
void dumpRange(Stream &s, Iterator first, Iterator last)
Definition StdValueTraits.h:92
CxxTest::charToString
char * charToString(unsigned long c, char *s)
Definition ValueTraits.cpp:48
CxxTest::s
char * s
Definition ValueTraits.h:143