Use a C++ bool constant
[ardour.git] / gtk2_ardour / item_counts.h
1 /*
2     Copyright (C) 2014 Paul Davis
3     Author: David Robillard
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __ardour_item_counts_h__
21 #define __ardour_item_counts_h__
22
23 #include <cstddef>
24 #include <map>
25 #include <utility>
26
27 #include "ardour/data_type.h"
28 #include "evoral/Parameter.hpp"
29
30 /** A count of various GUI items.
31  *
32  * This is used to keep track of 'consumption' of a selection when pasting, but
33  * may be useful elsewhere.
34  */
35 class ItemCounts
36 {
37 public:
38         ItemCounts() : _notes(0) {}
39
40         size_t n_playlists(ARDOUR::DataType t) const { return get_n(t, _playlists); }
41         size_t n_regions(ARDOUR::DataType t)   const { return get_n(t, _regions); }
42         size_t n_lines(Evoral::Parameter t)    const { return get_n(t, _lines); }
43         size_t n_notes()                       const { return _notes; }
44
45         void increase_n_playlists(ARDOUR::DataType t, size_t delta=1) {
46                 increase_n(t, _playlists, delta);
47         }
48
49         void increase_n_regions(ARDOUR::DataType t, size_t delta=1) {
50                 increase_n(t, _regions, delta);
51         }
52
53         void increase_n_lines(Evoral::Parameter t, size_t delta=1) {
54                 increase_n(t, _lines, delta);
55         }
56
57         void increase_n_notes(size_t delta=1) { _notes += delta; }
58
59 private:
60         template<typename Key>
61         size_t
62         get_n(const Key& key, const typename std::map<Key, size_t>& counts) const {
63                 typename std::map<Key, size_t>::const_iterator i = counts.find(key);
64                 return (i == counts.end()) ? 0 : i->second;
65         }
66
67         template<typename Key>
68         void
69         increase_n(const Key& key, typename std::map<Key, size_t>& counts, size_t delta) {
70                 typename std::map<Key, size_t>::iterator i = counts.find(key);
71                 if (i != counts.end()) {
72                         i->second += delta;
73                 } else {
74                         counts.insert(std::make_pair(key, delta));
75                 }
76         }
77
78         std::map<ARDOUR::DataType,  size_t> _playlists;
79         std::map<ARDOUR::DataType,  size_t> _regions;
80         std::map<Evoral::Parameter, size_t> _lines;
81         size_t                              _notes;
82 };
83
84 #endif /* __ardour_item_counts_h__ */