HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Util.h
Go to the documentation of this file.
1 //
2 // TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
3 // All rights reserved. See LICENSE.txt for license.
4 //
5 
6 #ifndef MATERIALX_UTIL
7 #define MATERIALX_UTIL
8 
9 /// @file
10 /// Utility methods
11 
12 #include <MaterialXCore/Export.h>
13 
15 
16 extern MX_CORE_API const string EMPTY_STRING;
17 
18 /// Return the version of the MaterialX library as a string.
20 
21 /// Return the major, minor, and build versions of the MaterialX library
22 /// as an integer tuple.
23 MX_CORE_API std::tuple<int, int, int> getVersionIntegers();
24 
25 /// Create a valid MaterialX name from the given string.
26 MX_CORE_API string createValidName(string name, char replaceChar = '_');
27 
28 /// Return true if the given string is a valid MaterialX name.
29 MX_CORE_API bool isValidName(const string& name);
30 
31 /// Increment the numeric suffix of a name
32 MX_CORE_API string incrementName(const string& name);
33 
34 /// Split a string into a vector of substrings using the given set of
35 /// separator characters.
36 MX_CORE_API StringVec splitString(const string& str, const string& sep);
37 
38 /// Apply the given substring substitutions to the input string.
39 MX_CORE_API string replaceSubstrings(string str, const StringMap& stringMap);
40 
41 /// Return a copy of the given string with letters converted to lower case.
42 MX_CORE_API string stringToLower(string str);
43 
44 /// Return true if the given string ends with the given suffix.
45 MX_CORE_API bool stringEndsWith(const string& str, const string& suffix);
46 
47 /// Trim leading and trailing spaces from a string.
48 MX_CORE_API string trimSpaces(const string& str);
49 
50 /// Combine the hash of a value with an existing seed.
51 template <typename T> void hashCombine(size_t& seed, const T& value)
52 {
53  seed ^= std::hash<T>()(value) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
54 }
55 
56 /// Split a name path into string vector
57 MX_CORE_API StringVec splitNamePath(const string& namePath);
58 
59 /// Create a name path from a string vector
60 MX_CORE_API string createNamePath(const StringVec& nameVec);
61 
62 /// Given a name path, return the parent name path
63 MX_CORE_API string parentNamePath(const string& namePath);
64 
66 
67 #endif
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:23
vector< string > StringVec
A vector of strings.
Definition: Library.h:57
MX_CORE_API string getVersionString()
Return the version of the MaterialX library as a string.
MATERIALX_NAMESPACE_BEGIN MX_CORE_API const string EMPTY_STRING
MX_CORE_API std::tuple< int, int, int > getVersionIntegers()
GLuint const GLchar * name
Definition: glcorearb.h:786
#define MX_CORE_API
Definition: Export.h:18
MX_CORE_API string stringToLower(string str)
Return a copy of the given string with letters converted to lower case.
MX_CORE_API string incrementName(const string &name)
Increment the numeric suffix of a name.
MX_CORE_API StringVec splitNamePath(const string &namePath)
Split a name path into string vector.
MX_CORE_API string replaceSubstrings(string str, const StringMap &stringMap)
Apply the given substring substitutions to the input string.
void hashCombine(size_t &seed, const T &value)
Combine the hash of a value with an existing seed.
Definition: Util.h:51
MX_CORE_API string createNamePath(const StringVec &nameVec)
Create a name path from a string vector.
MX_CORE_API bool isValidName(const string &name)
Return true if the given string is a valid MaterialX name.
MX_CORE_API string createValidName(string name, char replaceChar= '_')
Create a valid MaterialX name from the given string.
std::unordered_map< string, string > StringMap
An unordered map with strings as both keys and values.
Definition: Library.h:59
MX_CORE_API string trimSpaces(const string &str)
Trim leading and trailing spaces from a string.
Definition: core.h:1131
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:24
MX_CORE_API string parentNamePath(const string &namePath)
Given a name path, return the parent name path.
MX_CORE_API StringVec splitString(const string &str, const string &sep)
MX_CORE_API bool stringEndsWith(const string &str, const string &suffix)
Return true if the given string ends with the given suffix.