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.
equalsconstraint.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_EQUALSCONSTRAINT_H
8 #define IGLOO_EQUALSCONSTRAINT_H
9 
10 #include "./expressions/expression.h"
11 
12 namespace snowhouse {
13 
14  template< typename ExpectedType >
15  struct EqualsConstraint : Expression< EqualsConstraint<ExpectedType> >
16  {
17  EqualsConstraint(const ExpectedType& expected)
18  : m_expected(expected)
19  {
20  }
21 
22  template<typename ActualType>
23  bool operator()(const ActualType& actual) const
24  {
25  return (m_expected == actual);
26  }
27 
28  ExpectedType m_expected;
29  };
30 
31  template< typename ExpectedType >
32  inline EqualsConstraint<ExpectedType> Equals(const ExpectedType& expected)
33  {
34  return EqualsConstraint<ExpectedType>(expected);
35  }
36 
37  inline EqualsConstraint<std::string> Equals(const char* expected)
38  {
39  return EqualsConstraint<std::string>(expected);
40  }
41 
42  inline EqualsConstraint<bool> IsFalse()
43  {
44  return EqualsConstraint<bool>(false);
45  }
46 
47  inline EqualsConstraint<bool> IsTrue()
48  {
49  return EqualsConstraint<bool>(true);
50  }
51 
52  template <>
53  struct Stringizer< EqualsConstraint< bool > >
54  {
55  static std::string ToString(const EqualsConstraint<bool>& constraint)
56  {
57  return constraint.m_expected ? "true" : "false";
58  }
59  };
60 
61  template< typename ExpectedType >
62  struct Stringizer< EqualsConstraint< ExpectedType > >
63  {
64  static std::string ToString(const EqualsConstraint<ExpectedType>& constraint)
65  {
66  std::ostringstream builder;
67  builder << "equal to " << snowhouse::Stringize(constraint.m_expected);
68 
69  return builder.str();
70  }
71  };
72 }
73 
74 #endif
Definition: assert.h:13
Definition: equalsconstraint.h:15
Definition: stringize.h:71
Definition: expression.h:17