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 
24 class PDG_Scheduler;
25 class PDG_WorkItem;
26 
28 {
29 public:
30  /// Array of files
32 
33  /// Set of files, which uses the default clear struct defined at the
34  /// bottom of this file
36 
37  /// The file hash/modtime type
38  using Hash = int64;
40 
41  /// Enumeration of file types, used to maintain whether the file is an
42  /// expected output, a generated output, or a file reported at cook time.
43  enum FileType
44  {
49  };
50 
51  /// Default/invalid hash value
52  static constexpr Hash theInvalidHash = 0;
53 
54  /// JSON Serialization keys
56  static const UT_StringHolder theTagKey;
59  static const UT_StringHolder theOwnKey;
61 
62  /// Global empty file and empty file list statics
63  static const PDG_File theEmptyFile;
64  static const Array theEmptyFileArray;
65 
66 public:
67 
68  PDG_File();
70  bool own);
72  const UT_StringHolder& tag,
73  Hash hash,
74  bool own);
76  const UT_StringHolder& tag,
77  Hash hash,
78  FileType type,
79  bool own);
80 
81  int64 getMemoryUsage(bool inclusive) const;
82  /// Updates and return the local_path
83  UT_StringHolder localizePath(
84  const PDG_Scheduler* scheduler) const;
85 
86  bool isExpected() const {
87  return (myType == eFileExpected); }
88  bool isGenerated() const {
89  return (myType == eFileGenerated); }
90 
91  /// Return the local path. Note that this will not do the old __PDG_DIR__
92  /// localization automatically, call `localizePath` first.
93  const UT_StringHolder& local_data() const;
94  void setLocalData(const UT_StringHolder& local_data);
95  const UT_StringHolder& data() const { return myData; }
96  void setData(const UT_StringHolder& data);
97 
98  const UT_StringHolder& tag() const { return myTag; }
99  void setTag(const UT_StringHolder& tag);
100 
101  Hash hash() const { return myHash; }
102  void setHash(Hash hash);
103 
104  PDG_File::FileType type() const { return myType; }
105  void setType(FileType type);
106 
107  exint size() const { return mySize; }
108  void setSize(exint size);
109 
110  bool own() const { return myOwn; }
111  void setOwn(bool own);
112 
113  void updateStat(
114  const PDG_WorkItem* work_item,
115  bool force);
116  void clearStat();
117 
118  bool operator==(const PDG_File& other) const;
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 
125  void save(UT_JSONWriter& writer) const;
126  bool load(const UT_JSONValue& value,
127  bool strict=true);
128 
129  /// Saves a file array to json
130  static void save(const Array& array, UT_JSONWriter& writer);
131 
132  /// Loads a fle array from json
133  static bool load(Array& array,
134  const UT_JSONValue& value,
135  bool strict=true);
136 
137 private:
138  mutable UT_StringHolder myLocalData;
139  UT_StringHolder myData;
140  UT_StringHolder myTag;
141  Hash myHash;
142  exint mySize;
143  FileType myType;
144  bool myOwn;
145 };
146 
148 {
149  SYS_HashType hash = hash_value(file.data());
150  SYShashCombine(hash, hash_value(file.tag()));
151  //The hash and ownership flag shouldn't be considered
152  //when comparing work items
153  SYShashCombine(hash, file.type());
154  return hash;
155 }
156 
157 namespace UT
158 {
159  template <typename T>
160  struct DefaultClearer;
161 
162  template <>
164  {
165  static void clear(PDG_File& file)
166  { file = PDG_File::theEmptyFile; }
167  static bool isClear(const PDG_File& file)
168  { return (file == PDG_File::theEmptyFile); }
169  static void clearConstruct(PDG_File *p)
170  { new ((void *)p) PDG_File(); }
171  static const bool clearNeedsDestruction = false;
172  };
173 }
174 
175 #endif
static const UT_StringHolder theHashKey
Definition: PDG_File.h:57
static const Array theEmptyFileArray
Definition: PDG_File.h:64
Definition: ImfArray.h:47
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:63
#define PDG_API
Definition: PDG_API.h:23
static void clearConstruct(PDG_File *p)
Definition: PDG_File.h:169
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:60
static void clear(PDG_File &file)
Definition: PDG_File.h:165
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
static const UT_StringHolder theSizeKey
Definition: PDG_File.h:58
static const UT_StringHolder theTagKey
Definition: PDG_File.h:56
OIIO_FORCEINLINE vbool4 operator>=(const vint4 &a, const vint4 &b)
Definition: simd.h:4577
exint size() const
Definition: PDG_File.h:107
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
bool own() const
Definition: PDG_File.h:110
OIIO_FORCEINLINE vbool4 operator>(const vint4 &a, const vint4 &b)
Definition: simd.h:4561
Hash hash() const
Definition: PDG_File.h:101
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:38
const UT_StringHolder & tag() const
Definition: PDG_File.h:98
#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:95
bool isGenerated() const
Definition: PDG_File.h:88
static bool isClear(const PDG_File &file)
Definition: PDG_File.h:167
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:86
static const UT_StringHolder theDataKey
JSON Serialization keys.
Definition: PDG_File.h:55
Definition: core.h:1131
PDG_File::FileType type() const
Definition: PDG_File.h:104
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:147
type
Definition: core.h:1059
static const UT_StringHolder theOwnKey
Definition: PDG_File.h:59
Definition: format.h:895