HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDG_File.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_FILE_H
10 #define PDG_FILE_H
11 
12 #include "PDG_API.h"
13 
14 #include <UT/UT_Array.h>
15 #include <UT/UT_ArraySet.h>
16 #include <UT/UT_StringHolder.h>
17 #include <UT/UT_ValArray.h>
18 
19 #include <SYS/SYS_Hash.h>
20 
21 class UT_JSONValue;
22 class UT_JSONWriter;
23 class UT_OptionsHolder;
24 
25 class PDG_Scheduler;
26 class PDG_WorkItem;
27 
29 {
30 public:
31  /// Array of files
33 
34  /// Set of files, which uses the default clear struct defined at the
35  /// bottom of this file
37 
38  /// The file hash/modtime type
39  using Hash = int64;
41 
42  /// Enumeration of file types, used to maintain whether the file is an
43  /// expected output, a generated output, or a file reported at cook time.
44  enum FileType
45  {
50  };
51 
52  /// Default/invalid hash value
53  static constexpr Hash theInvalidHash = 0;
54 
55  /// JSON Serialization keys
57  static const UT_StringHolder theTagKey;
60  static const UT_StringHolder theOwnKey;
62 
63  /// Global empty file and empty file list statics
64  static const PDG_File theEmptyFile;
65  static const Array theEmptyFileArray;
66 
67 public:
68 
69  PDG_File();
71  bool own);
73  const UT_StringHolder& tag,
74  Hash hash,
75  bool own);
77  const UT_StringHolder& tag,
78  Hash hash,
79  FileType type,
80  bool own);
81 
82  int64 getMemoryUsage(bool inclusive) const;
83  /// Updates and return the local_path
84  UT_StringHolder localizePath(
85  const PDG_Scheduler* scheduler) const;
86 
87  bool isExpected() const {
88  return (myType == eFileExpected); }
89  bool isGenerated() const {
90  return (myType == eFileGenerated); }
91 
92  /// Return the local path. Note that this will not do the old __PDG_DIR__
93  /// localization automatically, call `localizePath` first.
94  const UT_StringHolder& local_data() const;
95  void setLocalData(const UT_StringHolder& local_data);
96  const UT_StringHolder& data() const { return myData; }
97  void setData(const UT_StringHolder& data);
98 
99  const UT_StringHolder& tag() const { return myTag; }
100  void setTag(const UT_StringHolder& tag);
101 
102  Hash hash() const { return myHash; }
103  void setHash(Hash hash);
104 
105  PDG_File::FileType type() const { return myType; }
106  void setType(FileType type);
107 
108  exint size() const { return mySize; }
109  void setSize(exint size);
110 
111  bool own() const { return myOwn; }
112  void setOwn(bool own);
113 
114  void updateStat(
115  const PDG_WorkItem* work_item,
116  bool force);
117  void clearStat();
118 
119  bool operator==(const PDG_File& other) const;
120  bool operator!=(const PDG_File& other) const;
121  bool operator<(const PDG_File& other) const;
122  bool operator<=(const PDG_File& other) const;
123  bool operator>(const PDG_File& other) const;
124  bool operator>=(const PDG_File& other) const;
125 
126  void save(UT_JSONWriter& writer) const;
127  void save(UT_OptionsHolder& dict) const;
128 
129  bool load(const UT_JSONValue& value,
130  bool strict=true);
131  bool load(
132  const UT_OptionsHolder& dict,
133  bool strict=true);
134 
135  /// Saves a file array to json
136  static void save(const Array& array, UT_JSONWriter& writer);
137 
138  /// Saves a file array to UT_Options
139  static void save(
140  const Array& array,
141  const UT_StringHolder& key,
142  UT_OptionsHolder& dict);
143 
144  /// Loads a fle array from json
145  static bool load(Array& array,
146  const UT_JSONValue& value,
147  bool strict=true);
148 
149  /// Loads a file array from a dict
150  static bool load(
151  Array& array,
152  const UT_StringHolder& key,
153  const UT_OptionsHolder& options,
154  bool strict=true);
155 
156 private:
157  mutable UT_StringHolder myLocalData;
158  UT_StringHolder myData;
159  UT_StringHolder myTag;
160  Hash myHash;
161  exint mySize;
162  FileType myType;
163  bool myOwn;
164 };
165 
167 {
168  SYS_HashType hash = hash_value(file.data());
169  SYShashCombine(hash, hash_value(file.tag()));
170  //The hash and ownership flag shouldn't be considered
171  //when comparing work items
172  SYShashCombine(hash, file.type());
173  return hash;
174 }
175 
176 namespace UT
177 {
178  template <typename T>
179  struct DefaultClearer;
180 
181  template <>
183  {
184  static void clear(PDG_File& file)
185  { file = PDG_File::theEmptyFile; }
186  static bool isClear(const PDG_File& file)
187  { return (file == PDG_File::theEmptyFile); }
188  static void clearConstruct(PDG_File *p)
189  { new ((void *)p) PDG_File(); }
190  static const bool clearNeedsDestruction = false;
191  };
192 }
193 
194 #endif
static const UT_StringHolder theHashKey
Definition: PDG_File.h:58
static const Array theEmptyFileArray
Definition: PDG_File.h:65
Definition: ImfArray.h:45
STATIC_INLINE size_t Hash(const char *s, size_t len)
Definition: farmhash.h:2038
static const PDG_File theEmptyFile
Global empty file and empty file list statics.
Definition: PDG_File.h:64
#define PDG_API
Definition: PDG_API.h:23
static void clearConstruct(PDG_File *p)
Definition: PDG_File.h:188
int64 exint
Definition: SYS_Types.h:125
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
static const UT_StringHolder theTypeKey
Definition: PDG_File.h:61
static void clear(PDG_File &file)
Definition: PDG_File.h:184
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
static const UT_StringHolder theSizeKey
Definition: PDG_File.h:59
static const UT_StringHolder theTagKey
Definition: PDG_File.h:57
OIIO_FORCEINLINE vbool4 operator>=(const vint4 &a, const vint4 &b)
Definition: simd.h:4577
exint size() const
Definition: PDG_File.h:108
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
bool own() const
Definition: PDG_File.h:111
OIIO_FORCEINLINE vbool4 operator>(const vint4 &a, const vint4 &b)
Definition: simd.h:4561
Hash hash() const
Definition: PDG_File.h:102
OIIO_FORCEINLINE vbool4 operator<=(const vint4 &a, const vint4 &b)
Definition: simd.h:4581
int64 Hash
The file hash/modtime type.
Definition: PDG_File.h:39
const UT_StringHolder & tag() const
Definition: PDG_File.h:99
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
long long int64
Definition: SYS_Types.h:116
const UT_StringHolder & data() const
Definition: PDG_File.h:96
bool isGenerated() const
Definition: PDG_File.h:89
static bool isClear(const PDG_File &file)
Definition: PDG_File.h:186
GLsizeiptr size
Definition: glcorearb.h:664
SIM_API const UT_StringHolder force
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
bool isExpected() const
Definition: PDG_File.h:87
static const UT_StringHolder theDataKey
JSON Serialization keys.
Definition: PDG_File.h:56
Definition: core.h:1131
PDG_File::FileType type() const
Definition: PDG_File.h:105
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
SYS_FORCE_INLINE size_t hash_value(const PDG_File &file)
Definition: PDG_File.h:166
type
Definition: core.h:1059
static const UT_StringHolder theOwnKey
Definition: PDG_File.h:60
Definition: format.h:895