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