Remove unnecessary 0 checks before delete; see http://www.parashift.com/c++-faq-lite...
[ardour.git] / libs / ardour / export_format_base.cc
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
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
21 #include <ardour/export_format_base.h>
22
23 namespace ARDOUR
24 {
25
26 void
27 ExportFormatBase::SelectableCompatible::set_selected (bool value)
28 {
29         if (_selected != value) {
30                 _selected = value;
31                 SelectChanged (value);
32         }
33 }
34
35 void
36 ExportFormatBase::SelectableCompatible::set_compatible (bool value)
37 {
38         if (_compatible != value) {
39                 _compatible = value;
40                 CompatibleChanged (value);
41         }
42         if (!value) {
43                 set_selected (false);
44         }
45 }
46
47 ExportFormatBase::ExportFormatBase ()
48 {
49         
50 }
51
52 ExportFormatBase::ExportFormatBase (ExportFormatBase const & other) :
53   sample_formats (other.sample_formats),
54   endiannesses (other.endiannesses),
55   sample_rates (other.sample_rates),
56   format_ids (other.format_ids),
57   qualities (other.qualities)
58 {
59
60 }
61
62 ExportFormatBase::~ExportFormatBase ()
63 {
64         
65 }
66
67 boost::shared_ptr<ExportFormatBase>
68 ExportFormatBase::get_intersection (ExportFormatBase const & other) const
69 {
70         return do_set_operation (other, SetIntersection);
71 }
72
73 boost::shared_ptr<ExportFormatBase>
74 ExportFormatBase::get_difference (ExportFormatBase const & other) const
75 {
76         return do_set_operation (other, SetDifference);
77 }
78
79 boost::shared_ptr<ExportFormatBase>
80 ExportFormatBase::get_union (ExportFormatBase const & other) const
81 {
82         return do_set_operation (other, SetUnion);
83 }
84
85 boost::shared_ptr<ExportFormatBase>
86 ExportFormatBase::do_set_operation (ExportFormatBase const & other, SetOperation operation) const
87 {
88         boost::shared_ptr<ExportFormatBase> result (new ExportFormatBase ());
89         
90         /* Sets */
91         
92         // Endiannesses
93         {
94                 EndianSet::const_iterator start1 = endiannesses.begin();
95                 EndianSet::const_iterator end1 = endiannesses.end();
96                 EndianSet::const_iterator start2 = other.endiannesses.begin();
97                 EndianSet::const_iterator end2 = other.endiannesses.end();
98                 std::insert_iterator<EndianSet> insert (result->endiannesses, result->endiannesses.begin());
99                 
100                 switch (operation) {
101                   case SetIntersection:
102                         std::set_intersection (start1, end1, start2, end2, insert);
103                         break;
104                   case SetDifference:
105                         std::set_difference (start1, end1, start2, end2, insert);
106                         break;
107                   case SetUnion:
108                         std::set_union (start1, end1, start2, end2, insert);
109                         break;
110                 }
111         }
112                 
113         // Sample formats
114         {
115                 SampleFormatSet::const_iterator start1 = sample_formats.begin();
116                 SampleFormatSet::const_iterator end1 = sample_formats.end();
117                 SampleFormatSet::const_iterator start2 = other.sample_formats.begin();
118                 SampleFormatSet::const_iterator end2 = other.sample_formats.end();
119                 std::insert_iterator<SampleFormatSet> insert (result->sample_formats, result->sample_formats.begin());
120                 
121                 switch (operation) {
122                   case SetIntersection:
123                         std::set_intersection (start1, end1, start2, end2, insert);
124                         break;
125                   case SetDifference:
126                         std::set_difference (start1, end1, start2, end2, insert);
127                         break;
128                   case SetUnion:
129                         std::set_union (start1, end1, start2, end2, insert);
130                         break;
131                 }
132         }
133         
134                 
135         // Sample rates
136         {
137                 SampleRateSet::const_iterator start1 = sample_rates.begin();
138                 SampleRateSet::const_iterator end1 = sample_rates.end();
139                 SampleRateSet::const_iterator start2 = other.sample_rates.begin();
140                 SampleRateSet::const_iterator end2 = other.sample_rates.end();
141                 std::insert_iterator<SampleRateSet> insert (result->sample_rates, result->sample_rates.begin());
142         
143                 switch (operation) {
144                   case SetIntersection:
145                         std::set_intersection (start1, end1, start2, end2, insert);
146                         break;
147                   case SetDifference:
148                         std::set_difference (start1, end1, start2, end2, insert);
149                         break;
150                   case SetUnion:
151                         std::set_union (start1, end1, start2, end2, insert);
152                         break;
153                 }
154         }
155         
156         // Format ids
157         {
158                 FormatSet::const_iterator start1 = format_ids.begin();
159                 FormatSet::const_iterator end1 = format_ids.end();
160                 FormatSet::const_iterator start2 = other.format_ids.begin();
161                 FormatSet::const_iterator end2 = other.format_ids.end();
162                 std::insert_iterator<FormatSet> insert (result->format_ids, result->format_ids.begin());
163         
164                 switch (operation) {
165                   case SetIntersection:
166                         std::set_intersection (start1, end1, start2, end2, insert);
167                         break;
168                   case SetDifference:
169                         std::set_difference (start1, end1, start2, end2, insert);
170                         break;
171                   case SetUnion:
172                         std::set_union (start1, end1, start2, end2, insert);
173                         break;
174                 }
175         }
176         
177         // Qualities
178         {
179                 QualitySet::const_iterator start1 = qualities.begin();
180                 QualitySet::const_iterator end1 = qualities.end();
181                 QualitySet::const_iterator start2 = other.qualities.begin();
182                 QualitySet::const_iterator end2 = other.qualities.end();
183                 std::insert_iterator<QualitySet> insert (result->qualities, result->qualities.begin());
184         
185                 switch (operation) {
186                   case SetIntersection:
187                         std::set_intersection (start1, end1, start2, end2, insert);
188                         break;
189                   case SetDifference:
190                         std::set_difference (start1, end1, start2, end2, insert);
191                         break;
192                   case SetUnion:
193                         std::set_union (start1, end1, start2, end2, insert);
194                         break;
195                 }
196         }
197         
198         return result;
199 }
200
201 }; // namespace ARDOUR