Blender V5.0
path.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7/* Utility functions to get paths to files distributed with the program. For
8 * the standalone apps, paths are relative to the executable, for dynamically
9 * linked libraries, the path to the library may be set with path_init, which
10 * then makes all paths relative to that. */
11
12#include <cstdio>
13
14#include "util/string.h"
15#include "util/vector.h"
16
18
19/* program paths */
20void path_init(const string &path = "", const string &user_path = "");
21string path_get(const string &sub = "");
22string path_user_get(const string &sub = "");
23string path_cache_get(const string &sub = "");
24
25/* path string manipulation */
26string path_filename(const string &path);
27string path_dirname(const string &path);
28string path_join(const string &dir, const string &file);
29string path_escape(const string &path);
30bool path_is_relative(const string &path);
31
32/* file info */
33size_t path_file_size(const string &path);
34bool path_exists(const string &path);
35bool path_is_directory(const string &path);
36string path_files_md5_hash(const string &dir);
37uint64_t path_modified_time(const string &path);
38
39/* directory utility */
40void path_create_directories(const string &path);
41
42/* file read/write utilities */
43FILE *path_fopen(const string &path, const string &mode);
44
45bool path_write_binary(const string &path, const vector<uint8_t> &binary);
46bool path_write_text(const string &path, string &text);
47bool path_read_binary(const string &path, vector<uint8_t> &binary);
48bool path_read_text(const string &path, string &text);
49
50bool path_read_compressed_binary(const string &path, vector<uint8_t> &binary);
51bool path_read_compressed_text(const string &path, string &text);
52
53/* File manipulation. */
54bool path_remove(const string &path);
55
56/* source code utility */
57string path_source_replace_includes(const string &source, const string &path);
58
59/* Simple least-recently-used cache for kernels.
60 *
61 * Kernels of same type are cached in the same directory.
62 * Whenever a kernel is used, its last modified time is updated.
63 * When a new kernel is added to the cache, clear old entries of the same type (i.e. in the same
64 * directory). */
65bool path_cache_kernel_exists_and_mark_used(const string &path);
66void path_cache_kernel_mark_added_and_clear_old(const string &path,
67 const size_t max_old_kernel_of_same_type = 5);
68
unsigned long long int uint64_t
#define CCL_NAMESPACE_END
size_t path_file_size(const string &path)
Definition path.cpp:554
bool path_read_compressed_binary(const string &path, vector< uint8_t > &binary)
Definition path.cpp:708
bool path_is_directory(const string &path)
Definition path.cpp:582
FILE * path_fopen(const string &path, const string &mode)
Definition path.cpp:975
string path_dirname(const string &path)
Definition path.cpp:401
string path_get(const string &sub="")
Definition path.cpp:337
string path_source_replace_includes(const string &source, const string &path)
Definition path.cpp:968
string path_files_md5_hash(const string &dir)
Definition path.cpp:611
bool path_is_relative(const string &path)
Definition path.cpp:444
uint64_t path_modified_time(const string &path)
Definition path.cpp:769
string path_join(const string &dir, const string &file)
Definition path.cpp:415
void path_cache_kernel_mark_added_and_clear_old(const string &path, const size_t max_old_kernel_of_same_type=5)
Definition path.cpp:1003
bool path_exists(const string &path)
Definition path.cpp:563
bool path_cache_kernel_exists_and_mark_used(const string &path)
Definition path.cpp:994
string path_user_get(const string &sub="")
Definition path.cpp:351
string path_escape(const string &path)
Definition path.cpp:437
bool path_write_binary(const string &path, const vector< uint8_t > &binary)
Definition path.cpp:653
bool path_write_text(const string &path, string &text)
Definition path.cpp:673
bool path_read_text(const string &path, string &text)
Definition path.cpp:739
bool path_read_compressed_text(const string &path, string &text)
Definition path.cpp:754
void path_create_directories(const string &path)
Definition path.cpp:647
string path_filename(const string &path)
Definition path.cpp:378
CCL_NAMESPACE_BEGIN void path_init(const string &path="", const string &user_path="")
Definition path.cpp:324
string path_cache_get(const string &sub="")
Definition path.cpp:360
bool path_remove(const string &path)
Definition path.cpp:778
bool path_read_binary(const string &path, vector< uint8_t > &binary)
Definition path.cpp:681