/src/core/PathUtils.h

http://github.com/imageworks/OpenColorIO · C Header · 95 lines · 41 code · 13 blank · 41 comment · 2 complexity · 0e5c9289270590282dbeb830961f1110 MD5 · raw file

  1. /*
  2. Copyright (c) 2003-2010 Sony Pictures Imageworks Inc., et al.
  3. All Rights Reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. * Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. * Neither the name of Sony Pictures Imageworks nor the names of its
  13. contributors may be used to endorse or promote products derived from
  14. this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef INCLUDED_OCIO_PATHUTILS_H
  28. #define INCLUDED_OCIO_PATHUTILS_H
  29. #include <OpenColorIO/OpenColorIO.h>
  30. #include <map>
  31. OCIO_NAMESPACE_ENTER
  32. {
  33. namespace pystring
  34. {
  35. namespace os
  36. {
  37. namespace path
  38. {
  39. // This is not currently included in pystring, but we need it
  40. // So let's define it locally for now
  41. std::string abspath(const std::string & path);
  42. }
  43. }
  44. }
  45. // The EnvMap is ordered by the length of the keys (long -> short). This
  46. // is so that recursive string expansion will deal with similar prefixed
  47. // keys as expected.
  48. // ie. '$TEST_$TESTING_$TE' will expand in this order '2 1 3'
  49. template <class T>
  50. struct EnvMapKey : std::binary_function <T, T, bool>
  51. {
  52. bool
  53. operator() (const T &x, const T &y) const
  54. {
  55. // If the lengths are unequal, sort by length
  56. if(x.length() != y.length())
  57. {
  58. return (x.length() > y.length());
  59. }
  60. // Otherwise, use the standard string sort comparison
  61. else
  62. {
  63. return (x<y);
  64. }
  65. }
  66. };
  67. typedef std::map< std::string, std::string, EnvMapKey< std::string > > EnvMap;
  68. // Get map of current env key = value, or update the existing entries
  69. void LoadEnvironment(EnvMap & map, bool update = false);
  70. // Expand a string with $VAR, ${VAR} or %VAR% with the keys passed
  71. // in the EnvMap.
  72. std::string EnvExpand(const std::string & str, const EnvMap & map);
  73. // Check if a file exists
  74. bool FileExists(const std::string & filename);
  75. // Get a fast hash for a file, without reading all the contents.
  76. // Currently, this checks the mtime and the inode number.
  77. std::string GetFastFileHash(const std::string & filename);
  78. void ClearPathCaches();
  79. }
  80. OCIO_NAMESPACE_EXIT
  81. #endif