cpplocate  1.0.0.a8d87a94e3ab
C++ Locator Library
cpplocate.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 
5 #include <string>
6 
7 #include <cpplocate/cpplocate_api.h>
8 
9 
10 namespace cpplocate
11 {
12 
13 
14 class ModuleInfo;
15 
16 
17 /**
18 * @brief
19 * Get path to the current executable
20 *
21 * @return
22 * Path to executable (including filename)
23 *
24 * @remarks
25 * The path is returned in native format, e.g., backslashes on Windows.
26 *
27 * It is assumed the executable path is static throughout the process.
28 */
29 CPPLOCATE_API const std::string & getExecutablePath();
30 
31 /**
32 * @brief
33 * Get path to the current application bundle
34 *
35 * @return
36 * Path to bundle (including filename)
37 *
38 * @remarks
39 * The path is returned in unified format (forward slashes).
40 * If the current executable is part of a macOS application bundle,
41 * this function returns the part to the bundle. Otherwise, an
42 * empty string is returned.
43 *
44 * It is assumed the bundle path is static throughout the process.
45 */
46 CPPLOCATE_API const std::string & getBundlePath();
47 
48 /**
49 * @brief
50 * Get path to the current module
51 *
52 * @return
53 * Path to module (directory in which the executable is located)
54 *
55 * @remarks
56 * The path is returned in unified format (forward slashes).
57 *
58 * It is assumed the executable name is static throughout the process.
59 */
60 CPPLOCATE_API const std::string & getModulePath();
61 
62 /**
63 * @brief
64 * Get path to dynamic library
65 *
66 * @param[in] symbol
67 * A symbol from the library, e.g., a function or variable pointer
68 *
69 * @return
70 * Path to library (including filename)
71 *
72 * @remarks
73 * The path is returned in unified format (forward slashes).
74 * If symbol is nullptr, an empty string is returned.
75 */
76 CPPLOCATE_API std::string getLibraryPath(void * symbol);
77 
78 /**
79 * @brief
80 * Locate path to a file or directory
81 *
82 * @param[in] relPath
83 * Relative path to a file or directory (e.g., 'data/logo.png')
84 * @param[in] systemDir
85 * Subdirectory for system installs (e.g., 'share/myappname')
86 * @param[in] symbol
87 * A symbol from the library, e.g., a function or variable pointer
88 *
89 * @return
90 * Path to file or directory
91 *
92 * @remarks
93 * This function tries to locate the named file or directory based
94 * on the location of the current executable or library. If the
95 * file or directory could be found, the base path from which the
96 * relative path can be resolved is returned. Otherwise, an empty
97 * string is returned.
98 *
99 * The path is returned in unified format (forward slashes).
100 */
101 CPPLOCATE_API std::string locatePath(const std::string & relPath, const std::string & systemDir = "", void * symbol = nullptr);
102 
103 /**
104 * @brief
105 * Tries to locate a module
106 *
107 * @param[in] name
108 * Module name (e.g., "mymodule")
109 *
110 * @return
111 * Module information, empty on error
112 *
113 * @remarks
114 * It is assumed the 'CPPLOCATE_PATH' environment variable
115 * is static throughout the process.
116 *
117 * This functions looks for the filename "<name>.modinfo".
118 * It searches the following locations:
119 * 1. The current module path
120 * 2. All pathes contained in the enironment variable CPPLOCATE_PATH
121 * 2.a <path>/<name>.modinfo
122 * 2.b <path>/<name>/<name>.modinfo
123 * 3. Standard locations:
124 * 3.a C:\Program Files<name><name>.modinfo
125 * 3.b /usr/share/<name>/<name>.modinfo
126 * 3.c /usr/local/share/<name>/<name>.modinfo
127 */
128 CPPLOCATE_API ModuleInfo findModule(const std::string & name);
129 
130 
131 } // namespace cpplocate
CPPLOCATE_API std::string getLibraryPath(void *symbol)
Get path to dynamic library.
Description of a module, containing key/value pairs.
Definition: ModuleInfo.h:20
CPPLOCATE_API const std::string & getModulePath()
Get path to the current module.
CPPLOCATE_API const std::string & getExecutablePath()
Get path to the current executable.
CPPLOCATE_API std::string locatePath(const std::string &relPath, const std::string &systemDir="", void *symbol=nullptr)
Locate path to a file or directory.
CPPLOCATE_API const std::string & getBundlePath()
Get path to the current application bundle.
Definition: cpplocate.h:10
CPPLOCATE_API ModuleInfo findModule(const std::string &name)
Tries to locate a module.