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.
haslengthconstraint.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_HASLENGTHCONSTRAINT_H
8 #define IGLOO_HASLENGTHCONSTRAINT_H
9 
10 #include "./expressions/expression.h"
11 
12 namespace snowhouse {
13 
14  template <typename ExpectedType>
15  struct HasLengthConstraint : Expression< HasLengthConstraint<ExpectedType> >
16  {
17  HasLengthConstraint(const ExpectedType& expected)
18  : m_expected(expected) {}
19 
20  template <typename ActualType>
21  bool operator()(const ActualType& actual) const
22  {
23  typedef typename ActualType::size_type SizeType;
24  SizeType expectedSize = static_cast<SizeType>(m_expected);
25  return (actual.size() == expectedSize);
26  }
27 
28  ExpectedType m_expected;
29  };
30 
31  template< typename ExpectedType >
32  inline HasLengthConstraint<ExpectedType> HasLength(const ExpectedType& expected)
33  {
34  return HasLengthConstraint<ExpectedType>(expected);
35  }
36 
37  inline HasLengthConstraint<int> IsEmpty()
38  {
39  return HasLength<int>(0);
40  }
41 
42  inline HasLengthConstraint<std::string> HasLength(const char* expected)
43  {
44  return HasLengthConstraint<std::string>(expected);
45  }
46 
47  template< typename ExpectedType >
48  struct Stringizer< HasLengthConstraint< ExpectedType > >
49  {
50  static std::string ToString(const HasLengthConstraint<ExpectedType>& constraint)
51  {
52  std::ostringstream builder;
53  builder << "of length " << snowhouse::Stringize(constraint.m_expected);
54 
55  return builder.str();
56  }
57  };
58 }
59 
60 #endif
Definition: assert.h:13
Definition: haslengthconstraint.h:15
Definition: stringize.h:71
Definition: expression.h:17