Move things round a bit.
[dcpomatic.git] / src / lib / dcp_content_type.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
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 2 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, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file src/content_type.cc
21  *  @brief A description of the type of content for a DCP (e.g. feature, trailer etc.)
22  */
23
24 #include <cassert>
25 #include "dcp_content_type.h"
26
27 using namespace std;
28
29 vector<DCPContentType const *> DCPContentType::_dcp_content_types;
30
31 DCPContentType::DCPContentType (string p, string o)
32         : _pretty_name (p)
33         , _opendcp_name (o)
34 {
35
36 }
37
38 void
39 DCPContentType::setup_dcp_content_types ()
40 {
41         _dcp_content_types.push_back (new DCPContentType ("Feature", "feature"));
42         _dcp_content_types.push_back (new DCPContentType ("Short", "short"));
43         _dcp_content_types.push_back (new DCPContentType ("Trailer", "trailer"));
44         _dcp_content_types.push_back (new DCPContentType ("Test", "test"));
45         _dcp_content_types.push_back (new DCPContentType ("Transitional", "transitional"));
46         _dcp_content_types.push_back (new DCPContentType ("Rating", "rating"));
47         _dcp_content_types.push_back (new DCPContentType ("Teaser", "teaster"));
48         _dcp_content_types.push_back (new DCPContentType ("Policy", "policy"));
49         _dcp_content_types.push_back (new DCPContentType ("Public Service Announcement", "psa"));
50         _dcp_content_types.push_back (new DCPContentType ("Advertisement", "advertisement"));
51 }
52
53 DCPContentType const *
54 DCPContentType::from_pretty_name (string n)
55 {
56         for (vector<DCPContentType const *>::const_iterator i = _dcp_content_types.begin(); i != _dcp_content_types.end(); ++i) {
57                 if ((*i)->pretty_name() == n) {
58                         return *i;
59                 }
60         }
61
62         return 0;
63 }
64
65 DCPContentType const *
66 DCPContentType::from_index (int n)
67 {
68         assert (n >= 0 && n < int (_dcp_content_types.size ()));
69         return _dcp_content_types[n];
70 }
71
72 int
73 DCPContentType::as_index (DCPContentType const * c)
74 {
75         vector<DCPContentType*>::size_type i = 0;
76         while (i < _dcp_content_types.size() && _dcp_content_types[i] != c) {
77                 ++i;
78         }
79
80         if (i == _dcp_content_types.size ()) {
81                 return -1;
82         }
83
84         return i;
85 }
86
87 vector<DCPContentType const *>
88 DCPContentType::all ()
89 {
90         return _dcp_content_types;
91 }