1 // Copyright (C) 2007  Davis E. King (davis@dlib.net)
2 // License: Boost Software License   See LICENSE.txt for the full license.
3 #ifndef DLIB_IS_KINd_H_
4 #define DLIB_IS_KINd_H_
5 
6 #include <vector>
7 
8 namespace dlib
9 {
10     /*!
11         This file contains a set of templates that enable you to determine if
12         a given type implements an abstract interface defined in one of the
13         dlib *_abstract.h files.
14     !*/
15 
16 // ----------------------------------------------------------------------------------------
17 
18     struct default_is_kind_value { static const bool value = false; };
19 
20 // ----------------------------------------------------------------------------------------
21 
22     template <typename T>
23     struct is_graph : public default_is_kind_value
24     {
25         /*!
26             - if (T is an implementation of graph/graph_kernel_abstract.h) then
27                 - is_graph<T>::value == true
28             - else
29                 - is_graph<T>::value == false
30         !*/
31     };
32 
33 // ----------------------------------------------------------------------------------------
34 
35     template <typename T>
36     struct is_directed_graph : public default_is_kind_value
37     {
38         /*!
39             - if (T is an implementation of directed_graph/directed_graph_kernel_abstract.h) then
40                 - is_directed_graph<T>::value == true
41             - else
42                 - is_directed_graph<T>::value == false
43         !*/
44     };
45 
46 // ----------------------------------------------------------------------------------------
47 
48     template <typename T, typename helper = void>
49     struct is_matrix : public default_is_kind_value
50     {
51         /*!
52             - if (T is some kind of matrix expression from the matrix/matrix_exp_abstract.h component) then
53                 - is_matrix<T>::value == true
54             - else
55                 - is_matrix<T>::value == false
56         !*/
57 
58         // Don't set the helper to anything.  Just let it be void.
59         ASSERT_ARE_SAME_TYPE(helper,void);
60     };
61 
62 // ----------------------------------------------------------------------------------------
63 
64     template <typename T>
65     struct is_array2d : public default_is_kind_value
66     {
67         /*!
68             - if (T is an implementation of array2d/array2d_kernel_abstract.h) then
69                 - is_array2d<T>::value == true
70             - else
71                 - is_array2d<T>::value == false
72         !*/
73     };
74 
75 // ----------------------------------------------------------------------------------------
76 
77     template <typename T>
78     struct is_array : public default_is_kind_value
79     {
80         /*!
81             - if (T is an implementation of array/array_kernel_abstract.h) then
82                 - is_array<T>::value == true
83             - else
84                 - is_array<T>::value == false
85         !*/
86     };
87 
88 // ----------------------------------------------------------------------------------------
89 
90     template <typename T>
91     struct is_std_vector : public default_is_kind_value
92     {
93         /*!
94             - if (T is an implementation of the standard C++ std::vector object) then
95                 - is_std_vector<T>::value == true
96             - else
97                 - is_std_vector<T>::value == false
98         !*/
99     };
100 
101 // ----------------------------------------------------------------------------------------
102 
103     template <typename T>
104     struct is_pair : public default_is_kind_value
105     {
106         /*!
107             - if (T is a std::pair object) then
108                 - is_std_vector<T>::value == true
109             - else
110                 - is_std_vector<T>::value == false
111         !*/
112     };
113 
114 // ----------------------------------------------------------------------------------------
115 
116     template <typename T>
117     struct is_rand : public default_is_kind_value
118     {
119         /*!
120             - if (T is an implementation of rand/rand_kernel_abstract.h) then
121                 - is_rand<T>::value == true
122             - else
123                 - is_rand<T>::value == false
124         !*/
125     };
126 
127 // ----------------------------------------------------------------------------------------
128 
129     template <typename T>
130     struct is_config_reader : public default_is_kind_value
131     {
132         /*!
133             - if (T is an implementation of config_reader/config_reader_kernel_abstract.h) then
134                 - is_config_reader<T>::value == true
135             - else
136                 - is_config_reader<T>::value == false
137         !*/
138     };
139 
140 // ----------------------------------------------------------------------------------------
141 // ----------------------------------------------------------------------------------------
142 //                              Implementation details
143 // ----------------------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------------------
145 
146     template <typename T, typename alloc>
147     struct is_std_vector<std::vector<T,alloc> >         { const static bool value = true; };
148     template <typename T> struct is_std_vector<T&>      { const static bool value = is_std_vector<T>::value; };
149     template <typename T> struct is_std_vector<const T&>{ const static bool value = is_std_vector<T>::value; };
150     template <typename T> struct is_std_vector<const T> { const static bool value = is_std_vector<T>::value; };
151 
152 // ----------------------------------------------------------------------------------------
153 
154     template <typename T, typename U>
155     struct is_pair<std::pair<T,U> > { const static bool value = true; };
156 
157 // ----------------------------------------------------------------------------------------
158 
159 }
160 
161 #endif // DLIB_IS_KINd_H_
162 
163