Cope nicely if the user has a configured default container ratio which is now disallowed.
[dcpomatic.git] / src / lib / ratio.h
1 /*
2     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #ifndef DCPOMATIC_RATIO_H
22 #define DCPOMATIC_RATIO_H
23
24 #include <dcp/util.h>
25 #include <boost/utility.hpp>
26 #include <vector>
27
28 class Ratio : public boost::noncopyable
29 {
30 public:
31         Ratio (float ratio, std::string id, std::string in, boost::optional<std::string> cn, std::string d)
32                 : _ratio (ratio)
33                 , _id (id)
34                 , _image_nickname (in)
35                 , _container_nickname (cn)
36                 , _isdcf_name (d)
37         {}
38
39         std::string id () const {
40                 return _id;
41         }
42
43         std::string image_nickname () const {
44                 return _image_nickname;
45         }
46
47         std::string container_nickname () const;
48
49         bool used_for_container () const {
50                 return static_cast<bool> (_container_nickname);
51         }
52
53         std::string isdcf_name () const {
54                 return _isdcf_name;
55         }
56
57         float ratio () const {
58                 return _ratio;
59         }
60
61         static void setup_ratios ();
62         static Ratio const * from_id (std::string i);
63         static Ratio const * from_ratio (float r);
64         static Ratio const * nearest_from_ratio (float r);
65
66         static std::vector<Ratio const *> all () {
67                 return _ratios;
68         }
69
70         static std::vector<Ratio const *> containers ();
71
72 private:
73         float _ratio;
74         /** id for use in metadata */
75         std::string _id;
76         /** nickname when used to describe an image ratio (e.g. Flat, Scope) */
77         std::string _image_nickname;
78         /** nickname when used to describe a container ratio */
79         boost::optional<std::string> _container_nickname;
80         std::string _isdcf_name;
81
82         static std::vector<Ratio const *> _ratios;
83 };
84
85 #endif