MaterialX 1.39.1
Loading...
Searching...
No Matches
Util.h
Go to the documentation of this file.
1//
2// Copyright Contributors to the MaterialX Project
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#ifndef MATERIALX_UTIL
7#define MATERIALX_UTIL
8
11
13
14MATERIALX_NAMESPACE_BEGIN
15
16extern MX_CORE_API const string EMPTY_STRING;
17
19MX_CORE_API string getVersionString();
20
23MX_CORE_API std::tuple<int, int, int> getVersionIntegers();
24
26MX_CORE_API string createValidName(string name, char replaceChar = '_');
27
29MX_CORE_API bool isValidName(const string& name);
30
32MX_CORE_API string incrementName(const string& name);
33
36MX_CORE_API StringVec splitString(const string& str, const string& sep);
37
40MX_CORE_API string joinStrings(const StringVec& strVec, const string& sep);
41
43MX_CORE_API string replaceSubstrings(string str, const StringMap& stringMap);
44
46MX_CORE_API string stringToLower(string str);
47
49MX_CORE_API bool stringStartsWith(const string& str, const string& prefix);
50
52MX_CORE_API bool stringEndsWith(const string& str, const string& suffix);
53
55MX_CORE_API string trimSpaces(const string& str);
56
58template <typename T> void hashCombine(size_t& seed, const T& value)
59{
60 seed ^= std::hash<T>()(value) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
61}
62
64MX_CORE_API StringVec splitNamePath(const string& namePath);
65
67MX_CORE_API string createNamePath(const StringVec& nameVec);
68
70MX_CORE_API string parentNamePath(const string& namePath);
71
72MATERIALX_NAMESPACE_END
73
74#endif
Import and export declarations for the Core library.
vector< string > StringVec
A vector of strings.
Definition: Library.h:55
std::unordered_map< string, string > StringMap
An unordered map with strings as both keys and values.
Definition: Library.h:57
MX_CORE_API string incrementName(const string &name)
Increment the numeric suffix of a name.
MX_CORE_API bool stringEndsWith(const string &str, const string &suffix)
Return true if the given string ends with the given suffix.
MX_CORE_API string createNamePath(const StringVec &nameVec)
Create a name path from a string vector.
MX_CORE_API bool stringStartsWith(const string &str, const string &prefix)
Return true if the given string starts with the given prefix.
MX_CORE_API string stringToLower(string str)
Return a copy of the given string with letters converted to lower case.
MX_CORE_API string joinStrings(const StringVec &strVec, const string &sep)
Join a vector of substrings into a single string, placing the given separator between each substring.
MX_CORE_API string trimSpaces(const string &str)
Trim leading and trailing spaces from a string.
MX_CORE_API string parentNamePath(const string &namePath)
Given a name path, return the parent name path.
MX_CORE_API string createValidName(string name, char replaceChar='_')
Create a valid MaterialX name from the given string.
MX_CORE_API StringVec splitNamePath(const string &namePath)
Split a name path into string vector.
MX_CORE_API bool isValidName(const string &name)
Return true if the given string is a valid MaterialX name.
void hashCombine(size_t &seed, const T &value)
Combine the hash of a value with an existing seed.
Definition: Util.h:58
MX_CORE_API string replaceSubstrings(string str, const StringMap &stringMap)
Apply the given substring substitutions to the input string.
MX_CORE_API string getVersionString()
Return the version of the MaterialX library as a string.
MX_CORE_API std::tuple< int, int, int > getVersionIntegers()
Return the major, minor, and build versions of the MaterialX library as an integer tuple.
MX_CORE_API StringVec splitString(const string &str, const string &sep)
Split a string into a vector of substrings using the given set of separator characters.