X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Futil.h;h=ccbe6083a057ba3c86dbe5ffb8bf859311128c5a;hb=refs%2Fheads%2Ftidy-eq-options;hp=992c5a61d8e38a92a43f0e63f0b2ca23f97f1bf4;hpb=29e2aa10c3985b8b86a389d1359c2cf149aff0ca;p=libdcp.git diff --git a/src/util.h b/src/util.h index 992c5a61..ccbe6083 100644 --- a/src/util.h +++ b/src/util.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of libdcp. @@ -31,51 +31,148 @@ files in the program, then also delete it here. */ -#ifndef LIBDCP_UTIL_H -#define LIBDCP_UTIL_H /** @file src/util.h - * @brief Utility methods. + * @brief Utility methods and classes */ -#include "types.h" -#include "data.h" -#include -#include + +#ifndef LIBDCP_UTIL_H +#define LIBDCP_UTIL_H + + +#include "array_data.h" +#include "local_time.h" +#include "warnings.h" +LIBDCP_DISABLE_WARNINGS +#include +LIBDCP_ENABLE_WARNINGS #include +#include #include +#include #include #include + +/* windows.h defines this but we want to use it */ +#undef ERROR + + +#define LIBDCP_UNUSED(x) (void)(x) + + +namespace ASDCP { + class Dictionary; +} + + namespace xmlpp { class Element; class Node; } + namespace dcp { + class CertificateChain; class GammaLUT; class OpenJPEGImage; + extern std::string make_uuid (); + +/** Create a digest for a file + * @param filename File name + * @param progress Optional progress reporting function. The function will be called + * with a progress value between 0 and 1 + * @return Digest + */ extern std::string make_digest (boost::filesystem::path filename, boost::function); -extern std::string make_digest (Data data); -extern bool empty_or_white_space (std::string s); + +extern std::string make_digest (ArrayData data); + extern bool ids_equal (std::string a, std::string b); extern std::string remove_urn_uuid (std::string raw); -extern void init (); +/** Set up various bits that the library needs. Should be called once + * by client applications. + * + * @param resources_directory Path to a directory containing the tags and xsd + * directories from the source code; if none is specified libdcp will look + * in the directory given by LIBDCP_RESOURCES or based on where the current + * executable is. + */ +extern void init (boost::optional resources_directory = boost::optional()); + +/** Decode a base64 string. The base64 decode routine in KM_util.cpp + * gives different values to both this and the command-line base64 + * for some inputs. Not sure why. + * + * @param in base64-encoded string + * @param out Output buffer + * @param out_length Length of output buffer + * @return Number of characters written to the output buffer + */ extern int base64_decode (std::string const & in, unsigned char* out, int out_length); + extern boost::optional relative_to_root (boost::filesystem::path root, boost::filesystem::path file); -extern FILE * fopen_boost (boost::filesystem::path, std::string); + extern std::string file_to_string (boost::filesystem::path, uintmax_t max_length = 1048576); + +/** @param key RSA private key in PEM format (optionally with -----BEGIN... / -----END...) + * @return SHA1 fingerprint of key + */ extern std::string private_key_fingerprint (std::string key); extern xmlpp::Node* find_child (xmlpp::Node const * node, std::string name); extern std::string openjpeg_version(); extern std::string spaces (int n); extern void indent (xmlpp::Element* element, int initial); +/** @return true if the day represented by \ref a is less than or + * equal to the one represented by \ref b, ignoring the time parts + */ +extern bool day_less_than_or_equal (LocalTime a, LocalTime b); + +/** @return true if the day represented by \ref a is greater than or + * equal to the one represented by \ref b, ignoring the time parts + */ +extern bool day_greater_than_or_equal (LocalTime a, LocalTime b); + +/** Try quite hard to find a string which starts with \ref base and is + * not in \ref existing + */ +extern std::string unique_string (std::vector existing, std::string base); + +extern ASDCP::Dictionary const* asdcp_smpte_dict; + +extern boost::filesystem::path directory_containing_executable (); +extern boost::filesystem::path resources_directory (); + + +class ASDCPErrorSuspender +{ +public: + ASDCPErrorSuspender(); + ~ASDCPErrorSuspender(); + +private: + Kumu::LogEntryList _log; + Kumu::ILogSink& _old; + Kumu::EntryListLogSink* _sink; +}; + + +template +void +add_to_container(To& container, From source) +{ + std::copy(source.begin(), source.end(), std::back_inserter(container)); } + +} + + #endif