Blender V5.3
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);
30string path_normalize(const string &path);
31bool path_is_relative(const string &path);
32string path_make_relative(const string &path, const string &base);
33
34/* file info */
35size_t path_file_size(const string &path);
36bool path_exists(const string &path);
37bool path_is_directory(const string &path);
38bool path_is_file(const string &path);
39string path_files_md5_hash(const string &dir);
40uint64_t path_modified_time(const string &path);
41
42/* directory utility */
43bool path_create_directories(const string &path);
44
45/* file read/write utilities */
46FILE *path_fopen(const string &path, const string &mode);
47
48bool path_write_binary(const string &path, const vector<uint8_t> &binary);
49bool path_write_text(const string &path, const string &text);
50bool path_read_binary(const string &path, vector<uint8_t> &binary);
51bool path_read_text(const string &path, string &text);
52
53bool path_read_compressed_binary(const string &path, vector<uint8_t> &binary);
54bool path_read_compressed_text(const string &path, string &text);
55
56/* File manipulation. */
57bool path_remove(const string &path);
58
59/* source code utility */
60string path_source_replace_includes(const string &source, const string &path);
61
62/* Simple least-recently-used cache for kernels.
63 *
64 * Kernels of same type are cached in the same directory.
65 * Whenever a kernel is used, its last modified time is updated.
66 * When a new kernel is added to the cache, clear old entries of the same type (i.e. in the same
67 * directory). */
68bool path_cache_kernel_exists_and_mark_used(const string &path);
69void path_cache_kernel_mark_added_and_clear_old(const string &path,
70 const size_t max_old_kernel_of_same_type = 5);
71
unsigned long long int uint64_t
#define CCL_NAMESPACE_END
size_t path_file_size(const string &path)
Definition path.cpp:594
bool path_read_compressed_binary(const string &path, vector< uint8_t > &binary)
Definition path.cpp:757
string path_user_get(const string &sub)
Definition path.cpp:378
string path_cache_get(const string &sub)
Definition path.cpp:383
string path_make_relative(const string &path_, const string &base_)
Definition path.cpp:480
bool path_is_directory(const string &path)
Definition path.cpp:622
FILE * path_fopen(const string &path, const string &mode)
Definition path.cpp:1024
string path_dirname(const string &path)
Definition path.cpp:422
string path_source_replace_includes(const string &source, const string &path)
Definition path.cpp:1017
bool path_create_directories(const string &filepath)
Definition path.cpp:696
string path_get(const string &sub)
Definition path.cpp:368
string path_files_md5_hash(const string &dir)
Definition path.cpp:660
bool path_is_relative(const string &path)
Definition path.cpp:475
uint64_t path_modified_time(const string &path)
Definition path.cpp:818
string path_join(const string &dir, const string &file)
Definition path.cpp:436
bool path_exists(const string &path)
Definition path.cpp:603
bool path_write_text(const string &path, const string &text)
Definition path.cpp:722
bool path_cache_kernel_exists_and_mark_used(const string &path)
Definition path.cpp:1043
string path_escape(const string &path)
Definition path.cpp:458
string path_normalize(const string &path)
Definition path.cpp:465
void path_cache_kernel_mark_added_and_clear_old(const string &new_path, const size_t max_old_kernel_of_same_type)
Definition path.cpp:1052
bool path_write_binary(const string &path, const vector< uint8_t > &binary)
Definition path.cpp:702
bool path_read_text(const string &path, string &text)
Definition path.cpp:788
bool path_read_compressed_text(const string &path, string &text)
Definition path.cpp:803
bool path_is_file(const string &path)
Definition path.cpp:631
string path_filename(const string &path)
Definition path.cpp:399
bool path_remove(const string &path)
Definition path.cpp:827
void path_init(const string &path, const string &user_path)
Definition path.cpp:355
bool path_read_binary(const string &path, vector< uint8_t > &binary)
Definition path.cpp:730