TooN
overfill_error.hh
1 //Copyright (C) Edward Rosten 2009, 2010
2 
3 //All rights reserved.
4 //
5 //Redistribution and use in source and binary forms, with or without
6 //modification, are permitted provided that the following conditions
7 //are met:
8 //1. Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //2. Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 //
14 //THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
15 //AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 //IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 //ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
18 //LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 //CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 //SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 //INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 //CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 //ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 //POSSIBILITY OF SUCH DAMAGE.
25 
26 namespace TooN{
27 namespace Internal{
28 
29 template<bool b> struct overfill;
30 template<> struct overfill<0>{};
31 
32 template<int N, int Size> struct CheckOverFill
33 {
34  static void check(int)
35  {
36  #ifdef TOON_TEST_INTERNALS
37  if(N >= Size)
38  throw StaticVectorOverfill();
39  #else
40  Internal::overfill<(N>=Size)> overfilled_vector;
41  #endif
42  };
43 };
44 
45 template<int N> struct CheckOverFill<N, -1>
46 {
47  static void use(int){}
48  static void check(int s)
49  {
50  use(s);
51  #ifdef TOON_TEST_INTERNALS
52  if(N >= s)
53  throw VectorOverfill();
54  #elif !defined TOON_NDEBUG_FILL
55  if(N >= s)
56  {
57  std::cerr << "TooN overfilled vector" << std::endl;
58  std::abort();
59  }
60  #endif
61  };
62 };
63 
64 
65 template<int N, int R, int C, bool IsDynamic=(R==-1||C==-1)> struct CheckMOverFill
66 {
67  static void check(int)
68  {
69  #ifdef TOON_TEST_INTERNALS
70  if(N >= R*C)
71  throw StaticMatrixOverfill();
72  #else
73  Internal::overfill<(N>=R*C)>();
74  #endif
75  }
76 };
77 
78 template<int N, int R, int C> struct CheckMOverFill<N, R, C, 1>
79 {
80  static void check(int s)
81  {
82  #ifdef TOON_TEST_INTERNALS
83  if(N >= s)
84  throw StaticMatrixOverfill();
85  #else
86  if(N >= s)
87  {
88  std::cerr << "TooN overfilled matrix" << std::endl;
89  std::abort();
90  }
91  #endif
92  }
93 };
94 
95 }}
Definition: overfill_error.hh:65
Pretty generic SFINAE introspection generator.
Definition: vec_test.cc:21
Definition: overfill_error.hh:32
Definition: overfill_error.hh:78
Definition: overfill_error.hh:29