Blender V4.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#ifndef __UTIL_PATH_H__
6#define __UTIL_PATH_H__
7
8/* Utility functions to get paths to files distributed with the program. For
9 * the standalone apps, paths are relative to the executable, for dynamically
10 * linked libraries, the path to the library may be set with path_init, which
11 * then makes all paths relative to that. */
12
13#include <stdio.h>
14
15#include "util/set.h"
16#include "util/string.h"
17#include "util/types.h"
18#include "util/vector.h"
19
21
22/* program paths */
23void path_init(const string &path = "", const string &user_path = "");
24string path_get(const string &sub = "");
25string path_user_get(const string &sub = "");
26string path_cache_get(const string &sub = "");
27
28/* path string manipulation */
29string path_filename(const string &path);
30string path_dirname(const string &path);
31string path_join(const string &dir, const string &file);
32string path_escape(const string &path);
33bool path_is_relative(const string &path);
34
35/* file info */
36size_t path_file_size(const string &path);
37bool path_exists(const string &path);
38bool path_is_directory(const string &path);
39string path_files_md5_hash(const string &dir);
40uint64_t path_modified_time(const string &path);
41
42/* directory utility */
43void 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, 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
73
74#endif
#define CCL_NAMESPACE_END
size_t path_file_size(const string &path)
Definition path.cpp:556
bool path_read_compressed_binary(const string &path, vector< uint8_t > &binary)
Definition path.cpp:709
bool path_is_directory(const string &path)
Definition path.cpp:584
FILE * path_fopen(const string &path, const string &mode)
Definition path.cpp:973
string path_dirname(const string &path)
Definition path.cpp:403
string path_get(const string &sub="")
Definition path.cpp:339
string path_source_replace_includes(const string &source, const string &path)
Definition path.cpp:966
string path_files_md5_hash(const string &dir)
Definition path.cpp:612
bool path_is_relative(const string &path)
Definition path.cpp:446
uint64_t path_modified_time(const string &path)
Definition path.cpp:769
string path_join(const string &dir, const string &file)
Definition path.cpp:417
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:565
bool path_cache_kernel_exists_and_mark_used(const string &path)
Definition path.cpp:992
string path_user_get(const string &sub="")
Definition path.cpp:353
string path_escape(const string &path)
Definition path.cpp:439
bool path_write_binary(const string &path, const vector< uint8_t > &binary)
Definition path.cpp:654
bool path_write_text(const string &path, string &text)
Definition path.cpp:674
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:648
string path_filename(const string &path)
Definition path.cpp:380
CCL_NAMESPACE_BEGIN void path_init(const string &path="", const string &user_path="")
Definition path.cpp:326
string path_cache_get(const string &sub="")
Definition path.cpp:362
bool path_remove(const string &path)
Definition path.cpp:778
bool path_read_binary(const string &path, vector< uint8_t > &binary)
Definition path.cpp:682
unsigned __int64 uint64_t
Definition stdint.h:90