blitzdg
an open-source project aiming to implement parallel discontinuous Galerkin (dg) solvers for common partial differential equations systems using blitz++ for array and tensor manipulations and MPI for distributed parallelism.
endswithconstraint.h
1 
2 // Copyright Joakim Karlsson & Kim Gräsman 2010-2013.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 #ifndef IGLOO_ENDSWITHCONSTRAINT_H
8 #define IGLOO_ENDSWITHCONSTRAINT_H
9 
10 #include "./expressions/expression.h"
11 
12 namespace snowhouse {
13 
14  template <typename ExpectedType>
15  struct EndsWithConstraint : Expression< EndsWithConstraint<ExpectedType> >
16  {
17  EndsWithConstraint(const ExpectedType& expected)
18  : m_expected(expected) {}
19 
20  bool operator()(const std::string& actual) const
21  {
22  size_t expectedPos = actual.length() - m_expected.length();
23  return actual.find(m_expected) == expectedPos;
24  }
25 
26  ExpectedType m_expected;
27  };
28 
29  template< typename ExpectedType >
30  inline EndsWithConstraint<ExpectedType> EndsWith(const ExpectedType& expected)
31  {
32  return EndsWithConstraint<ExpectedType>(expected);
33  }
34 
35  inline EndsWithConstraint<std::string> EndsWith(const char* expected)
36  {
37  return EndsWithConstraint<std::string>(expected);
38  }
39 
40  template< typename ExpectedType >
41  struct Stringizer< EndsWithConstraint< ExpectedType > >
42  {
43  static std::string ToString(const EndsWithConstraint<ExpectedType>& constraint)
44  {
45  std::ostringstream builder;
46  builder << "ends with " << snowhouse::Stringize(constraint.m_expected);
47 
48  return builder.str();
49  }
50  };
51 }
52 
53 #endif
Definition: assert.h:13
Definition: endswithconstraint.h:15
Definition: stringize.h:71
Definition: expression.h:17