// Copyright Joakim Karlsson & Kim Gräsman 2010-2012. // 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 IGLOO_HASLENGTHCONSTRAINT_H #define IGLOO_HASLENGTHCONSTRAINT_H #include "./expressions/expression.h" namespace snowhouse { template struct HasLengthConstraint : Expression< HasLengthConstraint > { HasLengthConstraint(const ExpectedType& expected) : m_expected(expected) {} template bool operator()(const ActualType& actual) const { typedef typename ActualType::size_type SizeType; SizeType expectedSize = static_cast(m_expected); return (actual.size() == expectedSize); } ExpectedType m_expected; }; template< typename ExpectedType > inline HasLengthConstraint HasLength(const ExpectedType& expected) { return HasLengthConstraint(expected); } inline HasLengthConstraint IsEmpty() { return HasLength(0); } inline HasLengthConstraint HasLength(const char* expected) { return HasLengthConstraint(expected); } template< typename ExpectedType > struct Stringizer< HasLengthConstraint< ExpectedType > > { static std::string ToString(const HasLengthConstraint& constraint) { std::ostringstream builder; builder << "of length " << snowhouse::Stringize(constraint.m_expected); return builder.str(); } }; } #endif