HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_PathMap.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * COMMENTS:
7  */
8 
9 #ifndef PDG_PATH_MAP_H
10 #define PDG_PATH_MAP_H
11 
12 #include "PDG_API.h"
13 
14 #include <UT/UT_Array.h>
15 #include <UT/UT_Lock.h>
16 #include <UT/UT_StringHolder.h>
17 
18 class UT_WorkBuffer;
19 
20 /*
21  * Defines a list of mappings between path strings, which are grouped by a
22  * mapping "zone". Path maps are applied to file paths to handle cross platform
23  * path differences
24  */
26 {
27 public:
28  /// Enumeration of path map matching types
29  enum MatchType
30  {
31  /// The mapping can be matched anywhere in the input string. For
32  /// example, "/path/" is a valid match in "H:/path/", "/mnt/path/"
33  /// and "/path/subpath/".
35 
36  /// The mapping is only valid as a prefix of the input string. For
37  /// example, "/path/" is not a valid match for "H:/path/ nor
38  /// "/mnt/path/", but is a valid match for "/path/subpath/".
40 
41  /// The mapping is only valid as a suffix of the input string. For
42  /// example, "/path/" is a valid match for "H:/path/ or "/mnt/path/",
43  /// but is not a valid match for "/path/subpath/".
45  };
46 
47  /// Path mapping entry contain the from path string, to path string, and
48  /// a boolean that indicates if `from` is a string of `to`.
49  struct Entry
50  {
52 
56 
58 
60  };
61 
62  /// Array of path mapping entries
64 
65  /// Default zone for Windows systems -- WIN
67 
68  /// Default zone for Mac systems -- MAC
70 
71  /// Default zone for Linux systems -- LINUX
73 
74  /// Special zone that matches with all platforms -- *
76 
77  /// Current PDG Path Map data version
78  static const int theVersion;
79 
80  /// Sepecial scheduler name that matches all schedulers
82 
83 public:
84  PDG_PathMap(int version);
85 
86  /// Reloads the path map instance from the environment
87  bool reload(bool merge, UT_WorkBuffer& errors);
88 
89  /// Returns a string representation of this path map
90  const UT_StringHolder& toString() const;
91 
92  /// Saves the path map to the specified work buffer, in JSON format
93  bool save(UT_WorkBuffer& buffer) const;
94 
95  /// Loads a path map from the input JSON string
96  bool load(const UT_StringHolder& path_map,
97  bool update_vars,
98  bool merge,
99  UT_WorkBuffer& errors);
100 
101  /// Applies the path mapping to the input path, using the desired mapping
102  /// zone.
103  UT_StringHolder mapPath(const UT_StringHolder& path,
104  const UT_StringHolder& zone) const;
105 
106  /// Applies the path mapping using the mapping zone from the current
107  /// platform.
109  { return mapPath(path, myZone); }
110 
111 
112  /// Returns the current zone for this path mapping instance
113  const UT_StringHolder& zone() const
114  { return myZone; }
115 
116  /// Sets the zone for this path mapping instance
117  void setZone(const UT_StringHolder& zone)
118  {
119  UT_Lock::Scope lock(myMapLock);
120  myZone = zone;
121  }
122 
123  /// Returns the array of path mapping entries currently stored in
124  /// this path map.
125  const EntryArray& mappings() const
126  { return myMapEntries; }
127 
128  /// Returns the mapping entries for a specific zone and/or scheduler
129  void filteredMappings(
130  EntryArray& entries,
131  const UT_StringHolder& zone,
132  const UT_StringHolder& scheduler) const;
133 
134  /// Adds an entry to the path map
135  void addPathMapping(
136  const UT_StringHolder& zone,
137  const UT_StringHolder& map_from,
138  const UT_StringHolder& map_to,
139  const UT_StringHolder& scheduler,
140  MatchType match_type);
141 
142  /// Clears path mapping entries for the specified scheduler path
143  void clearSchedulerMappings(
144  const UT_StringHolder& scheduler);
145 
146  /// Clears all path mapping entries
147  void clearAllMappings();
148 
149  /// Updates the internal string representation and env var for the path
150  /// mapping.
151  void commitPathMapping();
152 
153 
154  /// Returns the shared global path mapping instance
155  static PDG_PathMap& globalMap();
156 
157 private:
158  /// Top level key for path map array
159  static const UT_StringHolder thePathMapArrayKey;
160 
161  /// Map key for a destination path
162  static const UT_StringHolder thePathMapDestKey;
163 
164  /// Map key for a destination zone
165  static const UT_StringHolder thePathMapZoneKey;
166 
167  /// Map key for a destination scheduler, e.g. the scheduler that
168  /// supplied the entry
169  static const UT_StringHolder thePathMapSchedulerKey;
170 
171  /// Map key for the match type
172  static const UT_StringHolder thePathMapMatchTypeKey;
173 
174  /// Version number key
175  static const UT_StringHolder theVersionKey;
176 
177 private:
178  EntryArray myMapEntries;
179  mutable UT_StringHolder myString;
180  UT_StringHolder myZone;
181  UT_Lock myMapLock;
182  int myVersion;
183 };
184 
185 #endif
static const UT_StringHolder theAllZone
Special zone that matches with all platforms – *.
Definition: PDG_PathMap.h:75
PXL_API void reload()
Reload the configuration.
UT_StringHolder myScheduler
Definition: PDG_PathMap.h:55
static const UT_StringHolder theAllSchedulerName
Sepecial scheduler name that matches all schedulers.
Definition: PDG_PathMap.h:81
#define PDG_API
Definition: PDG_API.h:23
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
const EntryArray & mappings() const
Definition: PDG_PathMap.h:125
static const UT_StringHolder theLinuxZone
Default zone for Linux systems – LINUX.
Definition: PDG_PathMap.h:72
MatchType
Enumeration of path map matching types.
Definition: PDG_PathMap.h:29
UT_StringHolder myTo
Definition: PDG_PathMap.h:54
UT_StringHolder myFrom
Definition: PDG_PathMap.h:53
static const int theVersion
Current PDG Path Map data version.
Definition: PDG_PathMap.h:78
Definition: core.h:760
Definition: PDG_PathMap.h:49
UT_StringHolder myZone
Definition: PDG_PathMap.h:51
MatchType myMatchType
Definition: PDG_PathMap.h:57
void setZone(const UT_StringHolder &zone)
Sets the zone for this path mapping instance.
Definition: PDG_PathMap.h:117
const UT_StringHolder & zone() const
Returns the current zone for this path mapping instance.
Definition: PDG_PathMap.h:113
GT_API const UT_StringHolder version
static const UT_StringHolder theMacZone
Default zone for Mac systems – MAC.
Definition: PDG_PathMap.h:69
UT_StringHolder mapPath(const UT_StringHolder &path) const
Definition: PDG_PathMap.h:108
bool myIsSubpath
Definition: PDG_PathMap.h:59
static const UT_StringHolder theWinZone
Default zone for Windows systems – WIN.
Definition: PDG_PathMap.h:66