libdcp
util.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
3 
4  This file is part of libdcp.
5 
6  libdcp 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  libdcp 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 libdcp. If not, see <http://www.gnu.org/licenses/>.
18 
19  In addition, as a special exception, the copyright holders give
20  permission to link the code of portions of this program with the
21  OpenSSL library under certain conditions as described in each
22  individual source file, and distribute linked combinations
23  including the two.
24 
25  You must obey the GNU General Public License in all respects
26  for all of the code used other than OpenSSL. If you modify
27  file(s) with this exception, you may extend this exception to your
28  version of the file(s), but you are not obligated to do so. If you
29  do not wish to do so, delete this exception statement from your
30  version. If you delete this exception statement from all source
31  files in the program, then also delete it here.
32 */
33 
34 
40 #ifndef LIBDCP_UTIL_H
41 #define LIBDCP_UTIL_H
42 
43 
44 #include "array_data.h"
45 #include "local_time.h"
46 #include "warnings.h"
47 LIBDCP_DISABLE_WARNINGS
48 #include <asdcp/KM_log.h>
49 LIBDCP_ENABLE_WARNINGS
50 #include <boost/filesystem.hpp>
51 #include <boost/function.hpp>
52 #include <boost/optional.hpp>
53 #include <memory>
54 #include <string>
55 #include <stdint.h>
56 
57 
58 /* windows.h defines this but we want to use it */
59 #undef ERROR
60 
61 
62 #define LIBDCP_UNUSED(x) (void)(x)
63 
64 
65 namespace ASDCP {
66  class Dictionary;
67 }
68 
69 
70 namespace xmlpp {
71  class Element;
72  class Node;
73 }
74 
75 
76 namespace dcp {
77 
78 
79 class CertificateChain;
80 class GammaLUT;
81 class OpenJPEGImage;
82 
83 
84 extern std::string make_uuid ();
85 
92 extern std::string make_digest(boost::filesystem::path filename, boost::function<void (int64_t, int64_t)>);
93 
94 extern std::string make_digest (ArrayData data);
95 
96 extern bool ids_equal (std::string a, std::string b);
97 extern std::string remove_urn_uuid (std::string raw);
98 
107 extern void init (boost::optional<boost::filesystem::path> resources_directory = boost::optional<boost::filesystem::path>());
108 
118 extern int base64_decode (std::string const & in, unsigned char* out, int out_length);
119 
120 extern boost::optional<boost::filesystem::path> relative_to_root (boost::filesystem::path root, boost::filesystem::path file);
121 
122 extern std::string file_to_string (boost::filesystem::path, uintmax_t max_length = 1048576);
123 extern void write_string_to_file(std::string const& string, boost::filesystem::path const& path);
124 
128 extern std::string private_key_fingerprint (std::string key);
129 extern std::string openjpeg_version();
130 extern std::string spaces (int n);
131 extern void indent (xmlpp::Element* element, int initial);
132 
136 extern bool day_less_than_or_equal (LocalTime a, LocalTime b);
137 
142 
146 extern std::string unique_string (std::vector<std::string> existing, std::string base);
147 
148 extern ASDCP::Dictionary const* asdcp_smpte_dict;
149 
150 extern boost::filesystem::path directory_containing_executable ();
151 extern boost::filesystem::path resources_directory ();
152 
153 
155 {
156 public:
159 
160 private:
161  Kumu::LogEntryList _log;
162  Kumu::ILogSink& _old;
163  Kumu::EntryListLogSink* _sink;
164 };
165 
166 
167 template <class From, class To>
168 void
169 add_to_container(To& container, From source)
170 {
171  std::copy(source.begin(), source.end(), std::back_inserter(container));
172 }
173 
174 
175 }
176 
177 
178 #endif
ArrayData class.
Class to hold an arbitrary block of data.
Definition: array_data.h:55
A representation of a local time (down to the second), including its offset from GMT (equivalent to x...
Definition: local_time.h:68
LocalTime class.
Namespace for everything in libdcp.
Definition: array_data.h:50
std::string unique_string(std::vector< std::string > existing, std::string base)
Definition: util.cc:387
void init(boost::optional< boost::filesystem::path > resources_directory=boost::optional< boost::filesystem::path >())
int base64_decode(std::string const &in, unsigned char *out, int out_length)
Definition: util.cc:195
std::string private_key_fingerprint(std::string key)
Definition: util.cc:288
bool day_less_than_or_equal(LocalTime a, LocalTime b)
Definition: util.cc:357
std::string make_digest(boost::filesystem::path filename, boost::function< void(int64_t, int64_t)>)
bool day_greater_than_or_equal(LocalTime a, LocalTime b)
Definition: util.cc:372