File: cache.hh

package info (click to toggle)
performous 1.1%2Bgit20181118-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 11,712 kB
  • sloc: cpp: 30,008; ansic: 2,751; sh: 801; xml: 464; python: 374; makefile: 22
file content (25 lines) | stat: -rw-r--r-- 958 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#pragma once

#include "configuration.hh"
#include "fs.hh"
#include <boost/filesystem.hpp>
#include <cstring>
#include <stdexcept>

namespace cache {

	/** Builds the full path and file name for the SVG cache resource **/
	fs::path constructSVGCacheFileName(fs::path const& svgfilename, double factor);

	/** Load an SVG from the cache, if loading fails invalid_cache_error is thrown **/
	template <typename T> bool loadSVG(T& target, fs::path const& source_filename, double factor) {
		fs::path const cache_filename = cache::constructSVGCacheFileName(source_filename, factor);
		// Verify that a cached file exists and that it is more recent than the original SVG
		if (!fs::is_regular_file(cache_filename)) return false;
		if (fs::last_write_time(source_filename) > fs::last_write_time(cache_filename)) return false;
		// Try to load the cached file		
		try { loadPNG(target, cache_filename.string()); } catch( ... ) { return false; }
		return true;
	}
}