VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
grdef.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file grdef.h
19 ///
20 
21 #ifndef GR_DEF__H
22 #define GR_DEF__H
23 
24 #include "gdef.h"
25 #include <algorithm>
26 #include <utility>
27 
28 namespace Gr
29 {
30  inline
31  int scaled( int n , int scale )
32  {
33  return n > 0 ? ( scale == 1 ? n : ( 1 + (n-1)/std::max(1,scale) ) ) : 0 ;
34  }
35 
36  inline
37  size_t sizet( int a )
38  {
39  return a >= 0 ? static_cast<size_t>(a) : size_t(0U) ;
40  }
41 
42  inline
43  size_t sizet( int a , int b )
44  {
45  return sizet(a) * sizet(b) ;
46  }
47 
48  inline
49  size_t sizet( int a , int b , int c )
50  {
51  return sizet(a) * sizet(b) * sizet(c) ;
52  }
53 
54  template <typename T>
55  struct add_size
56  {
57  explicit add_size( size_t & n ) : m_n(n) {}
58  void operator()( const T & a ) { m_n += a.size() ; }
59  size_t & m_n ;
60  } ;
61 }
62 
63 #endif