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.
startswithconstraint.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_STARTSWITHCONSTRAINT_H
8 #define IGLOO_STARTSWITHCONSTRAINT_H
9 
10 #include "./expressions/expression.h"
11 
12 namespace snowhouse {
13 
14  template <typename ExpectedType>
15  struct StartsWithConstraint : Expression< StartsWithConstraint<ExpectedType> >
16  {
17  StartsWithConstraint(const ExpectedType& expected)
18  : m_expected(expected) {}
19 
20  bool operator()(const std::string& actual) const
21  {
22  return actual.find(m_expected) == 0;
23  }
24 
25  ExpectedType m_expected;
26  };
27 
28  template< typename ExpectedType >
29  inline StartsWithConstraint<ExpectedType> StartsWith(const ExpectedType& expected)
30  {
31  return StartsWithConstraint<ExpectedType>(expected);
32  }
33 
34  inline StartsWithConstraint<std::string> StartsWith(const char* expected)
35  {
36  return StartsWithConstraint<std::string>(expected);
37  }
38 
39  template< typename ExpectedType >
40  struct Stringizer< StartsWithConstraint< ExpectedType > >
41  {
42  static std::string ToString(const StartsWithConstraint<ExpectedType>& constraint)
43  {
44  std::ostringstream builder;
45  builder << "starts with " << snowhouse::Stringize(constraint.m_expected);
46 
47  return builder.str();
48  }
49  };
50 }
51 
52 #endif
Definition: assert.h:13
Definition: startswithconstraint.h:15
Definition: stringize.h:71
Definition: expression.h:17